pytorch-fsdp2

Integrate PyTorch FSDP2 fully_shard into training scripts for distributed model training.

1|Updated Feb 21, 2026
One-click install
npx skills add https://github.com/tianhao909/AI-Research-SKILLs-cn --skill pytorch-fsdp2-tianhao909
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/tianhao909/AI-Research-SKILLs-cn/tree/main/08-distributed-training/pytorch-fsdp2
Command: npx skills add https://github.com/tianhao909/AI-Research-SKILLs-cn --skill pytorch-fsdp2-tianhao909

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill enables training of large PyTorch models that exceed single-GPU memory by correctly implementing PyTorch's Fully Sharded Data Parallelism (FSDP2), including distributed checkpointing and mixed precision.

Core Features & Use Cases

  • Model Parallelism: Distributes model parameters, gradients, and optimizer states across multiple GPUs and nodes.
  • Memory Optimization: Reduces peak memory usage per GPU, allowing for larger models.
  • Distributed Checkpointing: Integrates with PyTorch's Distributed Checkpoint (DCP) for robust saving and loading of distributed states.
  • Mixed Precision & Offload: Configures mixed precision training and CPU offloading for further memory and performance gains.
  • Use Case: Train a multi-billion parameter language model by sharding its components across a cluster of GPUs, ensuring efficient memory utilization and fault-tolerant checkpointing.

Quick Start

Launch your PyTorch training script using torchrun, ensuring distributed initialization and applying the fully_shard wrapper bottom-up to your model's submodules before the root.

Frequently Asked Questions about pytorch-fsdp2

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

FAQPage Schema
How do I train large PyTorch models that exceed single-GPU memory limits?

To train large PyTorch models exceeding single-GPU memory, you can use PyTorch FSDP2 to distribute parameters, gradients, and optimizer states across multiple GPUs. This Skill integrates fully_shard to manage sharding and reduce peak memory per device.

What is the best way to set up distributed checkpointing for FSDP2 training?

The best way to set up distributed checkpointing for FSDP2 is using PyTorch's Distributed Checkpoint (DCP). This Skill configures DCP to robustly save and load distributed model states, ensuring fault tolerance during multi-GPU training.

How does bottom-up sharding work when applying fully_shard to a model?

Bottom-up sharding with fully_shard works by applying the wrapper to a model's submodules before the root module. This approach correctly initializes distributed sharding using DTensor and DeviceMesh for advanced parallelism.

Can I use mixed precision and CPU offloading with PyTorch distributed training?

Yes, you can use mixed precision and CPU offloading with PyTorch distributed training. This Skill configures both features to provide further memory reductions and performance optimizations during large model training.

Do I need torchrun to launch training scripts for multi-GPU model parallelism?

Yes, you need torchrun to launch your PyTorch training scripts for multi-GPU model parallelism. It ensures correct distributed initialization before applying the fully_shard wrapper for bottom-up sharding across your cluster.

Why does my PyTorch FSDP2 setup fail to shard models across multiple nodes?

PyTorch FSDP2 setup may fail to shard models if fully_shard is not applied bottom-up to submodules before the root, or if DeviceMesh and DTensor are not correctly initialized for distributed training across nodes.