code: def _average_training_metrics(
      combined_timeseries: Dict[str, Any],
      combined_num_batches: List[int],
  ) -> List[Dict[str, Any]]:
      """Average combined training metrics across GPUs"""
      # If the value for a metric is a single-element array, the averaging process will
      # change that into just the element. We record what metrics are single-element arrays
      # so we can wrap them in an array later (for perfect compatibility with non-averaging
      # codepath).
      array_metrics = []
      for metric_name in combined_timeseries.keys():
          process_batches = combined_timeseries[metric_name]
          if isinstance(process_batches[0][0], np.ndarray):
              array_metrics.append(metric_name)
  
      num_batches = combined_num_batches[
          0
      ]  # num_batches matches across data parallel ranks.
      num_processes = len(combined_num_batches)
      averaged_metrics_timeseries = {}  # type: Dict[str, List]
  
      for metric_name in combined_timeseries.keys():
          averaged_metrics_timeseries[metric_name] = []
          for batch_idx in range(num_batches):
              batch = [
                  combined_timeseries[metric_name][process_idx][
                      batch_idx
                  ]
                  for process_idx in range(num_processes)
              ]
  
              np_batch = np.array(batch)
              batch_avg = np.mean(
                  np_batch[np_batch != None]
              )  # noqa: E711
              if metric_name in array_metrics:
                  batch_avg = np.array(batch_avg)
              averaged_metrics_timeseries[metric_name].append(batch_avg)
      return util._dict_to_list(averaged_metrics_timeseries)
  
file_path: determined/harness/determined/pytorch/_metric_utils.py
imports: import logging
  from typing import Any, Dict, List, Optional, Tuple, Union, cast
  import numpy
  import torch
  import determined
  from determined import pytorch, util
label_desc: Use image node_id 2 for calling a global function with example usage: _average_training_metrics(combined_timeseries, combined_num_batches) and returns: util