pytorch-fsdp

Apply FSDP2 per-parameter sharding to PyTorch models with device meshes.

Updated Apr 19, 2026
One-click install
npx skills add https://github.com/gqf2008/hermez-ai --skill pytorch-fsdp-gqf2008
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-fsdp
Source: https://github.com/gqf2008/hermez-ai/tree/main/skills/mlops/training/pytorch-fsdp
Command: npx skills add https://github.com/gqf2008/hermez-ai --skill pytorch-fsdp-gqf2008

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Fully Sharded Data Parallelism (FSDP) in PyTorch enables memory-efficient, scalable training for very large models by sharding parameters and managing gradients across processes, including FSDP2 with per-parameter sharding, mixed precision, and CPU offloading.

Core Features & Use Cases

  • Per-parameter sharding with DTensor-based memory layout to reduce memory footprint during training.
  • Device mesh orchestration and FSDP2 integration for scalable, multi-node training of transformer-scale models.
  • Pre-forward all-gather and post-forward/backward resharding to maximize throughput while minimizing peak memory consumption.
  • Support for mixed precision and CPU offloading to balance compute and memory resources in heterogeneous environments.
  • Use Cases: training large models (e.g., transformers) that exceed single-device memory budgets, migrating from FSDP1 workflows, and optimizing memory-performance tradeoffs in distributed setups.

Quick Start

Apply fully_shard to your PyTorch model with a defined device mesh and begin distributed training to leverage per-parameter sharding.

Frequently Asked Questions about pytorch-fsdp

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

FAQPage Schema
How does PyTorch FSDP reduce memory footprint during distributed training?

PyTorch FSDP minimizes peak memory by sharding model parameters across distributed processes. It performs pre-forward all-gather to reconstruct layers locally, then reshards them post-forward to maximize throughput while keeping memory consumption low.

How do I apply per-parameter sharding to a transformer model using FSDP2?

You apply per-parameter sharding by defining a device mesh and applying the fully_shard function directly to your PyTorch model. This leverages DTensor-based memory layout orchestration for scalable multi-node training of transformer-scale workloads.

What is the difference between FSDP2 and traditional FSDP1 workflows?

FSDP2 introduces per-parameter sharding using a DTensor-based memory layout, moving away from the flat parameter management of FSDP1. This provides finer memory optimization and better device mesh integration for transformer-scale workloads.

Can I use CPU offloading and mixed precision with FSDP for large models?

Yes, FSDP supports mixed precision and CPU offloading to balance compute and memory resources in heterogeneous environments. This enables training large transformer models that exceed single-device memory budgets.

What prerequisites are needed to start distributed training with FSDP?

You need a compatible PyTorch environment, a defined device mesh, and proper distributed initialization. These prerequisites enable parameter sharding and gradient synchronization across your training processes.