code: def get_global_rank() -> int:
      """
      Get rank using torch.distributed if available. Otherwise, the RANK env var instead if initialized.
      Returns 0 if neither condition is met.
      """
      if dist.is_available() and dist.is_initialized():
          return dist.get_rank()
  
      environ_rank = os.environ.get("RANK", "")
      if environ_rank.isdecimal():
          return int(os.environ["RANK"])
  
      return 0
  
imports: import os
  import tempfile
  from functools import wraps
  from typing import Any, Callable, cast, List, Optional, TypeVar, Union
  import torch
  import torch.distributed
  import torch.nn.functional
  from torch import Tensor
  from torch.distributed.elastic.utils.distributed import get_free_port
  from typing_extensions import Literal
label_desc: Use image node_id 1 for calling a global function with example usage: get_global_rank() and returns: int, dist, int