code: def _get_rank() -> Optional[int]:
      # SLURM_PROCID can be set even if SLURM is not managing the multiprocessing,
      # therefore LOCAL_RANK needs to be checked first
      rank_keys = (
          "RANK",
          "LOCAL_RANK",
          "SLURM_PROCID",
          "JSM_NAMESPACE_RANK",
      )
      for key in rank_keys:
          rank = os.environ.get(key)
          if rank is not None:
              return int(rank)
      # None to differentiate whether an environment variable was set at all
      return None
  
file_path: pytorch-lightning/src/lightning/fabric/utilities/rank_zero.py
imports: import logging
  import os
  from functools import wraps
  from typing import Callable, Optional, TypeVar, overload
  import lightning_utilities.core.rank_zero
  from lightning_utilities.core.rank_zero import WarningCache, rank_prefixed_message, rank_zero_debug, rank_zero_deprecation, rank_zero_info, rank_zero_warn
  from typing_extensions import ParamSpec
  from lightning.fabric.utilities.imports import _UTILITIES_GREATER_EQUAL_0_10
label_desc: Use image node_id 1 for calling a global function with example usage: _get_rank() and returns: None, int