FSDPPrecision — PyTorch Lightning 2.5.1.post0 documentation (original) (raw)

class lightning.pytorch.plugins.precision.FSDPPrecision(precision, scaler=None)[source]

Bases: Precision

Precision plugin for training with Fully Sharded Data Parallel (FSDP).

Parameters:

Raises:

ValueError – If unsupported precision is provided.

clip_grad_by_norm(*_, **__)[source]

Clip gradients by norm.

Return type:

None

convert_input(data)[source]

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:

Any

convert_module(module)[source]

Convert the module parameters to the precision type this plugin handles.

This is optional and depends on the precision limitations during optimization.

Return type:

Module

convert_output(data)[source]

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:

Any

forward_context()[source]

A contextmanager for managing model forward/training_step/evaluation_step/predict_step.

Return type:

AbstractContextManager

load_state_dict(state_dict)[source]

Called when loading a checkpoint, implement to reload precision plugin state given precision plugin state_dict.

Parameters:

state_dict (dict[str, Any]) – the precision plugin state returned by state_dict.

Return type:

None

module_init_context()[source]

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:

AbstractContextManager

optimizer_step(optimizer, model, closure, **kwargs)[source]

Hook to run the optimizer step.

Return type:

Any

pre_backward(tensor, module)[source]

Runs before precision plugin executes backward.

Parameters:

Return type:

Tensor

state_dict()[source]

Called when saving a checkpoint, implement to generate precision plugin state_dict.

Return type:

dict[str, Any]

Returns:

A dictionary containing precision plugin state.

tensor_init_context()[source]

Controls how tensors get created (device, dtype).

Return type:

AbstractContextManager