What problem does it solve?
This Skill prevents out-of-memory failures and subtle FSDP2 misconfigurations by showing how to add PyTorch FSDP2 (fully_shard) to a distributed training script with the correct initialization, sharding order, precision/offload settings, and checkpoint workflow.
Core Features & Use Cases
- Correct FSDP2 initialization and contract adherence: guides required launch, device setup, hook-safe forward invocation, and optimizer construction on DTensor parameters.
- Bottom-up parameter sharding with controlled resharding: explains why fully_shard must be applied to submodules first and how to tune reshard_after_forward for memory/performance trade-offs.
- Robust distributed checkpointing: recommends Distributed Checkpoint (DCP) or distributed state-dict helpers instead of naive torch.save for DTensor/FSDP2 models.
- Use Case: you are training a transformer-sized model that exceeds single-GPU memory and need sharded training that can later compose with other parallelism (e.g., DeviceMesh for hybrid strategies).
Quick Start
Use pytorch-fsdp2 to retrofit a training script so it launches with torchrun, applies fully_shard bottom-up with the right DeviceMesh options, builds the optimizer after sharding, and checkpoints with DCP safely.