code: def _check_nan_losses(self, report):
      # skip this check in XLA mode as calling .item() in forward pass
      # greatly slows down the training
      if not is_xla():
          # check whether NaN has occurred in the losses, and exit the training
          # when NaN happens
          loss_dict = report.losses
          nan_loss_keys = []
          for key, value in loss_dict.items():
              if torch.any(torch.isnan(value)).item():
                  nan_loss_keys.append(key)
          if len(nan_loss_keys) > 0:
              keys_str = ", ".join(nan_loss_keys)
              error_msg = (
                  f"NaN occurred in the following loss(es): {keys_str}; "
                  f"exiting the training"
              )
              logger.info(error_msg)
              raise RuntimeError(error_msg)
  
imports: import gc
  import logging
  from abc import ABC
  from typing import Any, Dict
  import torch
  from mmf.common.meter import Meter
  from mmf.common.registry import registry
  from mmf.common.report import Report
  from mmf.common.sample import to_device
  from mmf.utils.distributed import is_xla
  from mmf.utils.general import clip_gradients, extract_loss, get_max_updates
  from torch import Tensor
label_desc: Use image node_id 5 for calling the TrainerTrainingLoopMixin obj's underlying member method code with example usage: obj._check_nan_losses(report) without return types