code: def _update_loss_metrics(self, losses, loss, metrics):
      if self._model_state == enums.ModelState.TRAIN:
          if self.train_batch_index == 0:
              self.train_meter = {k: AverageMeter() for k in metrics}
          losses.update(
              loss.item() * self.config.gradient_accumulation_steps,
              self.train_loader_bs,
          )
      elif self._model_state == enums.ModelState.VALID:
          if self.valid_batch_index == 0:
              self.valid_meter = {k: AverageMeter() for k in metrics}
          loss = self._driver.gather(loss).mean()
          losses.update(loss.item(), self.valid_loader_bs)
      else:
          raise ValueError("Invalid model state")
  
      monitor = self._update_monitor(losses, metrics)
  
      if self._model_state == enums.ModelState.TRAIN:
          self._train_step += 1
      elif self._model_state == enums.ModelState.VALID:
          self._valid_step += 1
      else:
          raise ValueError("Invalid model state")
      return losses, monitor
  
imports: import multiprocessing
  import time
  import warnings
  from dataclasses import dataclass
  from typing import Optional
  import torch
  from accelerate import Accelerator
  from torch.utils.data import DataLoader
  from tez import enums
  from tez.callbacks import CallbackRunner, Progress
  from tez.logger import logger
  from tez.utils import AverageMeter
  from .config import TezConfig
label_desc: Use image node_id 21 for calling the Tez obj's underlying member method code with example usage: obj._update_loss_metrics(losses, loss, metrics) and returns: losses,  monitor