code: def parse_device_filter(
      device_pool: HostInfoList, include_str=None, exclude_str=None
  ) -> HostInfoList:
      """Parse an inclusion or exclusion string and filter a hostfile dictionary.
  
      Examples:
          include_str="worker-0,worker-1" will execute jobs only on worker-0 and worker-1.
          exclude_str="worker-1" will use all available devices except worker-1.
  
      Args:
          device_pool (HostInfoList): a list of HostInfo objects
          include_str (str): --include option passed by user, default None
          exclude_str (str): --exclude option passed by user, default None
  
      Returns:
          filtered_hosts (HostInfoList): filtered hosts after inclusion/exclusion
      """
  
      # Ensure include/exclude are mutually exclusive
      if include_str and exclude_str:
          click.echo(
              "--include and --exclude are mutually exclusive, only one can be used"
          )
          exit()
  
      # no-op
      if include_str is None and exclude_str is None:
          return device_pool
  
      # Either build from scratch or remove items
      if include_str:
          parse_str = include_str
          filtered_hosts = HostInfoList()
      elif exclude_str:
          parse_str = exclude_str
          filtered_hosts = device_pool
  
      # foreach node in the list
      for node_config in parse_str.split(NODE_SEP):
          hostname = node_config
          hostinfo = device_pool.get_hostinfo(hostname)
          # sanity check hostname
          if not device_pool.has(hostname):
              click.echo(
                  f"Error: Hostname '{hostname}' not found in hostfile"
              )
              exit()
  
          if include_str:
              filtered_hosts.append(hostinfo)
          elif exclude_str:
              filtered_hosts.remove(hostname)
  
      return filtered_hosts
  
file_path: ColossalAI/colossalai/cli/launcher/run.py
imports: import os
  import sys
  from typing import List
  import click
  import torch
  from packaging import version
  from colossalai.context import Config
  from .hostinfo import HostInfo, HostInfoList
  from .multinode_runner import MultiNodeRunner
label_desc: Use image node_id 2 for calling a global function with example usage: parse_device_filter(device_pool, include_str, exclude_str) and returns: filtered_hosts, device_pool