pytorch-fsdp

Codify PyTorch FSDP2 training with per-parameter sharding across GPUs.

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/nadicodeai/argo-agent --skill pytorch-fsdp-nadicodeai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp
Source: https://github.com/nadicodeai/argo-agent/tree/main/optional-skills/mlops/pytorch-fsdp
Command: npx skills add https://github.com/nadicodeai/argo-agent --skill pytorch-fsdp-nadicodeai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Comprehensive guidance for Fully Sharded Data Parallel (FSDP) in PyTorch to enable memory-efficient, scalable distributed training across GPUs and nodes.

Core Features & Use Cases

  • Expert guidance on PyTorch FSDP2 with per-parameter sharding and DTensors.
  • Covers pre-forward and post-backward hooks, all-gather, and reduce-scatter patterns for efficient training.
  • Use cases include training very large models with limited memory, migrating from FSDP1 to FSDP2, and optimizing memory and compute balance in multi-GPU environments.

Quick Start

Apply fully_shard to your model and follow pre-forward hooks to all-gather parameters before training.

Frequently Asked Questions about pytorch-fsdp

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

FAQPage Schema
How do I use PyTorch FSDP to train large models with limited GPU memory?

PyTorch FSDP enables memory-efficient distributed training by sharding model parameters, gradients, and optimizer states across GPUs. You apply it to your model to distribute memory usage, allowing you to train models that exceed a single GPU's memory capacity.

What is the difference between FSDP1 and FSDP2 in PyTorch?

FSDP2 introduces per-parameter sharding and utilizes DTensors, moving away from FSDP1's module-level sharding. This newer approach offers finer memory control and simplifies advanced distributed training patterns compared to FSDP1.

How do I migrate my distributed training pipeline from FSDP1 to FSDP2?

Migrating to FSDP2 involves transitioning to per-parameter sharding using DTensors and device meshes. You must adapt your code to use the `fully_shard` API and adjust pre-forward and post-backward hooks for all-gather and reduce-scatter operations.

Do I need PyTorch 2.x to use per-parameter sharding with FSDP2?

Yes, PyTorch 2.x is required to use FSDP2 features like per-parameter sharding and DTensors. A compatible multi-GPU or multi-node mesh setup is also necessary to correctly distribute parameters and execute the training pipeline.

How do all-gather and reduce-scatter hooks work in PyTorch distributed training?

Pre-forward hooks trigger all-gather operations to collect sharded parameters before computation, while post-backward hooks trigger reduce-scatter operations to sync gradients. This ensures parameters are fully materialized in memory only when actively needed.

What is the best way to optimize memory and compute balance across multiple GPUs?

Optimizing memory and compute balance in multi-GPU environments involves using FSDP2 with device meshes to carefully manage per-parameter sharding. This distributes memory pressure evenly while maintaining compute efficiency during forward and backward passes.