class_docstr: Plugin for Automatic Mixed Precision (AMP) training with ``torch.autocast``.
  
  Args:
      precision: Whether to use ``torch.float16`` (``'16-mixed'``) or ``torch.bfloat16`` (``'bf16-mixed'``).
      device: The device for ``torch.autocast``.
      scaler: An optional :class:`torch.cuda.amp.GradScaler` to use.
code: def __init__(
      self,
      precision: Literal["16-mixed", "bf16-mixed"],
      device: str,
      scaler: Optional[torch.cuda.amp.GradScaler] = None,
  ) -> None:
      if precision not in ("16-mixed", "bf16-mixed"):
          raise ValueError(
              f"Passed `{type(self).__name__}(precision={precision!r})`."
              " Precision must be '16-mixed' or 'bf16-mixed'."
          )
  
      self.precision = precision
      if scaler is None and self.precision == "16-mixed":
          with _patch_cuda_is_available():
              # if possible, we defer CUDA initialization to support strategies that will attempt forks
              scaler = torch.cuda.amp.GradScaler()
      if scaler is not None and self.precision == "bf16-mixed":
          raise ValueError(
              f"`precision='bf16-mixed'` does not use a scaler, found {scaler}."
          )
      self.device = device
      self.scaler = scaler
  
      self._desired_input_dtype = (
          torch.bfloat16
          if self.precision == "bf16-mixed"
          else torch.float16
      )
  
imports: from typing import Any, ContextManager, Dict, Literal, Optional
  import torch
  from lightning_utilities.core.apply_func import apply_to_collection
  from torch import Tensor
  from torch.nn import Module
  from torch.optim import LBFGS, Optimizer
  from typing_extensions import override
  from lightning.fabric.accelerators.cuda import _patch_cuda_is_available
  from lightning.fabric.plugins.precision.precision import Precision
  from lightning.fabric.plugins.precision.utils import _convert_fp_tensor
  from lightning.fabric.utilities.types import Optimizable
label_desc: Use image node_id 1 to create a new MixedPrecision object from inherited base classes: Precision with example: obj = MixedPrecision(precision, device, scaler)