class_docstr: Run training in mixed precision
class_docstr_tok: ["Run","training","in","mixed","precision"]
code: def before_fit(self):
      assert (
          self.dls.device.type == "cuda"
      ), "Mixed-precision training requires a GPU, remove the call `to_fp16`"
      if self.learn.opt is None:
          self.learn.create_opt()
      self.model_pgs, self.master_pgs = get_master(
          self.opt, self.flat_master
      )
      self.old_pgs = self.opt.param_lists
      # Changes the optimizer so that the optimization step is done in FP32.
      _copy_state(self.learn.opt, self.model_pgs, self.master_pgs)
      if self.dynamic:
          self.count = 0
  
imports: from __future__ import annotations
  from ..basics import *
  from .progress import *
  from torch.cuda.amp import GradScaler, autocast
  from torch.cuda.amp.grad_scaler import OptState
  from ..fp16_utils import convert_network, model_grads_to_master_grads, master_params_to_model_params
  from torch.nn.utils import parameters_to_vector
label_desc: Use image node_id 2 for calling the NonNativeMixedPrecision obj's underlying member method code with example usage: obj.before_fit() without return types