code: def broadcast(
      tensor: Union[torch.Tensor, float, str, None],
      src: int = 0,
      safe_mode: bool = False,
  ) -> Union[torch.Tensor, float, str]:
      """Helper method to perform broadcast operation.
  
      Args:
          tensor: tensor or number or str to broadcast to participating processes.
              Make sure to respect data type of torch tensor input for all processes, otherwise execution will crash.
              Can use None for non-source data with ``safe_mode=True``.
          src: source rank. Default, 0.
          safe_mode: if True, non source input data can be ``None`` or anything (will be discarded), otherwise data type
              of the input ``tensor`` should be respected for all processes. Please, keep in mind, this mode is working
              only for dense tensors as source input if a tensor is provided. It also leads to some additional
              collectives before the broadcast, making it slower than without using this mode. Default, False.
  
      Returns:
          torch.Tensor or string or number
  
      Examples:
          .. code-block:: python
  
              y = None
              if idist.get_rank() == 0:
                  t1 = torch.rand(4, 5, 6, device=idist.device())
                  s1 = "abc"
                  x = 12.3456
                  y = torch.rand(1, 2, 3, device=idist.device())
              else:
                  t1 = torch.empty(4, 5, 6, device=idist.device())
                  s1 = ""
                  x = 0.0
  
              # Broadcast tensor t1 from rank 0 to all processes
              t1 = idist.broadcast(t1, src=0)
              assert isinstance(t1, torch.Tensor)
  
              # Broadcast string s1 from rank 0 to all processes
              s1 = idist.broadcast(s1, src=0)
              # >>> s1 = "abc"
  
              # Broadcast float number x from rank 0 to all processes
              x = idist.broadcast(x, src=0)
              # >>> x = 12.3456
  
              # Broadcast any of those types from rank 0,
              # but other ranks do not define the placeholder
              y = idist.broadcast(y, src=0, safe_mode=True)
              assert isinstance(y, torch.Tensor)
  
      .. versionadded:: 0.4.2
  
      .. versionchanged:: 0.4.5
          added ``safe_mode``
      """
      if _need_to_sync and isinstance(_model, _SerialModel):
          sync(temporary=True)
  
      return _model.broadcast(tensor, src=src, safe_mode=safe_mode)
  
imports: import socket
  from contextlib import contextmanager
  from functools import wraps
  from typing import Any, Callable, List, Mapping, Optional, Tuple, Union
  import torch
  from ignite.distributed.comp_models import _SerialModel, has_hvd_support, has_native_dist_support, has_xla_support, registered_computation_models
  from ignite.utils import setup_logger
label_desc: Use image node_id 16 for calling a global function with example usage: broadcast(tensor, src, safe_mode) and returns: _model