pytorch-fsdp

Implements fully sharded data-parallel training for large PyTorch models.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/loteiron/ZeusAgent --skill pytorch-fsdp-loteiron
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pytorch-fsdp
Source: https://github.com/loteiron/ZeusAgent/tree/main/optional-skills/mlops/pytorch-fsdp
Command: npx skills add https://github.com/loteiron/ZeusAgent --skill pytorch-fsdp-loteiron

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch>=2.0, transformers, and includes references (resource) components.

What problem does it solve? Training large models exhausts GPU memory when parameters, gradients, and optimizer states are replicated on every worker. This Skill provides guidance and runnable patterns for PyTorch FSDP, which shards model state across data-parallel workers to fit models that would otherwise not fit on a single device. ## Core Features & Use Cases - FSDP1 and FSDP2 (fully_shard) guidance: Covers wrapping strategies, sharding strategies, DTensor-based per-parameter sharding, and migration from FSDP1 to FSDP2. - Memory and performance patterns: Mixed precision, CPU offloading, communication/computation overlap, and prefetching control drawn from official PyTorch documentation. - Distributed training reference: Process group initialization, backend selection (NCCL, Gloo, MPI), checkpointing, and the Join context manager for uneven inputs. - Use Case: When training a multi-billion-parameter transformer across 8 GPUs, use this Skill to apply fully_shard bottom-up per layer, configure mixed precision, and produce sharded state dict checkpoints. ## Quick Start Ask the agent to show how to wrap a Transformer model with PyTorch FSDP2 fully_shard using a 1D CUDA device mesh and mixed precision.

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 a large model across multiple GPUs?▼

Apply fully_shard to each submodule bottom-up before applying it to the root model, passing a device mesh that defines the data-parallel workers. FSDP shards parameters, gradients, and optimizer states across workers and all-gathers parameters before each forward pass.

What is the difference between FSDP1 and FSDP2 fully_shard?▼

FSDP2 uses DTensor-based dim-0 per-parameter sharding instead of FSDP1's flat-parameter sharding, giving a simpler sharding representation and communication-free sharded state dicts. FSDP2 also avoids record_stream memory management and exposes manual prefetching and collective scheduling APIs.

Which backend should I use for PyTorch distributed training?▼

Use the NCCL backend for distributed training with CUDA GPUs, including InfiniBand hosts, and the Gloo backend for CPU training. Gloo can serve as a fallback for GPUs if NCCL encounters problems, though it runs slower.

How do I checkpoint a model trained with FSDP2?▼

FSDP2 produces sharded state dicts containing DTensors without requiring all-gathers. Use DTensor APIs like DTensor.full_tensor() or PyTorch Distributed Checkpoint's distributed state dict APIs to reshard them into full state dicts.

Why does distributed training hang with uneven input batches?▼

Hangs occur when ranks run different numbers of iterations and collective communications mismatch. Wrap the training loop in the Join context manager from torch.distributed.algorithms, which shadows collectives for joined processes until all ranks finish.