code: def torch_reduce_sum(
      device,
      logging_outputs,
      *extra_stats_to_sum,
      ignore=False,
  ):
      """
      Sync logging outputs across workers. fast_stat_sync_sum is
      faster than all_gather_list_sync, but is only suitable when
      logging outputs are scalars and can be summed. Note that
      *logging_outputs* cannot contain any nested dicts/lists.
      """
      data = {}
      for i, stat in enumerate(extra_stats_to_sum):
          data["extra_stats_" + str(i)] = stat
      if len(logging_outputs) > 0:
          log_keys = list(logging_outputs[0].keys())
          for k in log_keys:
              if not ignore:
                  v = sum(log[k] for log in logging_outputs if k in log)
              else:
                  v = logging_outputs[0][k]
                  v = torch.zeros_like(v) if torch.is_tensor(v) else 0
              data["logging_outputs_" + k] = v
      else:
          log_keys = None
  
      data = distributed_utils.all_reduce_dict(
          data, device=device, group=None
      )
  
      extra_stats_to_sum = [
          data["extra_stats_" + str(i)]
          for i in range(len(extra_stats_to_sum))
      ]
      if log_keys is not None:
          logging_outputs = [
              {k: data["logging_outputs_" + k] for k in log_keys}
          ]
      else:
          logging_outputs = []
      return logging_outputs, extra_stats_to_sum
  
imports: import math
  import torch
  from torch import nn
  import torch.distributed
  import deepspeed
  from deepspeed.utils import log_dist
  from fairseq import tasks, distributed_utils
  from fairseq.logging import metrics
  from ds_fairseq_data import BatchIterator
  from ds_fairseq_argument import gen_ds_fairseq_arg
label_desc: Use image node_id 1 for calling a global function with example usage: torch_reduce_sum(device, logging_outputs) and returns: logging_outputs,  extra_stats_to_sum