When the model is too big for one GPU
DDP replicates the model on every GPU. That works until the model itself doesn't fit. FullyShardedDataParallel (FSDP) shards the model parameters, gradients, AND optimizer states across GPUs. Each GPU only holds 1/N of each, gathering the slices it needs for forward and backward then releasing them. This is what makes it possible to train a 70B-parameter model on a cluster of 24GB GPUs.
Sharding strategies
- FULL_SHARD — shard parameters, gradients, optimizer states. Most memory-efficient. Default choice for the largest models.
- SHARD_GRAD_OP — shard gradients and optimizer state only; replicate parameters. Faster than FULL_SHARD because no parameter all-gather, but uses more memory.
- NO_SHARD — equivalent to DDP. Useful for unit tests that share the same training script.
FSDP vs FSDP2
FSDP1 wraps modules and is the legacy API; FSDP2 (the fully_shard() per-parameter approach) is the new in-development API with a cleaner interface and better composability with torch.compile. For new code in 2026, prefer FSDP2 if you're targeting bleeding-edge PyTorch — but FSDP1 is still production-stable and the documentation is more mature.
What stays the same
Inside the training loop, FSDP looks identical to DDP. You wrap the model and proceed as usual. The complexity is in setup (auto-wrap policies for nested modules, mixed-precision settings) — not in the loop.