FSDPPrecision¶
- class lightning.pytorch.plugins.precision.FSDPPrecision(precision, scaler=None)¶
Bases:
PrecisionPrecision plugin for training with Fully Sharded Data Parallel (FSDP).
Warning
This is an experimental feature.
- Parameters:
- Raises:
ValueError – If unsupported
precisionis provided.
- 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_module(module)¶
Convert the module parameters to the precision type this plugin handles.
This is optional and depends on the precision limitations during optimization.
- 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.
- module_init_context()¶
Instantiate module parameters or tensors in the precision type this plugin handles.
This is optional and depends on the precision limitations during optimization.
- Return type:
- 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:
- state_dict()¶
Called when saving a checkpoint, implement to generate precision plugin state_dict.
- tensor_init_context()¶
Controls how tensors get created (device, dtype).
- Return type: