pytorch-fsdp

Guides Fully Sharded Data Parallel training with PyTorch FSDP and FSDP2.

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill pytorch-fsdp-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/skills/mlops/training/pytorch-fsdp
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill pytorch-fsdp-mlt-oss

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Training large models exhausts single-GPU memory, and configuring PyTorch FSDP correctly (sharding strategies, mixed precision, CPU offloading, process groups) is error-prone. This Skill provides expert guidance and official documentation references for implementing distributed training with FSDP and FSDP2. ## Core Features & Use Cases - FSDP2 fully_shard Guidance: Explains the fully_shard API, DTensor-based per-parameter sharding, bottom-up application, and migration from FSDP1. - Distributed Communication Reference: Covers torch.distributed backends (NCCL, Gloo, MPI), process group initialization, and collective operations. - Advanced Patterns: Documents the Join context manager for uneven inputs, mixed precision, CPU offloading, and HSDP with 2D device meshes. - Use Case: When sharding a multi-billion-parameter transformer across 8 GPUs, use this Skill to correctly apply fully_shard layer-by-layer, configure the device mesh, and set up mixed precision. ## Quick Start Ask how to shard a PyTorch transformer model across multiple GPUs using FSDP2 fully_shard with 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 FSDP2 fully_shard to shard a model?

Apply fully_shard bottom-up: call it on each sublayer first, then on the root model. Each call groups parameters for one all-gather collective, and the root call groups remaining parameters like embeddings. The optimizer must be initialized with the resulting DTensor parameters.

What is the difference between PyTorch FSDP1 and FSDP2?

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

Which torch.distributed backend should I use for GPU training?

Use the NCCL backend for distributed training with CUDA GPUs, as it provides the best performance and supports InfiniBand and GPUDirect. Use Gloo for CPU training or as a fallback if NCCL encounters problems.

How do I handle uneven inputs in distributed PyTorch training?

Use the generic Join context manager from torch.distributed.algorithms, wrapping your DDP model and optimizer in Join([model, optimizer]). It shadows collective communications for joined processes, preventing hangs when ranks have different numbers of inputs.

Why does my FSDP training hang on exit?

Hangs on exit occur when destroy_process_group() is not called by all ranks, since ProcessGroupNCCL's destructor calls ncclCommAbort which must run collectively. Call destroy_process_group() once per trainer process near the end of main().

Can FSDP2 shard across a 2D device mesh for hybrid sharding?

Yes, passing a 2D mesh to fully_shard produces HSDP: parameters are sharded across the first mesh dimension and replicated across the second, with (Replicate(), Shard(0)) placement. A 1D mesh gives standard fully sharded FSDP.