pytorch-fsdp2

Integrate PyTorch FSDP2 with parameter sharding and distributed checkpointing.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/gagan114662/content_books --skill pytorch-fsdp2-gagan114662
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/gagan114662/content_books/tree/main/AI-research-SKILLs/08-distributed-training/pytorch-fsdp2
Command: npx skills add https://github.com/gagan114662/content_books --skill pytorch-fsdp2-gagan114662

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enables training of PyTorch models that exceed single-GPU memory capacity by efficiently sharding model parameters, gradients, and optimizer states across multiple GPUs.

Core Features & Use Cases

  • Distributed Training: Implements PyTorch FSDP2 for large model training.
  • Memory Optimization: Reduces peak memory usage per GPU through parameter sharding.
  • Mixed Precision & Offload: Configurable mixed precision and CPU offloading for further memory savings.
  • Distributed Checkpointing: Integrates with PyTorch Distributed Checkpoint (DCP) for robust saving and loading.
  • Use Case: Training a massive language model that requires more VRAM than available on any single GPU, distributing the workload across a cluster of GPUs.

Quick Start

Use the pytorch-fsdp2 skill to add PyTorch FSDP2 to your training script, configuring it for distributed checkpointing and mixed precision.

Frequently Asked Questions about pytorch-fsdp2

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

FAQPage Schema
How do I train a PyTorch model that exceeds single-GPU memory capacity?

To train a PyTorch model exceeding single-GPU memory capacity, shard parameters, gradients, and optimizer states across multiple GPUs using Fully Sharded Data Parallel (FSDP2). This reduces peak memory per GPU by distributing the workload across a cluster.

How does FSDP2 parameter sharding work with DTensor for distributed training?

FSDP2 parameter sharding uses the fully_shard API to distribute model parameters as DTensor objects across a DeviceMesh. This enables multi-dimensional parallelism, allowing efficient memory management and distributed training across GPUs.

Can I use mixed precision and CPU offloading with PyTorch FSDP2?

Yes, you can configure mixed precision and CPU offloading with PyTorch FSDP2. These features provide further memory savings by offloading parameters to CPU and reducing the memory footprint of numerical computations during large-scale training.

How do I save and load distributed checkpoints in PyTorch FSDP2?

Save and load distributed checkpoints in PyTorch FSDP2 using PyTorch Distributed Checkpoint (DCP). It integrates directly with the training script to robustly manage saving and loading model states across multiple GPUs.

What is the best way to configure an optimizer for FSDP2 sharded parameters?

Configure the optimizer directly on the DTensor parameters after applying fully_shard. This ensures the optimizer states are correctly sharded across the DeviceMesh, maintaining memory efficiency during large model training.

When do I need DeviceMesh for multi-dimensional parallelism in PyTorch?

You need DeviceMesh for multi-dimensional parallelism when training massive models across a cluster of GPUs. It works with FSDP2 to coordinate parameter sharding and distributed training across multiple parallelism dimensions simultaneously.