pytorch-fsdp2

Add PyTorch FSDP2 fully-sharded training with DTensor sharding and DCP checkpointing.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/tadod12/fraud-detection-research --skill pytorch-fsdp2-tadod12
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/tadod12/fraud-detection-research/tree/main/.agent/skills/08-distributed-training/pytorch-fsdp2
Command: npx skills add https://github.com/tadod12/fraud-detection-research --skill pytorch-fsdp2-tadod12

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill teaches how to add PyTorch FSDP2 (fully_shard) training to a script, enabling memory-efficient, DTensor-based sharding for large models that exceed single-GPU capacity, with correct init, sharding, mixed-precision/offload, and distributed checkpointing.

Core Features & Use Cases

  • Explicit bottom-up sharding of submodules using fully_shard and optional device mesh integration to enable DTensor per-parameter sharding.
  • Support for mixed-precision, CPU offload, and DTensor-based optimizer state, with robust checkpointing via DCP or distributed state-dict helpers.
  • Real-world use case: training transformer models that don’t fit on a single GPU across multiple nodes, with fault-tolerant checkpointing and scalable state management.

Quick Start

Initialize distributed training with torchrun, apply bottom-up FSDP2 sharding to the desired submodules, and configure DCP-based checkpointing as described in the references.

Frequently Asked Questions about pytorch-fsdp2

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

FAQPage Schema
How do I enable PyTorch FSDP2 fully-sharded training for large models?

You enable PyTorch FSDP2 fully-sharded training by applying the `fully_shard` function bottom-up to submodules, using DTensor per-parameter sharding and optional DeviceMesh integration to distribute model memory across multiple GPUs.

What is DTensor-based sharding and when do I need it for distributed training?

DTensor-based sharding is a per-parameter sharding mechanism used in PyTorch FSDP2 to enable memory-efficient, scalable multi-GPU training for large transformer models that exceed single-GPU capacity.

How do I set up mixed-precision and CPU offload with FSDP2?

You configure mixed-precision and CPU offload during the FSDP2 sharding application process, allowing DTensor-based optimizer states to manage memory consumption efficiently across multi-node training environments.

Does PyTorch distributed checkpointing work with topology changes in FSDP2?

Yes, robust distributed checkpointing via DCP or distributed state-dict helpers supports topology changes, ensuring fault-tolerant state management across multi-GPU and multi-node training configurations.

When should I use bottom-up sharding with fully_shard instead of other distributed training approaches?

Bottom-up sharding with `fully_shard` is preferred when you need explicit per-submodule application and DTensor-based state management to train large transformer models that do not fit on a single GPU.

Do I need to construct the optimizer before or after applying FSDP2 sharding?

You must construct the optimizer after applying FSDP2 sharding to ensure the optimizer state correctly reflects the DTensor-based sharded parameters and distributed training layout.