class_docstr: An instance ``scaler`` helps perform the steps of gradient scaling
  conveniently.
class_docstr_tok: ["An","instance","``","scaler","``","helps","perform","the","steps","of","gradient","scaling","conveniently","."]
docstr: :meth:`step` unscale the gradients and step the optimizer.
  
  ``*args`` and ``**kwargs`` are forwarded to ``optimizer.step()``.
  
  Args:
      optimizer (torch.optim.Optimizer):  Optimizer that applies the gradients.
      args:  Any arguments.
      kwargs:  Any keyword arguments.
  
  Returns:
      The return value of ``optimizer.step(*args, **kwargs)``.  None when overflow or underflow
      gradients occur and optimizer.step() is skipped.
docstr_tok: [":","meth",":","`","step","`","unscale","the","gradients","and","step","the","optimizer",".","``","*","args","``","and","``","*","*","kwargs","``","are","forwarded","to","``","optimizer.step","(",")","``",".","Args",":","optimizer","(","torch.optim.Optimizer",")",":","Optimizer","that","applies","the","gradients",".","args",":","Any","arguments",".","kwargs",":","Any","keyword","arguments",".","Returns",":","The","return","value","of","``","optimizer.step","(","*","args",",","*","*","kwargs",")","``",".","None","when","overflow","or","underflow","gradients","occur","and","optimizer.step","(",")","is","skipped","."]
code: def step(self, optimizer, *args, **kwargs):  # type: ignore
      """
      :meth:`step` unscale the gradients and step the optimizer.
  
      ``*args`` and ``**kwargs`` are forwarded to ``optimizer.step()``.
  
      Args:
          optimizer (torch.optim.Optimizer):  Optimizer that applies the gradients.
          args:  Any arguments.
          kwargs:  Any keyword arguments.
  
      Returns:
          The return value of ``optimizer.step(*args, **kwargs)``.  None when overflow or underflow
          gradients occur and optimizer.step() is skipped.
      """
      if "closure" in kwargs:
          raise RuntimeError(
              "Closure use is not currently supported if DynamicLossScaler is enabled."
          )
  
      optimizer_state = self._per_optimizer_states[id(optimizer)]
  
      if optimizer_state is OptState.STEPPED:
          raise RuntimeError(
              "step() has already been called since the last update()."
          )
  
      # check gradient norm. If gradient norm is nan or inf, adjust scale here, and skip step.
      # clip_grads_norm can happen before this step
      for group in optimizer.param_groups:
          grad_norm = self._get_gradients_norm(group["params"])
          try:
              self._check_overflow(grad_norm)
          except OverflowError:
              return None
  
      if optimizer_state is OptState.READY:
          self.unscale_(optimizer)
          state_dict = optimizer.state_dict()
          state_dict["loss_scale"] = self.loss_scale
  
      retval = optimizer.step(*args, **kwargs)
  
      optimizer_state = OptState.STEPPED
  
      return retval
  
file_path: fairscale/fairscale/experimental/optim/dynamic_loss_scaler.py
imports: from collections import defaultdict
  from enum import Enum
  from typing import Dict, List, Optional
  import torch
label_desc: Use image node_id 7 for calling the DynamicLossScaler obj's underlying member method code with example usage: obj.step(optimizer) and returns: retval, None