code: def average_losses_across_data_parallel_group(losses):
      """Reduce a tensor of losses across all GPUs."""
      averaged_losses = torch.cat(
          [loss.clone().detach().view(1) for loss in losses]
      )
      torch.distributed.all_reduce(
          averaged_losses,
          group=parallel_state.get_data_parallel_group(),
      )
      averaged_losses = (
          averaged_losses
          / torch.distributed.get_world_size(
              group=parallel_state.get_data_parallel_group()
          )
      )
  
      return averaged_losses
  
imports: from typing import Optional, List, Union, Tuple
  import torch
  from torch.nn.parallel import DistributedDataParallel
  from apex.multi_tensor_apply import multi_tensor_applier
  from apex.transformer import parallel_state
  from apex.transformer.enums import ModelType
  from apex.transformer.microbatches import build_num_microbatches_calculator
  from apex.transformer.pipeline_parallel._timers import _Timers
label_desc: Use image node_id 22 for calling a global function with example usage: average_losses_across_data_parallel_group(losses) and returns: averaged_losses