pytorch-fsdp2

Shard large PyTorch models across multiple GPUs with FSDP2.

Updated May 4, 2026
One-click install
npx skills add https://github.com/Supporter09/Face_Anti_Spoofing_Biometric --skill pytorch-fsdp2-supporter09
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp2
Source: https://github.com/Supporter09/Face_Anti_Spoofing_Biometric/tree/main/.claude/skills/pytorch-fsdp2
Command: npx skills add https://github.com/Supporter09/Face_Anti_Spoofing_Biometric --skill pytorch-fsdp2-supporter09

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you train PyTorch models that are too large for a single GPU by adding correct FSDP2 sharding, optimizer setup, and checkpoint handling.

Core Features & Use Cases

  • Large-Model Training: Split parameters, gradients, and optimizer state across GPUs for memory-efficient training.
  • Distributed Workflow Integration: Set up torchrun-based execution, device meshes, mixed precision, and optional CPU offload in the right order.
  • Checkpointing and Recovery: Save and load distributed state safely with DCP-compatible patterns for resharding and multi-rank training.
  • Use Case: If your transformer training script OOMs on one GPU, this Skill shows how to retrofit FSDP2 so the model can train across multiple devices without rewriting the whole stack.

Quick Start

Ask the assistant to convert your PyTorch training script into an FSDP2 workflow with bottom-up sharding, DTensor-aware optimization, and distributed checkpoint support.

Frequently Asked Questions about pytorch-fsdp2

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

FAQPage Schema
How do I shard a PyTorch model across multiple GPUs to prevent out-of-memory errors?

To shard a PyTorch model across multiple GPUs and prevent OOM errors, apply bottom-up fully_shard configuration to split parameters, gradients, and optimizer state. This FSDP2 retrofit enables memory-efficient training for workloads exceeding single-device memory limits.

What is the best way to set up distributed checkpointing for FSDP2 training?

The best way to set up distributed checkpointing for FSDP2 training is using DCP-compatible state dict handling. This pattern ensures safe saving and loading of distributed state, supporting resharding and multi-rank recovery without corrupting the sharded model layout.

Can I use mixed precision and CPU offload with PyTorch FSDP2?

Yes, you can configure mixed precision and CPU offload with PyTorch FSDP2. These settings are integrated into the distributed workflow setup alongside torchrun-based execution and device mesh configuration to optimize memory efficiency during training.

Do I need a DTensor-aware optimizer for FSDP2 sharding?

Yes, a DTensor-aware optimizer is required for FSDP2 sharding. Constructing the optimizer with DTensor awareness ensures that the optimizer state is correctly partitioned across the device mesh during distributed training.

How do I initialize torchrun for a PyTorch FSDP2 training script?

To initialize torchrun for a PyTorch FSDP2 training script, set up the distributed execution environment before applying bottom-up fully_shard sharding and configuring the device mesh. This establishes the multi-rank process group required for distributed training.

Why does my transformer training script OOM on a single GPU?

Your transformer training script OOMs on a single GPU because the model size exceeds available device memory. Retrofitting the script with FSDP2 shards parameters, gradients, and optimizer state across multiple GPUs to resolve this memory constraint.