code: def normalize_metrics_summary(
      metrics_summary: Dict[str, Tuple[float, int]], split: str
  ) -> Dict[str, float]:
      """Normalize the metrics in summary by its normalizer.
  
      Args:
        metrics_summary: A dictionary mapping metric name to (value, normalizer).
        split: Split for which we normalize the metrics. Used for logging.
  
      Returns:
        Normalized metrics summary.
  
      Raises:
        TrainingDivergedError: Due to observing a NaN in the metrics.
      """
      # TODO(dehghani): Currently we only support metrics of the form 1/N sum
      #   f(x_i). We may need a more general framework for metrics like
      #   precision and recall. Note in particular that while we're normalizing by
      #   the "metric normalization value" that is val[1], this value is previously
      #   summed up and is defined to be an integer.
      normalized_metrics_summary = {}
      for key, val in metrics_summary.items():
          normalized_metrics_summary[key] = val[0] / (val[1] + 1e-9)
          if np.isnan(normalized_metrics_summary[key]):
              msg = f"NaN detected in {split}_{key} (Unnormalized values: {val})"
              if split == "train":
                  raise TrainingDivergedError(msg)
              else:
                  logging.error("WARNING: Split %s %s", split, msg)
  
      return normalized_metrics_summary
  
imports: import collections.abc
  import copy
  import functools
  import os
  import re
  import time
  from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple, Union
  from absl import logging
  from clu import metric_writers
  import flax
  from flax import jax_utils
  from flax import struct
  import flax.linen
  from flax.training import checkpoints
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  import optax
  from scenic.common_lib import debug_utils
  from scenic.dataset_lib import dataset_utils
  from scenic.dataset_lib import datasets
  from scenic.train_lib import optimizers
  from tensorflow.io import gfile
label_desc: Use image node_id 12 for calling a global function with example usage: normalize_metrics_summary(metrics_summary, split) and returns: normalized_metrics_summary