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 clip_gradients(
      self,
      optimizer: Optimizer,
      clip_val: Union[int, float] = 0.0,
      gradient_clip_algorithm: GradClipAlgorithmType = GradClipAlgorithmType.NORM,
  ) -> None:
      if clip_val > 0 and _optimizer_handles_unscaling(optimizer):
          raise RuntimeError(
              f"The current optimizer, {type(optimizer).__qualname__}, does not allow for gradient clipping"
              " because it performs unscaling of gradients internally. HINT: Are you using a 'fused' optimizer?"
          )
      super().clip_gradients(
          optimizer=optimizer,
          clip_val=clip_val,
          gradient_clip_algorithm=gradient_clip_algorithm,
      )
  
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 4 for calling the MixedPrecision obj's underlying member method code with example usage: obj.clip_gradients(optimizer, clip_val, gradient_clip_algorithm) without return types