MixedPrecision
- class lightning.fabric.plugins.precision.MixedPrecision(precision, device, scaler=None)
Bases:
PrecisionPlugin for Automatic Mixed Precision (AMP) training with
torch.autocast.- Parameters:
precision (
Literal['16-mixed','bf16-mixed']) – Whether to usetorch.float16('16-mixed') ortorch.bfloat16('bf16-mixed').device (
str) – The device fortorch.autocast.scaler (
Optional[GradScaler]) – An optionaltorch.cuda.amp.GradScalerto use.
- backward(tensor, model, *args, **kwargs)
Performs the actual backpropagation.
- convert_input(data)
Convert model inputs (forward) to the floating point precision type of this plugin.
This is a no-op in the base precision plugin, since we assume the data already has the desired type (default is torch.float32).
- Return type:
- convert_output(data)
Convert outputs to the floating point precision type expected after model’s forward.
This is a no-op in the base precision plugin, since we assume the data already has the desired type (default is torch.float32).
- Return type:
- forward_context()
A contextmanager for managing model forward/training_step/evaluation_step/predict_step.
- Return type:
- load_state_dict(state_dict)
Called when loading a checkpoint, implement to reload precision plugin state given precision plugin state_dict.
- optimizer_step(optimizer, **kwargs)
Hook to run the optimizer step.
- Return type:
Was this page helpful?
Thanks for the feedback.