pytorch-fsdp2

Apply FSDP2 cross-device sharding with DTensor and DeviceMesh for PyTorch training.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/t2ance/dr-claw-plugin --skill pytorch-fsdp2-t2ance
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/t2ance/dr-claw-plugin/tree/main/plugins/ml-training-stack/skills/distributed-training/pytorch-fsdp2
Command: npx skills add https://github.com/t2ance/dr-claw-plugin --skill pytorch-fsdp2-t2ance

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, and includes references (resource) components.

What problem does it solve?

Large-model training often cannot fit on a single GPU, and users need deterministic, DTensor-based per-parameter sharding with DeviceMesh support. This skill provides a practical blueprint to apply PyTorch FSDP2 across submodules, manage mixed-precision/offload, and coordinate distributed checkpointing.

Core Features & Use Cases

  • Bottom-up sharding of submodules before the root to form efficient communication groups.
  • DTensor-based per-parameter sharding with DeviceMesh integration for scalable transformer-style models.
  • Flexible checkpointing via DCP/state-dict helpers to save/load distributed state.

Quick Start

Initialize distributed training with torchrun and wrap the model with fully_shard in a bottom-up manner, then begin training.

Frequently Asked Questions about pytorch-fsdp2

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

FAQPage Schema
How do I shard a large PyTorch model that exceeds single-GPU memory?▼

To shard a large PyTorch model that exceeds single-GPU memory, apply FSDP2 cross-device sharding to submodules. Use DTensor-based per-parameter sharding with DeviceMesh, enforcing bottom-up sharding before the root to form efficient communication groups.

What is the correct order for applying FSDP2 sharding to transformer submodules?▼

The correct order for applying FSDP2 sharding is bottom-up. You must shard submodules before the root module to form efficient communication groups, then create the optimizer post-sharding to ensure distributed training works correctly.

Does PyTorch FSDP2 support distributed checkpointing across multiple workers?▼

Yes, PyTorch FSDP2 supports distributed checkpointing across workers. It provides flexible checkpointing via DCP and state-dict helpers to save and load distributed state across multiple devices during scalable training.

Can I use DTensor and DeviceMesh for per-parameter sharding in PyTorch?▼

Yes, you can use DTensor and DeviceMesh for per-parameter sharding in PyTorch. FSDP2 integrates DTensor-based per-parameter sharding with DeviceMesh to provide scalable sharding for transformer-style models.

Do I need to create the optimizer before or after applying FSDP2 sharding?▼

You need to create the optimizer after applying FSDP2 sharding. The skill enforces post-sharding optimizer creation, ensuring the optimizer operates on the sharded parameters managed by DTensor and DeviceMesh.

What are the limitations of using FSDP2 for distributed training?▼

A limitation of using FSDP2 is that it requires PyTorch and careful bottom-up sharding of submodules. Users must manage mixed-precision and offload settings, and coordinate distributed checkpointing using DCP and state-dict workflows.