code: def test_process_combined_metrics_and_batches() -> None:
      # Test empty metrics. This case can arise when custom reducers are used, so it's okay for
      # evaluate_batch to return an empty dict.
      combined_metrics_and_batches = [
          (
              {},
              2,
          ),  # this is from a rank actually computing metrics but returning an empty dict
          ({}, 2),
      ]  # type: List[Tuple[Dict[Any, Any], int]]
      (
          processed_metrics,
          processed_batches,
      ) = metric_utils._process_combined_metrics_and_batches(
          combined_metrics_and_batches
      )
      expected_metrics = {}  # type: dict
      assert processed_metrics == expected_metrics
      assert processed_batches == [2, 2]
  
      # Test combine with some ranks not reporting metrics.
      combined_metrics_and_batches = [
          (
              {},
              0,
          ),  # this corresponds to a rank that does not compute metrics and gets filtered out
          ({}, 0),
          ({"loss1": [1, 2], "loss2": [-1, -2]}, 2),
          ({"loss1": [3, 4], "loss2": [-3, -4]}, 2),
      ]
      (
          processed_metrics,
          processed_batches,
      ) = metric_utils._process_combined_metrics_and_batches(
          combined_metrics_and_batches
      )
      expected_metrics = {
          "loss1": [[1, 2], [3, 4]],
          "loss2": [[-1, -2], [-3, -4]],
      }
      assert processed_metrics == expected_metrics
      assert processed_batches == [2, 2]
  
      # Test array handling.
      combined_metrics_and_batches = [
          ({}, 0),
          ({}, 0),
          ({"loss1": [1, 2], "loss2": [np.array(-1), np.array(-2)]}, 2),
          ({"loss1": [3, 4], "loss2": [np.array(-3), np.array(-4)]}, 2),
      ]
      (
          processed_metrics,
          processed_batches,
      ) = metric_utils._process_combined_metrics_and_batches(
          combined_metrics_and_batches
      )
      expected_metrics = {
          "loss1": [[1, 2], [3, 4]],
          "loss2": [
              [np.array(-1), np.array(-2)],
              [np.array(-3), np.array(-4)],
          ],
      }
      assert processed_metrics == expected_metrics
      assert processed_batches == [2, 2]
  
file_path: determined/harness/tests/experiment/pytorch/test_metric_utils.py
imports: import logging
  from typing import Any, Dict, List, Tuple, Union
  import numpy
  import pytest
  import torch
  import determined.errors
  import determined.pytorch._metric_utils
  from determined import pytorch
label_desc: Use image node_id 1 for calling a global function with example usage: test_process_combined_metrics_and_batches() without return types