code: def rank_zero_read_and_broadcast(
      func: Callable[..., T],
  ) -> Callable[..., T]:
      def wrapper(*args: Any, **kwargs: Any) -> T:
          ret = None
          rank = get_global_rank()
          process_group = kwargs.pop("process_group", None)
  
          # Do all filesystem reads from rank 0 only
          if rank == 0:
              ret = func(*args, **kwargs)
  
          # If not running in a distributed setting, return as is
          if not (dist.is_available() and dist.is_initialized()):
              # we cast here to avoid type errors, since it is
              # guaranteed the return value is of type T
              return cast(T, ret)
  
          # Otherwise, broadcast result from rank 0 to all ranks
          pg = PGWrapper(process_group)
          path_container = [ret]
          pg.broadcast_object_list(path_container, 0)
          val = path_container[0]
  
          # we cast here to avoid type errors, since it is
          # guaranteed the return value is of type T
          return cast(T, val)
  
      return wrapper
  
imports: import logging
  import os
  import re
  from typing import Any, Callable, cast, Dict, List, Optional, Pattern, Tuple, TypeVar
  import fsspec
  from pyre_extensions import none_throws
  from torch import distributed
  from torchtnt.framework.callbacks.checkpointer_types import RestoreOptions
  from torchtnt.framework.state import State
  from torchtnt.framework.unit import AppStateMixin
  from torchtnt.utils.distributed import get_global_rank, PGWrapper
  from torchtnt.utils.fsspec import get_filesystem
  from torchtnt.utils.stateful import Stateful
label_desc: Use image node_id 1 for calling a global function with example usage: rank_zero_read_and_broadcast(func) and returns: wrapper, cast, cast