pytorch-fsdp2

Set up PyTorch FSDP2 training with per-parameter DTensor sharding across devices.

2|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-config --skill pytorch-fsdp2-clay-hhk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/Clay-HHK/claude-config/tree/main/skills/AI-research-SKILLs/08-distributed-training/pytorch-fsdp2
Command: npx skills add https://github.com/Clay-HHK/claude-config --skill pytorch-fsdp2-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill helps you implement PyTorch FSDP2 fully_shard training to train models that don't fit on a single GPU, with correct initialization, per-parameter sharding using DeviceMesh, and robust checkpointing.

Core Features & Use Cases

  • Add FSDP2 to submodules bottom-up, configure mixed precision and optional CPU offload, and ensure optimizer is created after sharding.
  • Support DeviceMesh-based DTensor sharding, 2D hybrid sharding, and distributed checkpointing with DCP or state-dict helpers.
  • Use when you need DTensor-based sharding and scalable distributed training.

Quick Start

Configure a distributed run with torchrun, initialize a meta-model, apply fully_shard to submodules bottom-up, call fully_shard on the root, materialize weights to CUDA, and instantiate a DTensor-aware optimizer before training.

Frequently Asked Questions about pytorch-fsdp2

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up PyTorch FSDP2 training for a model that exceeds single-GPU memory?

To set up PyTorch FSDP2 training, initialize a meta-model, apply fully_shard to submodules bottom-up, call fully_shard on the root, materialize weights to CUDA, and instantiate a DTensor-aware optimizer before training.

What is per-parameter DTensor sharding and when do I need it for distributed training?

Per-parameter DTensor sharding uses DeviceMesh to distribute model parameters across devices. You need it when training large models that exceed a single-GPU memory and require scalable distributed training and checkpointing.

Can I use mixed precision and CPU offload with FSDP2 fully_shard?

Yes, you can configure mixed precision and optional CPU offload when applying FSDP2 fully_shard to submodules bottom-up, ensuring the optimizer is created only after sharding is complete.

Why does my DTensor-enabled optimizer fail after applying PyTorch FSDP2?

A DTensor-enabled optimizer fails if constructed before sharding. You must apply fully_shard bottom-up to submodules and the root, invoke model(inputs) to run hooks, then instantiate the optimizer.

What's the best way to checkpoint a model trained with PyTorch FSDP2 and DTensor?

The best way to checkpoint FSDP2 models is using distributed checkpointing workflows with DCP or distributed state-dict helpers, which properly manage DTensor state across devices.

Does PyTorch FSDP2 support 2D hybrid sharding with DeviceMesh?

Yes, PyTorch FSDP2 supports DeviceMesh-based 2D hybrid sharding, allowing you to combine DTensor sharding strategies for scalable distributed training across multiple devices.