class_docstr: Implements LAMB algorithm.
  
  Currently GPU-only.  Requires Apex to be installed via
  ``pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./``.
  
  This version of fused LAMB implements 2 fusions.
  
    * Fusion of the LAMB update's elementwise operations
    * A multi-tensor apply launch that batches the elementwise updates applied to all the model's parameters into one or a few kernel launches.
  
  :class:`apex.optimizers.FusedLAMB`'s usage is identical to any ordinary Pytorch optimizer::
  
      opt = apex.optimizers.FusedLAMB(model.parameters(), lr = ....)
      ...
      opt.step()
  
  :class:`apex.optimizers.FusedLAMB` may be used with or without Amp.  If you wish to use :class:`FusedLAMB` with Amp,
  you may choose any ``opt_level``::
  
      opt = apex.optimizers.FusedLAMB(model.parameters(), lr = ....)
      model, opt = amp.initialize(model, opt, opt_level="O0" or "O1 or "O2")
      ...
      opt.step()
  
  In general, ``opt_level="O1"`` is recommended.
  
  LAMB was proposed in `Large Batch Optimization for Deep Learning: Training BERT in 76 minutes`_.
  
  Arguments:
      params (iterable): iterable of parameters to optimize or dicts defining
          parameter groups.
      lr (float, optional): learning rate. (default: 1e-3)
      betas (Tuple[float, float], optional): coefficients used for computing
          running averages of gradient and its norm. (default: (0.9, 0.999))
      eps (float, optional): term added to the denominator to improve
          numerical stability. (default: 1e-8)
      weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
      amsgrad (boolean, optional): whether to use the AMSGrad variant of this
          algorithm from the paper `On the Convergence of Adam and Beyond`_
          NOT SUPPORTED now! (default: False)
      adam_w_mode (boolean, optional): Apply L2 regularization or weight decay
          True for decoupled weight decay(also known as AdamW) (default: True)
      grad_averaging (bool, optional): whether apply (1-beta2) to grad when
          calculating running averages of gradient. (default: True)
      set_grad_none (bool, optional): whether set grad to None when zero_grad()
          method is called. (default: True)
      max_grad_norm (float, optional): value used to clip global grad norm
          (default: 1.0)
      use_nvlamb (boolean, optional): Apply adaptive learning rate to 0.0
          weight decay parameter (default: False)
      step_supports_amp_scaling(boolean, optional): whether to use customized
          gradient unscaling logic (default: True)
  
  .. _Large Batch Optimization for Deep Learning - Training BERT in 76 minutes:
      https://arxiv.org/abs/1904.00962
  .. _On the Convergence of Adam and Beyond:
      https://openreview.net/forum?id=ryQu7f-RZ
class_docstr_tok: ["Implements","LAMB","algorithm",".","Currently","GPU-only",".","Requires","Apex","to","be","installed","via","``","pip","install","-v","--","no-cache-dir","--","global-option=","''","--","cpp_ext","''","--","global-option=","''","--","cuda_ext","''",".\/","``",".","This","version","of","fused","LAMB","implements","2","fusions",".","*","Fusion","of","the","LAMB","update","'s","elementwise","operations","*","A","multi-tensor","apply","launch","that","batches","the","elementwise","updates","applied","to","all","the","model","'s","parameters","into","one","or","a","few","kernel","launches",".",":","class",":","`","apex.optimizers.FusedLAMB","`","'s","usage","is","identical","to","any","ordinary","Pytorch","optimizer",":",":","opt","=","apex.optimizers.FusedLAMB","(","model.parameters","(",")",",","lr","=","....",")","...","opt.step","(",")",":","class",":","`","apex.optimizers.FusedLAMB","`","may","be","used","with","or","without","Amp",".","If","you","wish","to","use",":","class",":","`","FusedLAMB","`","with","Amp",",","you","may","choose","any","``","opt_level","``",":",":","opt","=","apex.optimizers.FusedLAMB","(","model.parameters","(",")",",","lr","=","....",")","model",",","opt","=","amp.initialize","(","model",",","opt",",","opt_level=","''","O0","''","or","``","O1","or","``","O2","''",")","...","opt.step","(",")","In","general",",","``","opt_level=","''","O1","''","``","is","recommended",".","LAMB","was","proposed","in","`","Large","Batch","Optimization","for","Deep","Learning",":","Training","BERT","in","76","minutes","`","_",".","Arguments",":","params","(","iterable",")",":","iterable","of","parameters","to","optimize","or","dicts","defining","parameter","groups",".","lr","(","float",",","optional",")",":","learning","rate",".","(","default",":","1e-3",")","betas","(","Tuple","[","float",",","float","]",",","optional",")",":","coefficients","used","for","computing","running","averages","of","gradient","and","its","norm",".","(","default",":","(","0.9",",","0.999",")",")","eps","(","float",",","optional",")",":","term","added","to","the","denominator","to","improve","numerical","stability",".","(","default",":","1e-8",")","weight_decay","(","float",",","optional",")",":","weight","decay","(","L2","penalty",")","(","default",":","0",")","amsgrad","(","boolean",",","optional",")",":","whether","to","use","the","AMSGrad","variant","of","this","algorithm","from","the","paper","`","On","the","Convergence","of","Adam","and","Beyond","`","_","NOT","SUPPORTED","now","!","(","default",":","False",")","adam_w_mode","(","boolean",",","optional",")",":","Apply","L2","regularization","or","weight","decay","True","for","decoupled","weight","decay","(","also","known","as","AdamW",")","(","default",":","True",")","grad_averaging","(","bool",",","optional",")",":","whether","apply","(","1-beta2",")","to","grad","when","calculating","running","averages","of","gradient",".","(","default",":","True",")","set_grad_none","(","bool",",","optional",")",":","whether","set","grad","to","None","when","zero_grad","(",")","method","is","called",".","(","default",":","True",")","max_grad_norm","(","float",",","optional",")",":","value","used","to","clip","global","grad","norm","(","default",":","1.0",")","use_nvlamb","(","boolean",",","optional",")",":","Apply","adaptive","learning","rate","to","0.0","weight","decay","parameter","(","default",":","False",")","step_supports_amp_scaling","(","boolean",",","optional",")",":","whether","to","use","customized","gradient","unscaling","logic","(","default",":","True",")","..","_Large","Batch","Optimization","for","Deep","Learning","-","Training","BERT","in","76","minutes",":","https",":","\/\/arxiv.org\/abs\/1904.00962","..","_On","the","Convergence","of","Adam","and","Beyond",":","https",":","\/\/openreview.net\/forum","?","id=ryQu7f-RZ"]
docstr: Returns a dict containing the current state of this :class:`DistributedFusedAdam` instance.
  Example::
      checkpoint = {}
      checkpoint['model'] = model.state_dict()
      checkpoint['optimizer'] = optimizer.state_dict()
      torch.save(checkpoint, "saved.pth")
docstr_tok: ["Returns","a","dict","containing","the","current","state","of","this",":","class",":","`","DistributedFusedAdam","`","instance",".","Example",":",":","checkpoint","=","{","}","checkpoint","[","'model","'","]","=","model.state_dict","(",")","checkpoint","[","'optimizer","'","]","=","optimizer.state_dict","(",")","torch.save","(","checkpoint",",","``","saved.pth","''",")"]
code: def state_dict(self):
      """
      Returns a dict containing the current state of this :class:`DistributedFusedAdam` instance.
      Example::
          checkpoint = {}
          checkpoint['model'] = model.state_dict()
          checkpoint['optimizer'] = optimizer.state_dict()
          torch.save(checkpoint, "saved.pth")
      """
      # save step, master weights and first/second moments
      state_dict = {}
      state_dict["step"] = self._step
      state_dict["fp32_p"] = self._fp32_p
      state_dict["fp32_m"] = self._fp32_m
      state_dict["fp32_v"] = self._fp32_v
      return state_dict
  
imports: import os
  import math
  import inspect
  import torch
  import importlib
  import amp_C
  from apex.multi_tensor_apply import multi_tensor_applier
  import torch.distributed.distributed_c10d
label_desc: Use image node_id 22 for calling the DistributedFusedLAMB obj's underlying member method code with example usage: obj.state_dict() and returns: state_dict