code: def get_local_rank(prior=None, launcher: str = None) -> Optional[int]:
      # LOCAL_RANK is same as GPU device id
  
      if prior is None:
          if launcher == "slurm":
              if not is_in_slurm_step():
                  raise RuntimeError(
                      "This process seems not to be launched by 'srun'"
                  )
  
              prior = int(os.environ["SLURM_LOCALID"])
          elif launcher == "mpi":
              raise RuntimeError(
                  "launcher=mpi is used for 'multiprocessing-distributed' mode"
              )
          elif launcher is not None:
              raise RuntimeError(
                  f"launcher='{launcher}' is not supported"
              )
  
      if prior is not None:
          return int(prior)
  
      elif "LOCAL_RANK" in os.environ:
          return int(os.environ["LOCAL_RANK"])
  
      elif "CUDA_VISIBLE_DEVICES" in os.environ:
          # There are two possibility:
          # - "CUDA_VISIBLE_DEVICES" is set to multiple GPU ids. e.g. "0.1,2"
          #   => This intends to specify multiple devices to to be used exactly
          #      and local_rank information is possibly insufficient.
          # - "CUDA_VISIBLE_DEVICES" is set to an id. e.g. "1"
          #   => This could be used for LOCAL_RANK
          cvd = os.environ["CUDA_VISIBLE_DEVICES"].split(",")
          if len(cvd) == 1 and "LOCAL_RANK" not in os.environ:
              # If CUDA_VISIBLE_DEVICES is set and LOCAL_RANK is not set,
              # then use it as LOCAL_RANK.
  
              # Unset CUDA_VISIBLE_DEVICES
              # because the other device must be visible to communicate
              return int(os.environ.pop("CUDA_VISIBLE_DEVICES"))
          else:
              return None
      else:
          return None
  
imports: import dataclasses
  import os
  import socket
  from typing import Optional
  import torch
  import torch.distributed
label_desc: Use image node_id 8 for calling a global function with example usage: get_local_rank(prior, launcher) and returns: int, int, None, int, None