code: def normalize_batch_metrics(
      batch_metrics: Sequence[Metrics],
  ) -> Metrics:
      """Consolidates and normalizes a list of per-batch metrics dicts."""
      # Here we sum the metrics that were already summed per batch.
      total_loss = np.sum([metrics.loss for metrics in batch_metrics])
      total_accuracy = np.sum(
          [metrics.accuracy for metrics in batch_metrics]
      )
      total = np.sum([metrics.count for metrics in batch_metrics])
      # Divide each metric by the total number of items in the data set.
      return Metrics(
          loss=total_loss.item() / total,
          accuracy=total_accuracy.item() / total,
      )
  
imports: from typing import Any, Callable, Dict, Iterable, Optional, Sequence, Tuple, Union
  from absl import logging
  from flax import struct
  from flax.metrics import tensorboard
  from flax.training import train_state
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  import optax
  import tensorflow
  import input_pipeline
  import models
label_desc: Use image node_id 8 for calling a global function with example usage: normalize_batch_metrics(batch_metrics) and returns: Metrics