code: def test_prepare_metric_reducers() -> None:
      metrics_dict = {"loss1": 1, "loss2": 2}
  
      # Test mismatched keys
      reducer = {}  # type: Union[Dict[str, Any], pytorch.Reducer]
      with pytest.raises(determined.errors.InvalidExperimentException):
          _ = metric_utils._prepare_metrics_reducers(
              reducer, metrics_dict.keys()
          )
  
      # Test invalid reducer
      reducer = {"loss1": pytorch.Reducer.AVG, "loss2": 2}
      with pytest.raises(determined.errors.InvalidExperimentException):
          _ = metric_utils._prepare_metrics_reducers(
              reducer, metrics_dict.keys()
          )
  
      # Test single reducer
      reducer = pytorch.Reducer.AVG
      prepped_reducers = metric_utils._prepare_metrics_reducers(
          reducer, metrics_dict.keys()
      )
      assert prepped_reducers == {
          "loss1": pytorch.Reducer.AVG,
          "loss2": pytorch.Reducer.AVG,
      }
  
      # Test reducer dict
      reducer = {
          "loss1": pytorch.Reducer.AVG,
          "loss2": pytorch.Reducer.SUM,
      }
      prepped_reducers = metric_utils._prepare_metrics_reducers(
          reducer, metrics_dict.keys()
      )
      assert prepped_reducers == {
          "loss1": pytorch.Reducer.AVG,
          "loss2": pytorch.Reducer.SUM,
      }
  
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 3 for calling a global function with example usage: test_prepare_metric_reducers() without return types