class_docstr: :class:`FP16_Optimizer` A cutdown version of apex.fp16_utils.FP16_Optimizer.
  Designed only to wrap apex.contrib.optimizers.FusedAdam, FusedSGD.
  Refer to apex.fp16_utils documents for more information.
  Example::
      model = torch.nn.Linear(D_in, D_out).cuda().half()
      optimizer = apex.contrib.optimizers.FusedSGD(model.parameters())
      optimizer = FP16_Optimizer(optimizer, static_loss_scale = 128.0)
      ...
      # loss.backward() becomes:
      optimizer.backward(loss)
      ...
  Example with dynamic loss scaling::
      ...
      optimizer = FP16_Optimizer(optimizer, dynamic_loss_scale=True)
                                 # optional arg to control dynamic loss scaling behavior
                                 # dynamic_loss_args={'scale_window' : 500})
                                 # Usually, dynamic_loss_args is not necessary.
class_docstr_tok: [":","class",":","`","FP16_Optimizer","`","A","cutdown","version","of","apex.fp16_utils.FP16_Optimizer",".","Designed","only","to","wrap","apex.contrib.optimizers.FusedAdam",",","FusedSGD",".","Refer","to","apex.fp16_utils","documents","for","more","information",".","Example",":",":","model","=","torch.nn.Linear","(","D_in",",","D_out",")",".cuda","(",")",".half","(",")","optimizer","=","apex.contrib.optimizers.FusedSGD","(","model.parameters","(",")",")","optimizer","=","FP16_Optimizer","(","optimizer",",","static_loss_scale","=","128.0",")","...","#","loss.backward","(",")","becomes",":","optimizer.backward","(","loss",")","...","Example","with","dynamic","loss","scaling",":",":","...","optimizer","=","FP16_Optimizer","(","optimizer",",","dynamic_loss_scale=True",")","#","optional","arg","to","control","dynamic","loss","scaling","behavior","#","dynamic_loss_args=","{","'scale_window","'",":","500","}",")","#","Usually",",","dynamic_loss_args","is","not","necessary","."]
docstr: Not supporting closure.
docstr_tok: ["Not","supporting","closure","."]
code: def step(self, closure=None):
      """
      Not supporting closure.
      """
      fp16_grads = []
      norm_groups = []
      skip = False
  
      for group in self.fp16_groups:
          fp16_grad = []
          for i, p in enumerate(group):
              fp16_grad.append(p.grad)
          fp16_grads.append(fp16_grad)
  
      # nan check
      self.overflow_buf.zero_()
      for fp16_grad in fp16_grads:
          if len(fp16_grad) > 0:
              norm, norm_per_tensor = multi_tensor_applier(
                  self.multi_tensor_l2norm,
                  self.overflow_buf,
                  [fp16_grad],
                  True,
              )
              norm_groups.append(norm)
              if self.overflow_buf.item() != 0:
                  skip = True
  
      if skip:
          self._update_scale(skip)
          return
  
      # norm is in fact norm*cur_scale
      self.optimizer.step(
          grads=fp16_grads,
          output_params=self.fp16_groups,
          scale=self.cur_scale,
          grad_norms=norm_groups,
      )
  
      self._update_scale(False)
      return
  
file_path: apex/apex/contrib/optimizers/fp16_optimizer.py
imports: import torch
  from apex.multi_tensor_apply import multi_tensor_applier
label_desc: Use image node_id 3 for calling the FP16_Optimizer obj's underlying member method code with example usage: obj.step(closure) without return types