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: import itertools
  import math
  from typing import Dict, Iterator, List, Tuple, Union
  import torch
  import torch.nn
  from torch import Tensor
label_desc: Use image node_id 12 for calling a global function with example usage: average_losses_across_data_parallel_group(losses) and returns: averaged_losses