code: def all_reduce(
      tensor: Union[torch.Tensor, float],
      op: str = "SUM",
      group: Optional[Union[Any, List[int]]] = None,
  ) -> Union[torch.Tensor, float]:
      """Helper method to perform all reduce operation.
  
      Args:
          tensor: tensor or number to collect across participating processes.
          op: reduction operation, "SUM" by default. Possible values: "SUM", "PRODUCT", "MIN", "MAX", "AND", "OR".
              Horovod backend supports only "SUM", "AVERAGE", "ADASUM", "MIN", "MAX", "PRODUCT".
          group: list of integer or the process group for each backend. If None, the default process group will be used.
  
      Returns:
          torch.Tensor or number
  
      .. versionchanged:: 0.4.11
          added ``group``
      """
      if _need_to_sync and isinstance(_model, _SerialModel):
          sync(temporary=True)
  
      if isinstance(group, list) and all(
          isinstance(item, int) for item in group
      ):
          group = _model.new_group(group)
  
      return _model.all_reduce(tensor, op, group=group)
  
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 14 for calling a global function with example usage: all_reduce(tensor, op, group) and returns: _model