code: def _prepare_metrics_reducers(
      reducer: Union[pytorch.Reducer, Dict[str, Any]], keys: Any
  ) -> Dict[str, pytorch.Reducer]:
      metrics_reducers = {}  # type: Dict[str, pytorch.Reducer]
      if isinstance(reducer, Dict):
          metrics_reducers = reducer
          if keys != metrics_reducers.keys():
              raise det.errors.InvalidExperimentException(
                  "Please provide a single evaluation reducer or "
                  "provide a reducer for every validation metric. "
                  f"Expected keys: {keys}, provided keys: {metrics_reducers.keys()}.",
              )
      else:
          for key in keys:
              metrics_reducers[key] = reducer
  
      for key in keys:
          if not isinstance(metrics_reducers[key], pytorch.Reducer):
              raise det.errors.InvalidExperimentException(
                  "Please select `determined.pytorch.Reducer` for reducing validation metrics.",
              )
  
      return metrics_reducers
  
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 5 for calling a global function with example usage: _prepare_metrics_reducers(reducer, keys) and returns: metrics_reducers