ZeRO: Partition the Model States Across GPUs So Data Parallelism Can Hold 100B+ Parameters
ZeRO notes that data parallelism stores full copies of parameters, gradients and optimizer states on every GPU: 16 bytes per parameter with mixed-precision Adam. It partitions them in three stages, with unchanged communication in the first two and 50% more in the third. We recompute its Table 1.
On this page
Why this paper matters
In 2019, training anything much larger than GPT-2 (1.5B) meant model parallelism (splitting each layer’s matrices across GPUs), pipeline parallelism, or a mix of both. ZeRO (Zero Redundancy Optimizer), introduced by Rajbhandari et al. of Microsoft’s DeepSpeed team in October 2019, pointed out what those approaches overlooked: in plain data parallelism, every GPU holds a complete copy of the parameters, gradients and optimizer states, which is an enormous redundancy.
The paper’s opening numbers are blunt. Data parallelism runs out of memory on a 32GB GPU beyond 1.4B parameters. Model parallelism goes further, but once it leaves a single node the link bandwidth falls from 300GB/s per link (NVSwitch inside a node) to 12.5GB/s per link (InfiniBand EDR between nodes), and the paper reports that Megatron-LM alone cannot scale efficiently beyond 40B parameters. ZeRO instead partitions those states across GPUs and gathers them only when needed, so that plain data parallelism can hold large models. The idea lives on in DeepSpeed’s ZeRO-1/2/3 and PyTorch FSDP, and is one of the standard building blocks of large-model training today.
Where the memory goes: model states and residual states
The paper splits training memory into two kinds.
Model states are parameters, gradients and optimizer states. In mixed-precision training the forward and backward passes use fp16, while the optimizer keeps an fp32 copy of the parameters plus momentum and variance. With Adam, parameters need:
| Item | Bytes |
|---|---|
| fp16 parameters | |
| fp16 gradients | |
| fp32 parameter copy, momentum, variance | , with for Adam |
| Total |
The paper’s example: GPT-2 with 1.5B parameters needs at least 24GB for model states alone, while its fp16 parameters are only 3GB.
Residual states are activations, temporary buffers and fragmentation. The paper’s numbers: for GPT-2 at sequence length 1K and batch size 32, activations take about 60GB, dropping to about 8GB with activation checkpointing; a GPT-like model with 100B parameters at batch size 32 still needs about 60GB even with checkpointing. Temporary buffers matter too: a fused fp32 buffer for all-reduce on a 3B-parameter model takes 12GB. On top of that, tensors with different lifetimes fragment memory, so an allocation can fail even when the total is sufficient.
ZeRO-DP: three stages
ZeRO-DP targets the model states. Each GPU keeps only its own share and communicates to get the rest when it is needed. The three stages stack:
| Stage | Partitioned | Model states per GPU | 7.5B params, 64 GPUs | Communication per step |
|---|---|---|---|---|
| Plain data parallelism | nothing | 120 GB | ||
| optimizer states | 31.4 GB | |||
| plus gradients | 16.6 GB | |||
| plus parameters | 1.88 GB |
The communication analysis is the elegant part. The gradient all-reduce in data parallelism is already a reduce-scatter plus an all-gather, each moving elements, in total. With gradients partitioned, each GPU reduce-scatters to get its own gradient shard, updates its own parameter shard, then all-gathers the full parameters: still , the same as plain data parallelism. So the memory savings of the first two stages are free. In the third stage the parameters are partitioned too, so each part must be broadcast during the forward pass and again during the backward pass, on top of the gradient reduce-scatter: , or 1.5 times.
ZeRO-R: the residual states
Three optimizations, one for each kind of residual memory:
- Partitioned activation checkpoints (). With model parallelism every GPU stores a replicated copy of the activation checkpoints. ZeRO partitions them across the model-parallel group and all-gathers them when needed. The paper’s example: a 100B model, batch size 32, sequence length 1024 and 16-way model parallelism, with one checkpoint per layer, needs about 33GB per GPU; cuts it to about 2GB, and the remainder can be offloaded to the CPU ().
- Constant-size buffers (). The buffer size no longer grows with the model but stays at a constant that is large enough for efficiency.
- Memory defragmentation (). Long-lived tensors (checkpoints, parameter gradients) are kept apart from short-lived ones to avoid fragmentation.
Recomputing Table 1
The paper’s Table 1 lists per-GPU model-state memory for 7.5B, 128B and 1T parameter models at several data-parallel degrees: 54 numbers in all. The code below recomputes all of them from the formulas above, and also finds the largest model that fits in a 32GB GPU when only model states count:
K = 12 # Adam optimizer state: fp32 params, momentum, variance, 4 B each
def bytes_per_param(nd, stage):
"""Model-state bytes per parameter per GPU; stage 0 = plain DP."""
p, g, o = 2, 2, K # fp16 params, fp16 grads, optimizer state
if stage >= 1:
o /= nd # P_os: partition optimizer states
if stage >= 2:
g /= nd # P_os+g: also partition gradients
if stage >= 3:
p /= nd # P_os+g+p: also partition parameters
return p + g + o
# Paper Table 1, in GB: {params (B): {Nd: (P_os, P_os+g, P_os+g+p)}}
table1 = {
7.5: {1: (120, 120, 120), 4: (52.5, 41.3, 30), 16: (35.6, 21.6, 7.5),
64: (31.4, 16.6, 1.88), 256: (30.4, 15.4, 0.47),
1024: (30.1, 15.1, 0.12)},
128: {1: (2048, 2048, 2048), 4: (896, 704, 512), 16: (608, 368, 128),
64: (536, 284, 32), 256: (518, 263, 8), 1024: (513, 257, 2)},
1000: {1: (16000, 16000, 16000), 4: (7000, 5500, 4000),
16: (4750, 2875, 1000), 64: (4187, 2218, 250),
256: (4046, 2054, 62.5), 1024: (4011, 2013, 15.6)},
}
n, worst = 0, 0.0
for psi, rows in table1.items():
for nd, vals in rows.items():
for stage, printed in enumerate(vals, start=1):
ours = bytes_per_param(nd, stage) * psi # 1 GB = 1e9 bytes
worst = max(worst, abs(ours - printed))
n += 1
print(f"{n} entries checked, max |diff| = {worst:.2f} GB")
# Largest model (in B params) whose model states fit in 32 GB
for nd in (1, 64, 1024):
sizes = [32 / bytes_per_param(nd, s) for s in range(4)]
print(f"Nd={nd:<5d}", " ".join(f"{x:7.1f}B" for x in sizes))
Output:
54 entries checked, max |diff| = 0.88 GB
Nd=1 2.0B 2.0B 2.0B 2.0B
Nd=64 2.0B 7.6B 14.4B 128.0B
Nd=1024 2.0B 8.0B 15.9B 2048.0B
All 54 numbers are within 0.88GB of the formula: the fractional parts of the large entries are truncated in the paper, so the formula is not wrong. The last four columns are plain data parallelism, , and . With 64 GPUs the three stages fit about 7.6B, 14.4B and 128B parameters, matching the paper’s “7.5B, 14B and 128B”; with 1024 GPUs the theoretical ceiling of the third stage is 2048B, which is the paper’s “trillion-parameter” claim. Note that the 2.0B for plain data parallelism counts only model states; the paper measured PyTorch DDP running out of memory at 1.4B, because activations and buffers need memory too.
Experiments
The experiments ran on 400 V100 GPUs (25 DGX-2 nodes, 800Gbps between nodes) with GPT-2-like Transformers; the baselines were PyTorch DDP and NVIDIA’s September 2019 Megatron-LM. The implementation evaluated, ZeRO-100B, contains only and ZeRO-R.
| Result | Numbers |
|---|---|
| Model size | ZeRO-100B with 16-way model parallelism trains up to 170B parameters efficiently; Megatron-LM alone cannot scale efficiently beyond 40B |
| Speed | Sustained 15 PFlops (over 30% of peak) on models from 8B to 100B parameters; over 38 TFlops per GPU for a 100B model on 400 GPUs; up to 10× faster than the baseline |
| Scalability | A 60B model shows super-linear speedup from 64 to 400 GPUs: the saved memory allows a larger per-GPU batch and higher arithmetic intensity |
| Usability | 13B parameters on 128 GPUs without model parallelism, over 40 TFlops per GPU on average; baseline DDP fails at 1.4B and stays below 20 TFlops |
| Configuration ablation (Figure 6, 16-way model parallelism) | The largest trainable model grows from 40B to 60B, 140B, then 150B across configurations C1 to C5 (partitioned activations, partitioned gradients and CPU offload of activations each contribute one step) |
| Turing-NLG | A 17B-parameter model trained with ZeRO-100B, perplexity 10.21 (the paper writes Webtext-103), 41.4 TFlops per GPU; the paper calls it the largest language model in the world as of May 12, 2020 |
Limitations and cautions
- “Trillion parameters” is an analysis, not a measurement. The implementation has only and ZeRO-R and reached at most 170B; the third stage, which partitions parameters, appears in the paper only as a follow-up plan (the authors write of extending the system by enabling the stage that partitions parameters to support 1 trillion parameters). The trillion-scale numbers in Table 1 are inferences from the memory analysis with no corresponding training run.
- Super-linear speedup is not free. It comes from the larger per-GPU batch size raising arithmetic intensity; the paper’s own footnote warns that too large a batch size hurts convergence, and says only that these large models are not yet in that regime with up to 1K GPUs.
- Hardware and precision are from 2019. The runs used V100s and fp16 mixed precision. Today’s bf16 and faster interconnects change throughput and the best configuration, but the structure of the memory and communication accounting stays the same.
- Table 1 is truncated. The fractional parts of the large numbers are dropped (at most 0.88GB in the code above), so do not quote them as exact values.
- Choice of baselines. The Megatron-LM comparison uses the September 2019 open-source release, and the paper has no quantitative comparison with pipeline parallelism such as GPipe.
- Not a replacement for every kind of parallelism. The paper itself concedes that model parallelism is still needed when activation memory is too large or the batch size is constrained; large-scale training today usually combines ZeRO/FSDP with tensor, pipeline and expert parallelism, see Distributed Training.
What to take from this paper
- Model states cost 16 bytes per parameter, and every GPU holds a copy. Remember and you can estimate how many GPUs a model needs.
- Partitioning does not necessarily add communication. A reduce-scatter plus an all-gather equals an all-reduce, so the first two stages only reorder the same traffic.
- The cost is concentrated in the last stage. Partitioning parameters adds an all-gather, 1.5 times the communication; whether that pays off depends on bandwidth and batch size.
- Residual memory matters too. Activations, buffers and fragmentation become bottlenecks on large models, which is why ZeRO-R exists.
- Separate implementation from analysis. “Can train a trillion parameters” in the paper is a theoretical capacity, not a training result.
Further reading
- Paper: ZeRO: Memory Optimizations Toward Training Trillion Parameter Models
- Related wiki pages: Distributed Training (ZeRO and FSDP with verified communication volumes), Compute and Memory for Training (activation memory beyond model states)
- Glossary: ZeRO
FAQ
- What do the three ZeRO stages partition?
- The paper calls them P_os, P_os+g and P_os+g+p. First the optimizer states (per-GPU memory 4Ψ + 12Ψ/N_d bytes), then also the gradients (2Ψ + 14Ψ/N_d), then also the parameters (16Ψ/N_d), where Ψ is the parameter count, N_d is the data-parallel degree and 12 is the optimizer-state bytes of mixed-precision Adam. DeepSpeed later named them ZeRO-1, ZeRO-2 and ZeRO-3.
- Does ZeRO increase communication?
- Not in the first two stages. Plain data parallelism moves 2Ψ elements per step per GPU (one reduce-scatter and one all-gather, Ψ each), and partitioning optimizer states and gradients keeps it at 2Ψ. The third stage must gather parameters in both the forward and the backward pass, for 3Ψ in total, 1.5 times plain data parallelism.
- Does ZeRO replace model parallelism?
- The paper argues that ZeRO makes model parallelism much less attractive when the only goal is to fit the model, since ZeRO-DP saves at least as much memory without changing the model. The two can be combined: in the experiments ZeRO with Megatron-LM's 16-way model parallelism trained up to 170B parameters. The paper also notes that model parallelism still helps, for example when activation memory is too large or the batch size would otherwise grow too big.
- Did the paper actually train trillion-parameter models?
- No. The implementation, ZeRO-100B, contains only P_os+g and ZeRO-R and trained at most 170B parameters. The third stage (partitioning parameters) was a follow-up plan at the time of the paper, and the trillion-parameter claim comes from a memory and communication analysis, not a training run.