This teaches Claude to correctly implement PyTorch's FSDP2 (the DTensor-based sharding API via fully_shard) in training scripts. It covers the full setup: launching with torchrun, applying bottom-up sharding to submodules before the root, creating optimizers after sharding so they see DTensor parameters, and checkpointing with Distributed Checkpoint or the state dict helpers. The skill is opinionated about the right patterns (use model() not model.forward(), never naively torch.save DTensor state dicts) and includes concrete migration steps from meta device initialization through mixed precision config. Use this when your model won't fit on one GPU or you want cleaner per-parameter sharding than FSDP1.

skills.sh installs
1K
GitHub stars
14.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add orchestra-research/ai-research-skills --skill pytorch-fsdp2 --agent claude-code

Installs into .claude/skills of the current project.

Files

Skill: Use PyTorch FSDP2 (fully_shard) correctly in a training script

This skill teaches a coding agent how to add PyTorch FSDP2 to a training loop with correct initialization, sharding, mixed precision/offload configuration, and checkpointing.

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.


When to use this skill

Use FSDP2 when:

  • Your model doesn’t fit on one GPU (parameters + gradients + optimizer state).
  • You want an eager-mode sharding approach that is DTensor-based per-parameter sharding (more inspectable, simpler sharded state dicts) than FSDP1.
  • You may later compose DP with Tensor Parallel using DeviceMesh.

Avoid (or be careful) if:

  • You need strict backwards-compatible checkpoints across PyTorch versions (DCP warns against this).
  • You’re forced onto older PyTorch versions without the FSDP2 stack.

Alternatives (when FSDP2 is not the best fit)

Sponsors

Details

Repository
github.com/orchestra-research/ai-research-skills
Categories
AI & Agent Building, Data Science & ML
First seen
Jun 3, 2026

More from orchestra-research/ai-research-skills

All 95
1orchestra-research avatarmodal-serverless-gpuorchestra-research/ai-research-skillsServerless GPU cloud platform for running ML workloads. Use when you need on-demand GPU access without infrastructure management, deploying ML models as APIs, o1Kskills.sh installs
2orchestra-research avatarmoe-trainingorchestra-research/ai-research-skillsTrain Mixture of Experts (MoE) models using DeepSpeed or HuggingFace. Use when training large-scale models with limited compute (5× cost reduction vs dense mode1Kskills.sh installs
3orchestra-research avatarllama-factoryorchestra-research/ai-research-skillsExpert guidance for fine-tuning LLMs with LLaMA-Factory - WebUI no-code, 100+ models, 2/3/4/5/6/8-bit QLoRA, multimodal support1Kskills.sh installs
4orchestra-research avatarmodel-mergingorchestra-research/ai-research-skillsMerge multiple fine-tuned models using mergekit to combine capabilities without retraining. Use when creating specialized models by blending domain-specific exp1Kskills.sh installs
5orchestra-research avatartransformer-lens-interpretabilityorchestra-research/ai-research-skillsProvides guidance for mechanistic interpretability research using TransformerLens to inspect and manipulate transformer internals via HookPoints and activation 1Kskills.sh installs
6orchestra-research avataropenrlhf-trainingorchestra-research/ai-research-skillsHigh-performance RLHF framework with Ray+vLLM acceleration. Use for PPO, GRPO, RLOO, DPO training of large models (7B-70B+). Built on Ray, vLLM, ZeRO-3. 2× fast1Kskills.sh installs