pytorch-fsdp

Configures PyTorch FSDP and FSDP2 distributed training with sharding and mixed precision.

4|Updated May 18, 2026
One-click install
npx skills add https://github.com/ZardLi1115/zedclaw --skill pytorch-fsdp-zardli1115
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp
Source: https://github.com/ZardLi1115/zedclaw/tree/main/optional-skills/mlops/pytorch-fsdp
Command: npx skills add https://github.com/ZardLi1115/zedclaw --skill pytorch-fsdp-zardli1115

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

PyTorch FSDP training guidance helps you reduce GPU memory usage and scale larger models by correctly applying Fully Sharded Data Parallel (including FSDP2-style per-parameter sharding) without getting stuck on common configuration pitfalls.

Core Features & Use Cases

  • FSDP concepts and when to apply them: Explains why sharding helps, how forward/backward all-gather and post-step reduce-scatter work, and how to structure sharding calls bottom-up.
  • FSDP2 (fully_shard) behavior: Covers DTensor-based parameter sharding, hook-driven unsharding/resharding, and the expected contract for forward/backward execution.
  • Practical distributed training prerequisites: Provides related PyTorch distributed context needed to reason about process groups, communication backends, and uneven input handling via Join (useful when debugging hangs).

Quick Start

Ask the agent to help you configure PyTorch FSDP2 for your model by explaining what you need to change in initialization, forward usage (model(input)), optimizer setup, and how to interpret common memory/communication issues for your world size and mesh.

Frequently Asked Questions about pytorch-fsdp

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

FAQPage Schema
How does PyTorch FSDP model sharding work to reduce GPU memory usage?

PyTorch FSDP model sharding reduces GPU memory by distributing parameters, gradients, and optimizer states across processes. During forward and backward passes, it uses all-gather to reconstruct layers and reduce-scatter to synchronize gradients, enabling larger model training.

What is the difference between FSDP and FSDP2 fully_shard in PyTorch?

FSDP2 fully_shard uses DTensor-based per-parameter sharding and hook-driven unsharding/resharding instead of module-level wrapping. This approach provides finer control over parameter sharding and requires adhering to specific forward and backward execution contracts to ensure correct distributed training.

How do I configure FSDP2 for my PyTorch distributed training model?

To configure FSDP2, apply fully_shard bottom-up through your model modules, set up the optimizer with sharded parameters, and ensure forward execution respects DTensor semantics. You must also manage mixed precision and CPU offloading configurations based on your mesh and world size.

Why does my PyTorch FSDP training hang during distributed execution?

PyTorch FSDP training hangs often stem from uneven input handling across process groups or mismatched collective operations. Using the Join context manager for uneven inputs and verifying communication backend synchronization helps identify and resolve these execution contract violations.

Do I need to understand PyTorch distributed fundamentals to use FSDP2?

Yes, using FSDP2 requires knowledge of PyTorch distributed fundamentals including process groups, communication backends, and synchronization. Understanding these prerequisites is essential for correctly implementing DTensor parameter sharding and debugging execution contract issues.

When should I use CPU offloading with PyTorch FSDP?

Use CPU offloading with PyTorch FSDP when GPU memory is insufficient for your model size and sharding alone does not resolve the constraint. It offloads parameters or optimizer states to CPU RAM, but requires careful configuration to avoid communication bottlenecks during the forward and backward passes.