code: def spawn_workers(main, cfg):
      """Use torch.multiprocessing.spawn to launch distributed processes"""
      if cfg.DDP_CONFIG.AUTO_RANK_MATCH:
          assert len(cfg.DDP_CONFIG.WOLRD_URLS) > 0
          assert cfg.DDP_CONFIG.WOLRD_URLS[0] in cfg.DDP_CONFIG.DIST_URL
          assert (
              len(cfg.DDP_CONFIG.WOLRD_URLS)
              == cfg.DDP_CONFIG.WORLD_SIZE
          )
          cfg.DDP_CONFIG.WORLD_RANK = get_local_ip_and_match(
              cfg.DDP_CONFIG.WOLRD_URLS
          )
          assert cfg.DDP_CONFIG.WORLD_RANK != -1
  
      ngpus_per_node = torch.cuda.device_count()
      if cfg.DDP_CONFIG.DISTRIBUTED:
          cfg.DDP_CONFIG.GPU_WORLD_SIZE = (
              ngpus_per_node * cfg.DDP_CONFIG.WORLD_SIZE
          )
          mp.spawn(
              main_worker,
              nprocs=ngpus_per_node,
              args=(ngpus_per_node, main, cfg),
          )
      else:
          main_worker(cfg.DDP_CONFIG.GPU, ngpus_per_node, main, cfg)
  
imports: import torch
  import torch.distributed
  import torch.backends.cudnn
  import torch.multiprocessing
label_desc: Use image node_id 2 for calling a global function with example usage: spawn_workers(main, cfg) without return types