code: def all_reduce_op(
      tensor: torch.Tensor,
      op: torch.distributed.ReduceOp,
      after_op_func: Callable[[torch.Tensor], torch.Tensor] = None,
  ) -> torch.Tensor:
      """
      Wrapper over torch.distributed.all_reduce for performing
      reduction of tensor over all processes in both distributed /
      non-distributed scenarios.
      """
      if is_distributed_training_run():
          tensor, orig_device = convert_to_distributed_tensor(tensor)
          torch.distributed.all_reduce(tensor, op)
          if after_op_func is not None:
              tensor = after_op_func(tensor)
          tensor = convert_to_normal_tensor(tensor, orig_device)
      return tensor
  
imports: import io
  import tempfile
  from typing import Any, Callable, List, Tuple
  import torch
label_desc: Use image node_id 9 for calling a global function with example usage: all_reduce_op(tensor, op, after_op_func) and returns: tensor