code: def parse_resource_filter(host_info, include_str="", exclude_str=""):
      """Parse an inclusion or exclusion string and filter a hostfile dictionary.
  
      String format is NODE_SPEC[@NODE_SPEC ...], where
          NODE_SPEC = NAME[:SLOT[,SLOT ...]].
      If :SLOT is omitted, include/exclude all slots on that host.
  
      Examples:
          include_str="worker-0@worker-1:0,2" will use all slots on worker-0 and
            slots [0, 2] on worker-1.
          exclude_str="worker-1:0" will use all available resources except
            slot 0 on worker-1.
      """
  
      # Constants that define our syntax
      NODE_SEP = "@"
      SLOT_LIST_START = ":"
      SLOT_SEP = ","
  
      # Ensure include/exclude are mutually exclusive
      if (include_str != "") and (exclude_str != ""):
          raise ValueError(
              "include_str and exclude_str are mutually exclusive."
          )
  
      # no-op
      if (include_str == "") and (exclude_str == ""):
          return host_info
  
      # Either build from scratch or remove items
      filtered_hosts = dict()
      if include_str:
          parse_str = include_str
      if exclude_str != "":
          filtered_hosts = deepcopy(host_info)
          parse_str = exclude_str
  
      # foreach node in the list
      for node_config in parse_str.split(NODE_SEP):
          # Node can either be alone or node:slot,slot,slot
          if SLOT_LIST_START in node_config:
              hostname, slots = node_config.split(SLOT_LIST_START)
              slots = [int(x) for x in slots.split(SLOT_SEP)]
  
              # sanity checks
              if hostname not in host_info:
                  raise ValueError(
                      f"Hostname '{hostname}' not found in hostfile"
                  )
              for slot in slots:
                  if slot not in host_info[hostname]:
                      raise ValueError(
                          f"No slot '{slot}' specified on host '{hostname}'"
                      )
  
              # If include string, build the list from here
              if include_str:
                  filtered_hosts[hostname] = slots
              elif exclude_str:
                  for slot in slots:
                      logger.info(f"removing {slot} from {hostname}")
                      filtered_hosts[hostname].remove(slot)
  
          # User just specified the whole node
          else:
              hostname = node_config
              # sanity check hostname
              if hostname not in host_info:
                  raise ValueError(
                      f"Hostname '{hostname}' not found in hostfile"
                  )
  
              if include_str:
                  filtered_hosts[hostname] = host_info[hostname]
              elif exclude_str:
                  filtered_hosts[hostname] = []
  
      # Post-processing to remove duplicates and empty nodes
      del_keys = []
      for hostname in filtered_hosts:
          # Remove duplicates
          filtered_hosts[hostname] = _stable_remove_duplicates(
              filtered_hosts[hostname]
          )
          # Remove empty hosts
          if len(filtered_hosts[hostname]) == 0:
              del_keys.append(hostname)
      for name in del_keys:
          del filtered_hosts[name]
  
      # Lastly, go over filtered_hosts and convert to a OrderedDict() to ensure
      # we map ranks to nodes correctly by maintaining host_info ordering.
      ordered_hosts = collections.OrderedDict()
      for host in host_info:
          if host in filtered_hosts:
              ordered_hosts[host] = filtered_hosts[host]
  
      return ordered_hosts
  
imports: import os
  import sys
  import json
  import base64
  import argparse
  import subprocess
  import collections
  from copy import deepcopy
  import signal
  import time
  import torch.cuda
  from .multinode_runner import PDSHRunner, OpenMPIRunner, MVAPICHRunner, SlurmRunner
  from .constants import PDSH_LAUNCHER, OPENMPI_LAUNCHER, MVAPICH_LAUNCHER, SLURM_LAUNCHER
  from ..constants import TORCH_DISTRIBUTED_DEFAULT_PORT
  from ..nebula.constants import NEBULA_EXPORT_ENVS
  from ..utils import logger
  from ..autotuning import Autotuner
label_desc: Use image node_id 4 for calling a global function with example usage: parse_resource_filter(host_info, include_str, exclude_str) and returns: ordered_hosts, host_info