code: def resolve_distributed_mode(args):
      # Note that args.distributed is set by only this function.
      # and ArgumentParser doesn't have such option
  
      if args.multiprocessing_distributed:
          num_nodes = get_num_nodes(
              args.dist_world_size, args.dist_launcher
          )
          # a. multi-node
          if num_nodes > 1:
              args.distributed = True
          # b. single-node and multi-gpu with multiprocessing_distributed mode
          elif args.ngpu > 1:
              args.distributed = True
          # c. single-node and single-gpu
          else:
              args.distributed = False
  
          if args.ngpu <= 1:
              # Disable multiprocessing_distributed mode if 1process per node or cpu mode
              args.multiprocessing_distributed = False
          if args.ngpu == 1:
              # If the number of GPUs equals to 1 with multiprocessing_distributed mode,
              # LOCAL_RANK is always 0
              args.local_rank = 0
  
          if (
              num_nodes > 1
              and get_node_rank(args.dist_rank, args.dist_launcher)
              is None
          ):
              raise RuntimeError(
                  "--dist_rank or RANK must be set "
                  "if --multiprocessing_distributed == true"
              )
  
          # Note that RANK, LOCAL_RANK, and WORLD_SIZE is automatically set,
          # so we don't need to check here
      else:
          # d. multiprocess and multi-gpu with external launcher
          #    e.g. torch.distributed.launch
          if (
              get_world_size(args.dist_world_size, args.dist_launcher)
              > 1
          ):
              args.distributed = True
          # e. single-process
          else:
              args.distributed = False
  
          if args.distributed and args.ngpu > 0:
              if (
                  get_local_rank(args.local_rank, args.dist_launcher)
                  is None
              ):
                  raise RuntimeError(
                      "--local_rank or LOCAL_RANK must be set "
                      "if --multiprocessing_distributed == false"
                  )
          if args.distributed:
              if (
                  get_node_rank(args.dist_rank, args.dist_launcher)
                  is None
              ):
                  raise RuntimeError(
                      "--dist_rank or RANK must be set "
                      "if --multiprocessing_distributed == false"
                  )
      if (
          args.distributed
          and args.dist_launcher == "slurm"
          and not is_in_slurm_step()
      ):
          raise RuntimeError(
              "Launch by 'srun' command if --dist_launcher='slurm'"
          )
  
imports: import dataclasses
  import os
  import socket
  from typing import Optional
  import torch
  import torch.distributed
label_desc: Use image node_id 1 for calling a global function with example usage: resolve_distributed_mode(args) without return types