class_docstr: Controller class for optimization. Mostly a thin
  wrapper for `optim`, but also useful for implementing
  rate scheduling beyond what is currently available.
  Also implements necessary methods for training RNNs such
  as grad manipulations.
  
  Args:
      optimizer: A ``torch.optim.Optimizer`` instance.
      learning_rate: The initial learning rate.
      learning_rate_decay_fn: An optional callable taking the current step
          as argument and return a learning rate scaling factor.
      max_grad_norm: Clip gradients to this global norm.
class_docstr_tok: ["Controller","class","for","optimization",".","Mostly","a","thin","wrapper","for","`","optim","`",",","but","also","useful","for","implementing","rate","scheduling","beyond","what","is","currently","available",".","Also","implements","necessary","methods","for","training","RNNs","such","as","grad","manipulations",".","Args",":","optimizer",":","A","``","torch.optim.Optimizer","``","instance",".","learning_rate",":","The","initial","learning","rate",".","learning_rate_decay_fn",":","An","optional","callable","taking","the","current","step","as","argument","and","return","a","learning","rate","scaling","factor",".","max_grad_norm",":","Clip","gradients","to","this","global","norm","."]
docstr: Update the model parameters based on current gradients.
  
  Optionally, will employ gradient modification or update learning
  rate.
docstr_tok: ["Update","the","model","parameters","based","on","current","gradients",".","Optionally",",","will","employ","gradient","modification","or","update","learning","rate","."]
code: def step(self):
      """Update the model parameters based on current gradients.
  
      Optionally, will employ gradient modification or update learning
      rate.
      """
      learning_rate = self.learning_rate()
  
      if self.amp:
          self._scaler.unscale_(self._optimizer)
      elif self._fp16 == "legacy":
          if hasattr(self._optimizer, "update_master_grads"):
              self._optimizer.update_master_grads()
          if (
              hasattr(self._optimizer, "clip_master_grads")
              and self._max_grad_norm > 0
          ):
              self._optimizer.clip_master_grads(self._max_grad_norm)
  
      for group in self._optimizer.param_groups:
          group["lr"] = learning_rate
          if self._max_grad_norm > 0 and self._fp16 != "legacy":
              clip_grad_norm_(group["params"], self._max_grad_norm)
  
      if self.amp:
          # unscaled optimizer's gradients (already done therefore skip),
          # skips optimizer.step() if gradients contain infs/NaNs.
          self._scaler.step(self._optimizer)
          # Updates the scale for next iteration.
          self._scaler.update()
      else:
          self._optimizer.step()
      self._decay_step += 1
      self._training_step += 1
  
imports: import torch
  import torch.optim
  from torch.nn.utils import clip_grad_norm_
  import operator
  import functools
  from copy import copy
  from math import sqrt
  import types
  import os
  import importlib
  from onmt.utils.misc import fn_args
label_desc: Use image node_id 10 for calling the Optimizer obj's underlying member method code with example usage: obj.step() without return types