class_docstr: Holds the common metrics of a sequence-to-sequence model.
class_docstr_tok: ["Holds","the","common","metrics","of","a","sequence-to-sequence","model","."]
docstr: Update the metrics.
  
  :param batches:
      The batches processed by the model in the last training step.
  :param output:
      The losses generated by the model for each batch in ``batches``.
  :param elapsed_time:
      The total elapsed time to read and process ``batches``.
docstr_tok: ["Update","the","metrics",".",":","param","batches",":","The","batches","processed","by","the","model","in","the","last","training","step",".",":","param","output",":","The","losses","generated","by","the","model","for","each","batch","in","``","batches","``",".",":","param","elapsed_time",":","The","total","elapsed","time","to","read","and","process","``","batches","``","."]
code: def update_metrics(
      self,
      batches: Sequence[Seq2SeqBatch],
      losses: Sequence[Tensor],
      elapsed_time: float,
  ) -> None:
      """Update the metrics.
  
      :param batches:
          The batches processed by the model in the last training step.
      :param output:
          The losses generated by the model for each batch in ``batches``.
      :param elapsed_time:
          The total elapsed time to read and process ``batches``.
      """
      loss = torch.zeros((), dtype=torch.float64)
  
      batch_size = torch.zeros((), dtype=torch.float64)
  
      num_source_elements = torch.zeros((), dtype=torch.float64)
      num_target_elements = torch.zeros((), dtype=torch.float64)
  
      for batch, loss in zip(batches, losses):
          loss += loss
  
          batch_size += batch.batch_size
  
          num_source_elements += (
              batch.num_source_elements() - batch.batch_size
          )
          num_target_elements += (
              batch.num_target_elements() - batch.batch_size
          )
  
      loss /= num_target_elements
  
      self.loss.update(loss, weight=num_target_elements)
  
      # Mainly exists for compatibility with fairseq's `nll_loss`.
      self.entropy_loss.update(
          loss / math.log(2), weight=num_target_elements
      )
  
      self.batch_size.update(batch_size * self.gang.size)
  
      self.elements_per_batch.update(
          num_target_elements * self.gang.size
      )
  
      self.elements_per_second.update(
          int(num_target_elements), elapsed_time
      )
  
      self.num_source_elements.update(num_source_elements)
      self.num_target_elements.update(num_target_elements)
  
imports: from __future__ import annotations
  import math
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Any, Optional, Sequence, Tuple, final
  import torch
  from torch import Tensor
  from torch.nn import Module
  from torcheval.metrics import Mean, Sum, Throughput
  from fairseq2.data import VocabularyInfo
  from fairseq2.gang import Gang
  from fairseq2.metrics import MetricBag
  from fairseq2.models.sequence import SequenceModelOutput
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.typing import finaloverride
label_desc: Use image node_id 2 for calling the Seq2SeqModelMetricBag obj's underlying member method code with example usage: obj.update_metrics(batches, losses, elapsed_time) without return types