MixedPrecision¶
- class lightning.pytorch.plugins.precision.MixedPrecision(precision, device, scaler=None)¶
Bases:
PrecisionPlugin for Automatic Mixed Precision (AMP) training with
torch.autocast.- Parameters:
- clip_gradients(optimizer, clip_val=0.0, gradient_clip_algorithm=GradClipAlgorithmType.NORM)¶
Clips the gradients.
- Return type:
- forward_context()¶
Enable autocast and clear cached casts after nested grad-disabling contexts exit.
- load_state_dict(state_dict)¶
Called when loading a checkpoint, implement to reload precision plugin state given precision plugin state_dict.
- optimizer_step(optimizer, model, closure, **kwargs)¶
Hook to run the optimizer step.
- Return type:
- pre_backward(tensor, module)¶
Runs before precision plugin executes backward.
- Parameters:
tensor¶ (
Tensor) – The tensor that will be used for backpropagationmodule¶ (
LightningModule) – The module that was involved in producing the tensor and whose parameters need the gradients
- Return type: