code: def broadcast_object(
      obj, root_rank=0, name=None, process_set=global_process_set
  ):
      """
      Serializes and broadcasts an object from root rank to all other processes.
      Typical usage is to broadcast the `optimizer.state_dict()`, for example:
  
      .. code-block:: python
  
          state_dict = broadcast_object(optimizer.state_dict(), 0)
          if hvd.rank() > 0:
              optimizer.load_state_dict(state_dict)
  
      Arguments:
          obj: An object capable of being serialized without losing any context.
          root_rank: The rank of the process from which parameters will be
                     broadcasted to all other processes.
          name: Optional name to use during broadcast, will default to the class
                type.
          process_set: Process set object to limit this operation to a subset of
                       Horovod processes. Default is the global process set.
      Returns:
          The object that was broadcast from the `root_rank`.
      """
      if name is None:
          name = type(obj).__name__
  
      if rank() == root_rank:
          b = io.BytesIO()
          cloudpickle.dump(obj, b)
          t = torch.ByteTensor(bytearray(b.getvalue()))
          sz = torch.IntTensor([t.shape[0]])
          broadcast_(sz, root_rank, name + ".sz", process_set)
      else:
          sz = torch.IntTensor([0])
          broadcast_(sz, root_rank, name + ".sz", process_set)
          t = torch.ByteTensor(sz.tolist()[0])
  
      broadcast_(t, root_rank, name + ".t", process_set)
  
      if rank() != root_rank:
          buf = io.BytesIO(t.numpy().tobytes())
          obj = cloudpickle.load(buf)
  
      return obj
  
file_path: horovod/horovod/torch/functions.py
imports: import collections
  import io
  from collections.abc import Iterable
  import cloudpickle
  import torch
  from horovod.torch.mpi_ops import allgather, broadcast_, broadcast_async_
  from horovod.torch.mpi_ops import synchronize
  from horovod.torch.mpi_ops import rank, size
  from horovod.torch.mpi_ops import ProcessSet, global_process_set
label_desc: Use image node_id 3 for calling a global function with example usage: broadcast_object(obj, root_rank, name, process_set) and returns: obj