code: def __init__(
      self,
      init_optimizer,
      static_loss_scale=1.0,
      dynamic_loss_scale=False,
      dynamic_loss_args=None,
      verbose=True,
  ):
      print(
          "Warning:  FP16_Optimizer is deprecated and dangerous, and will be deleted soon.  "
          "If it still works, you're probably getting lucky.  "
          "For mixed precision, use the documented API https://nvidia.github.io/apex/amp.html, with opt_level=O1."
      )
  
      from apex import deprecated_warning
  
      deprecated_warning(
          "apex.fp16_utils is deprecated and will be removed by the end of February 2023. Use [PyTorch AMP](https://pytorch.org/docs/stable/amp.html)"
      )
  
      if not torch.cuda.is_available:
          raise SystemError("Cannot use fp16 without CUDA.")
  
      self.verbose = verbose
  
      self.optimizer = init_optimizer
      # init_state_dict sets up an alternative way to cast per-param state tensors.
      # Stashing here in case https://github.com/pytorch/pytorch/issues/7733 makes it necessary.
      # init_state_dict = init_optimizer.state_dict()
  
      self.fp16_groups = []
      self.fp32_from_fp16_groups = []
      self.fp32_from_fp32_groups = []
      for i, param_group in enumerate(self.optimizer.param_groups):
          self.maybe_print(
              "FP16_Optimizer processing param group {}:".format(i)
          )
          fp16_params_this_group = []
          fp32_params_this_group = []
          fp32_from_fp16_params_this_group = []
          for i, param in enumerate(param_group["params"]):
              if param.requires_grad:
                  if param.type() == "torch.cuda.HalfTensor":
                      self.maybe_print(
                          "FP16_Optimizer received torch.cuda.HalfTensor with {}".format(
                              param.size()
                          )
                      )
                      fp16_params_this_group.append(param)
                      master_param = param.detach().clone().float()
                      master_param.requires_grad = True
                      param_group["params"][i] = master_param
                      fp32_from_fp16_params_this_group.append(
                          master_param
                      )
                      # Reset existing state dict key to the new master param.
                      # We still need to recast per-param state tensors, if any, to FP32.
                      if param in self.optimizer.state:
                          self.optimizer.state[
                              master_param
                          ] = self.optimizer.state.pop(param)
                  elif param.type() == "torch.cuda.FloatTensor":
                      self.maybe_print(
                          "FP16_Optimizer received torch.cuda.FloatTensor with {}".format(
                              param.size()
                          )
                      )
                      fp32_params_this_group.append(param)
                      param_group["params"][i] = param
                  else:
                      raise TypeError(
                          "Wrapped parameters must be either "
                          "torch.cuda.FloatTensor or torch.cuda.HalfTensor. "
                          "Received {}".format(param.type())
                      )
  
          self.fp16_groups.append(fp16_params_this_group)
          self.fp32_from_fp16_groups.append(
              fp32_from_fp16_params_this_group
          )
          self.fp32_from_fp32_groups.append(fp32_params_this_group)
  
      self.all_fp16_params = []
      for group in self.fp16_groups:
          self.all_fp16_params += group
  
      self.all_fp32_from_fp16_params = []
      for group in self.fp32_from_fp16_groups:
          self.all_fp32_from_fp16_params += group
  
      self.all_fp32_from_fp32_params = []
      for group in self.fp32_from_fp32_groups:
          self.all_fp32_from_fp32_params += group
  
      # Leverage state_dict() and load_state_dict() to recast preexisting per-param state tensors
      self.optimizer.load_state_dict(self.optimizer.state_dict())
      # alternative way to cast per-param state tensors:
      # self.optimizer.load_state_dict(init_state_dict)
  
      if dynamic_loss_scale:
          self.dynamic_loss_scale = True
          if dynamic_loss_args is not None:
              self.loss_scaler = LossScaler(
                  "dynamic", **dynamic_loss_args
              )
          else:
              self.loss_scaler = LossScaler("dynamic")
      else:
          self.dynamic_loss_scale = False
          self.loss_scaler = LossScaler(static_loss_scale)
  
      self.overflow = False
      self.first_closure_call_this_step = True
  
      self.clip_grad_norm = clip_grad_norm
  
      # TODO:  Centralize exposure and import error checking for the C backend.
      if multi_tensor_applier.available:
          import amp_C
  
          self.multi_tensor_scale = amp_C.multi_tensor_scale
          self._dummy_overflow_buf = torch.cuda.IntTensor([0])
  
imports: import torch
  from torch import nn
  from torch.autograd import Variable
  from torch.nn.parameter import Parameter
  from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
  from ..amp._amp_state import _amp_state, maybe_print
  from ..amp.scaler import LossScaler
  from ..multi_tensor_apply import multi_tensor_applier
  from .fp16util import model_grads_to_master_grads, master_params_to_model_params, clip_grad_norm
label_desc: Use image node_id 1 to create a new FP16_Optimizer object from inherited base classes: object with example: obj = FP16_Optimizer(init_optimizer, static_loss_scale, dynamic_loss_scale, dynamic_loss_args, verbose)