class_docstr: Implements Adam 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 Adam implements 2 fusions.
  
    * Fusion of the Adam 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.FusedAdam` may be used as a drop-in replacement for ``torch.optim.AdamW``,
  or ``torch.optim.Adam`` with ``adam_w_mode=False``::
  
      opt = apex.optimizers.FusedAdam(model.parameters(), lr = ....)
      ...
      opt.step()
  
  :class:`apex.optimizers.FusedAdam` may be used with or without Amp.  If you wish to use :class:`FusedAdam` with Amp,
  you may choose any ``opt_level``::
  
      opt = apex.optimizers.FusedAdam(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.
  
  
  .. warning::
      A previous version of :class:`FusedAdam` allowed a number of additional arguments to ``step``.  These additional arguments
      are now deprecated and unnecessary.
  
  Adam was been proposed in `Adam: A Method for Stochastic Optimization`_.
  
  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 square. (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`_
          (default: False) NOT SUPPORTED in FusedAdam!
      adam_w_mode (boolean, optional): Apply L2 regularization or weight decay
          True for decoupled weight decay(also known as AdamW) (default: True)
      set_grad_none (bool, optional): whether set grad to None when zero_grad()
          method is called. (default: True)
      capturable (bool, optional): whether to use the version of the optimizer
          that can be used with CUDA Graphs. (default: False)
      master_weights (bool, optional): whether to maintain FP32 master weights
         in the optimizer with FP16 mixed precision training, currently can
         only be used with capturable set to True. (default: False)
  
  .. _Adam - A Method for Stochastic Optimization:
      https://arxiv.org/abs/1412.6980
  .. _On the Convergence of Adam and Beyond:
      https://openreview.net/forum?id=ryQu7f-RZ
class_docstr_tok: ["Implements","Adam","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","Adam","implements","2","fusions",".","*","Fusion","of","the","Adam","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.FusedAdam","`","may","be","used","as","a","drop-in","replacement","for","``","torch.optim.AdamW","``",",","or","``","torch.optim.Adam","``","with","``","adam_w_mode=False","``",":",":","opt","=","apex.optimizers.FusedAdam","(","model.parameters","(",")",",","lr","=","....",")","...","opt.step","(",")",":","class",":","`","apex.optimizers.FusedAdam","`","may","be","used","with","or","without","Amp",".","If","you","wish","to","use",":","class",":","`","FusedAdam","`","with","Amp",",","you","may","choose","any","``","opt_level","``",":",":","opt","=","apex.optimizers.FusedAdam","(","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",".","..","warning",":",":","A","previous","version","of",":","class",":","`","FusedAdam","`","allowed","a","number","of","additional","arguments","to","``","step","``",".","These","additional","arguments","are","now","deprecated","and","unnecessary",".","Adam","was","been","proposed","in","`","Adam",":","A","Method","for","Stochastic","Optimization","`","_",".","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","square",".","(","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","`","_","(","default",":","False",")","NOT","SUPPORTED","in","FusedAdam","!","adam_w_mode","(","boolean",",","optional",")",":","Apply","L2","regularization","or","weight","decay","True","for","decoupled","weight","decay","(","also","known","as","AdamW",")","(","default",":","True",")","set_grad_none","(","bool",",","optional",")",":","whether","set","grad","to","None","when","zero_grad","(",")","method","is","called",".","(","default",":","True",")","capturable","(","bool",",","optional",")",":","whether","to","use","the","version","of","the","optimizer","that","can","be","used","with","CUDA","Graphs",".","(","default",":","False",")","master_weights","(","bool",",","optional",")",":","whether","to","maintain","FP32","master","weights","in","the","optimizer","with","FP16","mixed","precision","training",",","currently","can","only","be","used","with","capturable","set","to","True",".","(","default",":","False",")","..","_Adam","-","A","Method","for","Stochastic","Optimization",":","https",":","\/\/arxiv.org\/abs\/1412.6980","..","_On","the","Convergence","of","Adam","and","Beyond",":","https",":","\/\/openreview.net\/forum","?","id=ryQu7f-RZ"]
code: def zero_grad(self):
      if self.set_grad_none:
          for group in self.param_groups:
              for p in group["params"]:
                  p.grad = None
      else:
          super(FusedAdam, self).zero_grad()
  
imports: import torch
  from apex.multi_tensor_apply import multi_tensor_applier
label_desc: Use image node_id 2 for calling the FusedAdam obj's underlying member method code with example usage: obj.zero_grad() without return types