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: Returns the state of the scaler as a :class:`dict`.
docstr_tok: ["Returns","the","state","of","the","scaler","as","a",":","class",":","`","dict","`","."]
code: def state_dict(self):
      """Returns the state of the scaler as a :class:`dict`."""
      return dict(
          cur_scale=self.cur_scale,
          cur_iter=self.cur_iter,
          mode=self.mode,
          last_overflow_iter=self.last_overflow_iter,
          scale_factor=self.scale_factor,
          scale_window=self.scale_window,
      )
  
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 5 for calling the LossScaler obj's underlying member method code with example usage: obj.state_dict() and returns: dict