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})`."
              f" 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 MisconfigurationException(
              f"`precision='bf16-mixed'` does not use a scaler, found {scaler}."
          )
      self.device = device
      self.scaler = scaler
  
imports: from contextlib import contextmanager
  from typing import Any, Callable, Dict, Generator, Literal, Optional, Union
  import torch
  from torch import Tensor
  from torch.optim import LBFGS, Optimizer
  from typing_extensions import override
  import lightning.pytorch
  from lightning.fabric.accelerators.cuda import _patch_cuda_is_available
  from lightning.fabric.plugins.precision.amp import _optimizer_handles_unscaling
  from lightning.fabric.utilities.types import Optimizable
  from lightning.pytorch.plugins.precision.precision import Precision
  from lightning.pytorch.utilities import GradClipAlgorithmType
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
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)