pytorch-fsdp2
Agent skill fromOrchestra-Research/AI-Research-SKILLs
Adds PyTorch FSDP2 (fully_shard) to training scripts with correct init, sharding, mixed precision/offload config, and distributed checkpointing. Use when models exceed single-GPU memory or when you need DTensor-based sharding with DeviceMesh.
How to install pytorch-fsdp2
install pytorch-fsdp2
# install the AI-Research-SKILLs pack with the skills CLI
npx skills add Orchestra-Research/AI-Research-SKILLs# or add only this skill to Claude Code: copy the folder
08-distributed-training/pytorch-fsdp2/
# into
~/.claude/skills/pytorch-fsdp2/ (all projects)
.claude/skills/pytorch-fsdp2/ (one project)
1# Skill: Use PyTorch FSDP2 (`fully_shard`) correctly in a training script23This skill teaches a coding agent how to **add PyTorch FSDP2** to a training loop with correct initialization, sharding, mixed precision/offload configuration, and checkpointing.45> FSDP2 in PyTorch is exposed primarily via `torch.distributed.fsdp.fully_shard` and the `FSDPModule` methods it adds in-place to modules. See: `references/pytorch_fully_shard_api.md`, `references/pytorch_fsdp2_tutorial.md`.67---89## When to use this skill1011Use FSDP2 when:12- Your model **doesn’t fit** on one GPU (parameters + gradients + optimizer state).13- You want an eager-mode sharding approach that is **DTensor-based per-parameter sharding** (more inspectable, simpler sharded state dicts) than FSDP1.14- You may later compose DP with **Tensor Parallel** using **DeviceMesh**.1516Avoid (or be careful) if:17- You need strict backwards-compatible checkpoints across PyTorch versions (DCP warns against this).18- You’re forced onto older PyTorch versions without the FSDP2 stack.1920## Alternatives (when FSDP2 is not the best fit)2122- **DistributedDataParallel (DDP)**: Use the standard data-parallel wrapper when you want classic distributed data parallel training.23- **FullyShardedDataParallel (FSDP1)**: Use the original FSDP wrapper for parameter sharding across data-parallel workers.2425Reference: `references/pytorch_ddp_notes.md`, `references/pytorch_fsdp1_api.md`.2627---2829## Contract the agent must follow30…
Excerpt shown under the repository's MIT license.
