class_docstr: Class that manages loss scaling in mixed precision training which
  supports both dynamic or static mode.
  
  The implementation refers to
  https://github.com/NVIDIA/apex/blob/master/apex/fp16_utils/loss_scaler.py.
  Indirectly, by supplying ``mode='dynamic'`` for dynamic loss scaling.
  It's important to understand how :class:`LossScaler` operates.
  Loss scaling is designed to combat the problem of underflowing
  gradients encountered at long times when training fp16 networks.
  Dynamic loss scaling begins by attempting a very high loss
  scale.  Ironically, this may result in OVERflowing gradients.
  If overflowing gradients are encountered, :class:`FP16_Optimizer` then
  skips the update step for this particular iteration/minibatch,
  and :class:`LossScaler` adjusts the loss scale to a lower value.
  If a certain number of iterations occur without overflowing gradients
  detected,:class:`LossScaler` increases the loss scale once more.
  In this way :class:`LossScaler` attempts to "ride the edge" of always
  using the highest loss scale possible without incurring overflow.
  
  Args:
      init_scale (float): Initial loss scale value, default: 2**32.
      scale_factor (float): Factor used when adjusting the loss scale.
          Default: 2.
      mode (str): Loss scaling mode. 'dynamic' or 'static'
      scale_window (int): Number of consecutive iterations without an
          overflow to wait before increasing the loss scale. Default: 1000.
docstr: Check if params contain NaN.
docstr_tok: ["Check","if","params","contain","NaN","."]
code: def _has_inf_or_nan(x):
      """Check if params contain NaN."""
      try:
          cpu_sum = float(x.float().sum())
      except RuntimeError as instance:
          if "value cannot be converted" not in instance.args[0]:
              raise
          return True
      else:
          if (
              cpu_sum == float("inf")
              or cpu_sum == -float("inf")
              or cpu_sum != cpu_sum
          ):
              return True
          return False
  
imports: import functools
  import warnings
  from collections import abc
  from inspect import getfullargspec
  import numpy
  import torch
  import torch.nn
  from annotator.uniformer.mmcv.utils import TORCH_VERSION, digit_version
  from .dist_utils import allreduce_grads
label_desc: Use image node_id 3 for calling the LossScaler obj's underlying member method code with example usage: obj._has_inf_or_nan(x) and returns: False, True, True