# ZeRO and FSDP2 explained: how sharded data parallelism fits big models on small GPUs

Training a model needs about 16 bytes per parameter before activations, so an 8B model wants 128 GB on every GPU under plain data parallelism. ZeRO and FSDP2 split that memory across GPUs. This guide does the maths and shows the code.

The first wall you hit when training or fine-tuning a large model is not compute. It is memory. A single GPU with 80 GB cannot hold the full training state of an 8-billion-parameter model, even before it stores a single activation. Plain data parallelism makes this worse, because every GPU keeps its own complete copy of everything.

Sharded data parallelism fixes the waste. Instead of replicating parameters, gradients and optimizer state on every GPU, each GPU keeps only a slice and fetches the rest just in time. Microsoft's ZeRO paper introduced the idea in three stages, and PyTorch's Fully Sharded Data Parallel (FSDP) made it a core part of PyTorch. Its second version, FSDP2, built on the `fully_shard` API, received a set of changes in PyTorch 2.15, released in late October 2026, including a breaking change to the default gradient reduction dtype. This article explains where the memory goes, computes how each stage divides it, and shows what to set in code.

## What happened

### ZeRO paper defines three stages of sharding (7 October 2019)

Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase and Yuxiong He of Microsoft posted "ZeRO: Memory Optimizations Toward Training Trillion Parameter Models". It showed that mixed-precision Adam training stores 16 bytes per parameter, and that data parallelism replicates all of it. ZeRO partitions optimizer states (stage 1), then gradients (stage 2), then parameters (stage 3) across the data-parallel GPUs. For a 7.5B-parameter model on 64 GPUs, the paper computes per-GPU model-state memory falling from 120 GB to 31.4 GB, 16.6 GB and 1.88 GB. ZeRO ships in Microsoft's DeepSpeed library.

### PyTorch publishes its FSDP design paper (21 April 2023)

Yanli Zhao, Andrew Gu, Rohan Varma and colleagues described PyTorch's native implementation in "PyTorch FSDP: Experiences on Scaling Fully Sharded Data Parallel". The abstract reports performance "comparable" to Distributed Data Parallel (DDP), support for "significantly larger models", and "near-linear scalability in terms of TFLOPS".

### PyTorch 2.15 updates FSDP2 (28 October 2026)

The PyTorch 2.15 release blog lists several FSDP2 changes, all marked API Unstable. Precision-sensitive parameters "such as MoE router gates and norm weights, can stay in fp32 while the rest of the model trains in bf16, still with one all-gather per `fully_shard`", through `MixedPrecisionPolicy(param_dtype_override_fn=...)`. "A full gradient-accumulation step can now be captured in a single CUDA graph." "FSDP reduce grads can now be overlapped with subsequent compute." Gradients now "follow each parameter's `grad_dtype`", and the docs state that `reduce_dtype` no longer defaults to `param_dtype`: "Set `reduce_dtype=torch.bfloat16` to keep the previous behavior." The release also makes a rewritten NCCL backend the default and adds a flight recorder that "writes a post-mortem to disk when a collective hangs". DevClass reports that the legacy ProcessGroupNCCL is kept as a fallback and slated for removal in PyTorch 2.16 if the new backend performs well.

## Where training memory goes

Let Ψ be the number of parameters. With mixed-precision Adam, the ZeRO paper counts these model states per parameter:

| Item | Precision | Bytes per parameter |
|---|---|---|
| Working parameters | fp16 or bf16 | 2 |
| Gradients | fp16 or bf16 | 2 |
| Master parameters | fp32 | 4 |
| Adam momentum | fp32 | 4 |
| Adam variance | fp32 | 4 |
| **Total** | | **16** |

The last three rows are the optimizer state, written as KΨ with K = 12. So model state is 2Ψ + 2Ψ + 12Ψ = 16Ψ bytes. Activations, temporary buffers and memory fragmentation come on top of that and depend on batch size and sequence length. If the optimizer or precision terms are unfamiliar, see the site pages on [optimizers](/tools/optimizers) and [mixed precision](/tools/mixed-precision), and the [numeric precision simulation](/ai-simulations/train-numeric-precision).

For an 8B model: 16 × 8 × 10^9 = 128 × 10^9 bytes, or 128 GB. Under plain data parallelism (DDP), every GPU holds all 128 GB, no matter how many GPUs you add. Adding GPUs speeds up training but does nothing for memory.

An everyday analogy: eight people cooking from one recipe book. Data parallelism gives each cook a full copy of the book. ZeRO tears the book into eight sections, gives one to each cook, and has them read a section aloud when someone needs it. Less paper, more talking.

## The three ZeRO stages, worked out

Let N be the number of data-parallel GPUs. The ZeRO paper gives per-GPU model-state memory as:

- **Stage 1 (shard optimizer state):** 4Ψ + 12Ψ / N
- **Stage 2 (also shard gradients):** 2Ψ + 14Ψ / N
- **Stage 3 (also shard parameters):** 16Ψ / N

**Worked example, 8B model on 8 GPUs.** Ψ = 8 × 10^9.

- DDP: 16 × 8 = 128 GB per GPU.
- Stage 1: 4 × 8 + 12 × 8 / 8 = 32 + 12 = 44 GB.
- Stage 2: 2 × 8 + 14 × 8 / 8 = 16 + 14 = 30 GB.
- Stage 3: 16 × 8 / 8 = 16 GB.

On 80 GB GPUs, DDP cannot even start. Stage 1 fits with 36 GB left for activations, stage 3 with 64 GB left. The paper's own example checks out with the same formulas: for 7.5B parameters on 64 GPUs, stage 1 gives 30 + 90 / 64 = 31.41 GB, stage 2 gives 15 + 105 / 64 = 16.64 GB, and stage 3 gives 120 / 64 = 1.875 GB, matching its 31.4, 16.6 and 1.88 GB.

| Model and GPUs | DDP | ZeRO-1 | ZeRO-2 | ZeRO-3 / FSDP |
|---|---|---|---|---|
| 7.5B, 64 GPUs | 120 GB | 31.41 GB | 16.64 GB | 1.88 GB |
| 8B, 8 GPUs | 128 GB | 44 GB | 30 GB | 16 GB |
| 8B, 64 GPUs | 128 GB | 33.5 GB | 17.75 GB | 2 GB |
| 70B, 8 GPUs | 1,120 GB | 385 GB | 262.5 GB | 140 GB |
| 70B, 64 GPUs | 1,120 GB | 293.12 GB | 155.31 GB | 17.5 GB |

All values are model states only, computed with the formulas above. Two patterns stand out. First, stages 1 and 2 hit a floor: even with infinite GPUs, stage 1 never drops below 4Ψ and stage 2 never below 2Ψ, because each GPU still holds full parameters. Second, only stage 3 scales all the way down. A 70B model on 8 GPUs still needs 140 GB per GPU at stage 3, so full fine-tuning at that size needs more GPUs, CPU offload, or a different approach such as LoRA.

```chart
{"type": "line", "title": "Per-GPU model-state memory for an 8B model", "x": ["1", "2", "4", "8", "16", "32", "64"], "series": [{"name": "DDP", "data": [128, 128, 128, 128, 128, 128, 128]}, {"name": "ZeRO-1", "data": [128, 80, 56, 44, 38, 35, 33.5]}, {"name": "ZeRO-2", "data": [128, 72, 44, 30, 23, 19.5, 17.75]}, {"name": "ZeRO-3 / FSDP", "data": [128, 64, 32, 16, 8, 4, 2]}], "xlabel": "data-parallel GPUs", "ylabel": "GB per GPU", "unit": " GB", "note": "Computed with the ZeRO paper's formulas, 16 bytes per parameter, activations excluded"}
```

### What it costs in communication

Memory savings are paid for in network traffic. The ZeRO paper puts per-step communication at 2Ψ for DDP, stage 1 and stage 2. Gradient all-reduce is a reduce-scatter plus an all-gather, and stages 1 and 2 reuse that pattern. Stage 3 needs 3Ψ, about 1.5 times as much, because parameters must be gathered again during the backward pass.

In bf16 (2 bytes per value) for an 8B model, that is 2 × 8 × 10^9 × 2 = 32 GB moved per GPU per step for DDP or stages 1 and 2, and 3 × 8 × 10^9 × 2 = 48 GB for stage 3. Whether that extra 16 GB hurts depends on your interconnect and how well it overlaps with compute, which is why FSDP prefetches the next layer's parameters while the current one computes.

```chart
{"type": "bar", "title": "Memory saved versus traffic added, 8B model on 8 GPUs", "x": ["DDP", "ZeRO-1", "ZeRO-2", "ZeRO-3"], "series": [{"name": "model state per GPU (GB)", "data": [128, 44, 30, 16]}, {"name": "communication per step (GB, bf16)", "data": [32, 32, 32, 48]}], "ylabel": "GB", "note": "Computed from the ZeRO paper's memory formulas and its 2 psi and 3 psi communication volumes, at 2 bytes per value"}
```

## How FSDP2 implements stage 3

FSDP is PyTorch's version of ZeRO stage 3. You wrap groups of layers, usually each transformer block, into FSDP units. During training, for each unit:

1. **All-gather** the unit's parameter shards so every GPU briefly holds the full layer.
2. **Run** the forward computation for that layer.
3. **Reshard**: free the full parameters, keeping only the local shard.
4. In the backward pass, **all-gather again**, compute gradients, then **reduce-scatter** them so each GPU keeps only the gradient shard it owns.
5. The optimizer updates only the local shard of parameters and state.

Only one or two units are unsharded at any time. If an 8B model had 32 equal transformer blocks, which is an approximation, each block would hold 250 million parameters, and gathering one in bf16 costs a transient 250 × 10^6 × 2 bytes = 0.5 GB.

FSDP2's `fully_shard` changes how shards are stored. The PyTorch docs say "This implementation represents the sharded parameters as `DTensor`s sharded on dim-0". Each parameter is split along its first dimension, instead of being flattened into one buffer as in FSDP1, which the docs say makes resharding and sharded state dicts easier to reason about.

Key options, from the PyTorch 2.15 documentation:

| Option | What it does | Typical use |
|---|---|---|
| `mesh` | 1D mesh gives full sharding; 2D mesh gives HSDP, sharding across the 1st dim and replicating across the 0th | HSDP for multi-node jobs |
| `reshard_after_forward` | `True` frees parameters after forward and re-gathers in backward; `False` keeps them; an `int` reshards to a smaller group | Default is `True` for non-root modules, `False` for the root |
| `mp_policy` | `MixedPrecisionPolicy(param_dtype, reduce_dtype)` | bf16 compute, chosen reduce dtype |
| `offload_policy` | `CPUOffloadPolicy(pin_memory=True)` moves parameters, gradients and optimizer state to CPU; the optimizer step runs on CPU | Fitting models too big for GPU memory |

A minimal FSDP2 setup looks like this. It follows the documented signature; launch it with `torchrun --nproc_per_node=8 train.py`.

```python
import torch
import torch.distributed as dist
from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy

dist.init_process_group("nccl")
torch.cuda.set_device(dist.get_rank() % torch.cuda.device_count())

model = build_transformer().cuda()           # your model
mp = MixedPrecisionPolicy(param_dtype=torch.bfloat16,
                          reduce_dtype=torch.bfloat16)  # explicit since 2.15

for block in model.layers:                   # one FSDP unit per transformer block
    fully_shard(block, mp_policy=mp)
fully_shard(model, mp_policy=mp)             # root: keeps params after forward by default

optim = torch.optim.AdamW(model.parameters(), lr=3e-4)
for batch in loader:
    loss = model(**batch).loss
    loss.backward()
    optim.step()
    optim.zero_grad()
```

The explicit `reduce_dtype=torch.bfloat16` matters after 2.15. Gradients that are reduce-scattered in fp32 instead of bf16 double that traffic: for an 8B model, Ψ values × 4 bytes = 32 GB instead of Ψ × 2 bytes = 16 GB per reduce-scatter. Some teams prefer fp32 reduction for numerical stability; the point is to choose it on purpose.

### Hybrid sharding (HSDP)

Full sharding across many nodes means every all-gather crosses the slower inter-node network. HSDP shards within a group, typically the 8 GPUs of one node, and replicates across groups. Per-GPU model state is then 16Ψ / 8 regardless of node count: 16 GB for an 8B model. Only gradient all-reduce crosses nodes. You trade some memory for less cross-node traffic, which often wins on clusters with fast NVLink inside nodes and slower links between them. The [parallelism planner simulation](/ai-simulations/train-parallelism-planner) lets you combine this with [tensor parallelism](/tools/tensor-parallelism) and [pipeline parallelism](/tools/pipeline-parallelism).

## Use cases and examples

**1. Full fine-tuning an 8B model on one 8-GPU node.** A team with eight 80 GB GPUs wants full fine-tuning, not adapters. DDP needs 128 GB per GPU and fails. FSDP2 with full sharding needs 16 GB of model state per GPU, leaving about 64 GB for activations, as computed above. If activations still do not fit, activation checkpointing trades recomputation for memory.

**2. A 70B model on a single node.** The same team tries 70B. Even at stage 3 on 8 GPUs, model state is 140 GB per GPU, more than an 80 GB card. Their options are CPU offload through `CPUOffloadPolicy`, which moves optimizer steps to the CPU and is slower, scaling to 64 GPUs (17.5 GB per GPU), or switching to [LoRA](/ai-simulations/lora), which keeps the base weights frozen and trains a small adapter.

**3. Multi-node pre-training with HSDP.** A lab trains on 16 nodes of 8 GPUs. Full sharding across 128 GPUs would cut an 8B model's state to 1 GB per GPU but push every all-gather across nodes. HSDP with an 8-GPU shard group keeps 16 GB per GPU and limits cross-node traffic to gradient all-reduce. They pick HSDP because memory is not their bottleneck; the network is.

**4. Upgrading to PyTorch 2.15.** A team relied on `reduce_dtype=None` to inherit bf16. After upgrading, the docs say `reduce_dtype` follows each parameter's `grad_dtype` instead. If that is fp32, the gradient reduce-scatter for their 8B model grows from 16 GB to 32 GB per step. They pin `reduce_dtype=torch.bfloat16` and use the new `param_dtype_override_fn` to keep MoE router gates and norm weights in fp32.

**5. Sizing before renting.** Before booking a cluster, an engineer runs the formulas for each candidate setup, as in the tables here. The [model sizing simulation](/ai-simulations/train-model-sizing) and the [training at scale topic](/topics/deep-learning/training-at-scale) do the same with activations and KV cache included.

## What it means in practice

Sharding is the default way to train anything that does not fit on one GPU. The memory maths is simple enough to do by hand: 16 bytes per parameter for mixed-precision Adam, divided by the number of GPUs for whatever you shard. Stages 1 and 2 are cheap in communication but hit a floor. Stage 3, which FSDP implements, scales memory down without limit but adds about 50% more traffic. FSDP2 makes this composable with tensor and pipeline parallelism through DTensor, and PyTorch 2.15 adds finer precision control and better overlap. It also changes a default you may depend on. For the wider picture, see [FSDP](/tools/fsdp) and [DeepSpeed ZeRO](/tools/deepspeed-zero) on the site.

## What to do now

1. **Do the memory maths first.** Multiply parameters by 16 bytes, divide by your shard group size, and leave room for activations.
2. **Wrap at the transformer-block level.** One `fully_shard` per block, then the root, is the standard pattern.
3. **Set `reduce_dtype` explicitly.** After PyTorch 2.15 it no longer inherits `param_dtype`.
4. **Keep sensitive parameters in fp32.** Use `param_dtype_override_fn` for router gates and norm weights, as the 2.15 release describes.
5. **Choose HSDP for multi-node jobs.** Shard within the node, replicate across nodes, unless memory forces full sharding.
6. **Use stage 1 or 2 when they fit.** They cost no extra communication over DDP.
7. **Try activation checkpointing before CPU offload.** It keeps all work on the GPU, while offload moves the optimizer step to the CPU.
8. **Use the new flight recorder.** PyTorch 2.15 dumps post-mortems from every rank when a collective hangs, so one stalled GPU is easier to find.

## Risks and open questions

**Activations are not in these numbers.** The 16-bytes rule covers model state only. Long sequences can make activation memory larger than everything else.

**Communication can erase the gains.** Stage 3's extra 50% traffic is cheap on fast interconnects and costly on slow ones. Measure step time, not only memory.

**New features are marked unstable.** The PyTorch 2.15 FSDP2 additions are labelled API Unstable, so their interfaces may change in later releases.

**Default changes are easy to miss.** The `reduce_dtype` change alters traffic and numerics without any code change on your side.

**Watch next:** how teams adopt per-parameter precision for MoE models, and whether the new CUDA graph capture of whole accumulation steps shows measurable speedups in published benchmarks such as [MLPerf Training](/articles/mlperf-training-v6-1-endpoints-explained).

## Frequently asked questions

### Is FSDP the same as ZeRO stage 3?

Conceptually, yes. Both shard parameters, gradients and optimizer state across data-parallel GPUs and gather parameters just in time. FSDP is PyTorch's native implementation; ZeRO ships in DeepSpeed.

### Why 16 bytes per parameter?

Mixed-precision Adam stores 2 bytes for bf16 or fp16 parameters, 2 for gradients, and 12 for fp32 optimizer state: master weights, momentum and variance. The ZeRO paper uses this breakdown. Other optimizers or precisions change the number.

### Does sharding make training slower?

Stages 1 and 2 move the same amount of data as DDP. Stage 3 moves about 1.5 times as much, but FSDP overlaps gathers with compute. On fast interconnects the slowdown is often small; on slow networks it can be large.

### What is the difference between FSDP1 and FSDP2?

FSDP1 flattens a unit's parameters into one buffer. FSDP2's `fully_shard` keeps each parameter as a DTensor sharded on its first dimension. The PyTorch docs say this makes resharding and sharded state dicts easier to reason about.

### When should I use HSDP?

Use it on multi-node clusters where links between nodes are slower than links inside a node. It shards within a node and replicates across nodes, trading some memory for much less cross-node traffic.

## Summary

Mixed-precision Adam needs about 16 bytes per parameter of model state, so an 8B model needs 128 GB on every GPU under plain data parallelism. ZeRO shards that state: stage 1 shards optimizer state (44 GB per GPU for 8B on 8 GPUs), stage 2 adds gradients (30 GB), and stage 3 adds parameters (16 GB), at the price of about 1.5 times the communication. PyTorch FSDP2 implements stage 3 with DTensor shards, gathering one block at a time, and supports hybrid sharding for multi-node jobs. PyTorch 2.15 adds per-parameter precision, CUDA graph capture and better overlap, and changes the `reduce_dtype` default, so set it explicitly when you upgrade.

## Sources

- [arXiv: ZeRO: Memory Optimizations Toward Training Trillion Parameter Models](https://arxiv.org/abs/1910.02054)
- [arXiv: PyTorch FSDP: Experiences on Scaling Fully Sharded Data Parallel](https://arxiv.org/abs/2304.11277)
- [PyTorch: torch.distributed.fsdp.fully_shard documentation (2.15)](https://docs.pytorch.org/docs/2.15/distributed.fsdp.fully_shard.html)
- [PyTorch Blog: PyTorch 2.15 release](https://pytorch.org/blog/pytorch-2-15-release-blog/)
- [DevClass: PyTorch 2.15 tackles the one bad GPU problem](https://www.devclass.com/ai-ml/2026/11/07/pytorch-215-tackles-the-one-bad-gpu-problem/5308234)
- [arXiv PDF: ZeRO paper, full text with memory formulas](https://arxiv.org/pdf/1910.02054)
