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: Returns a dict containing the current state of this :class:`FP16_Optimizer` instance.
  This dict contains attributes of :class:`FP16_Optimizer`, as well as the state_dict
  of the contained Pytorch optimizer.
  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",":","`","FP16_Optimizer","`","instance",".","This","dict","contains","attributes","of",":","class",":","`","FP16_Optimizer","`",",","as","well","as","the","state_dict","of","the","contained","Pytorch","optimizer",".","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:`FP16_Optimizer` instance.
      This dict contains attributes of :class:`FP16_Optimizer`, as well as the state_dict
      of the contained Pytorch optimizer.
      Example::
          checkpoint = {}
          checkpoint['model'] = model.state_dict()
          checkpoint['optimizer'] = optimizer.state_dict()
          torch.save(checkpoint, "saved.pth")
      """
      state_dict = {}
      state_dict["dynamic_loss_scale"] = self.dynamic_loss_scale
      state_dict["cur_scale"] = self.cur_scale
      state_dict["cur_iter"] = self.cur_iter
      if state_dict["dynamic_loss_scale"]:
          state_dict["last_overflow_iter"] = self.last_overflow_iter
          state_dict["scale_factor"] = self.scale_factor
          state_dict["scale_window"] = self.scale_window
      state_dict["optimizer_state_dict"] = self.optimizer.state_dict()
      state_dict["fp32_groups"] = self.fp32_groups
      return state_dict
  
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 10 for calling the FP16_Optimizer obj's underlying member method code with example usage: obj.state_dict() and returns: state_dict