code: def reduce_value(
      value: Tensor, dst: Optional[int] = 0, average: bool = True
  ):
      world_size = get_world_size()
      if world_size < 2:
          return value
      if dst is None:
          dist.all_reduce(value)
          if average:
              value = value / world_size
      else:
          dist.reduce(value, dst)
          if (get_rank() == dst) and average:
              value = value / world_size
      return value
  
file_path: gluonts/src/gluonts/nursery/daf/tslib/engine/distributed.py
imports: from typing import Optional
  import os
  import torch
  from torch import Tensor
  from torch import distributed
label_desc: Use image node_id 6 for calling a global function with example usage: reduce_value(value, dst, average) and returns: value, value