Paper commentary
ZeRO: Memory Optimizations Toward Training Trillion Parameter Models
- Problem Plain data parallelism replicates the full model state on every device, so it runs out of memory beyond 1.4B parameters on 32 GB GPUs, while model parallelism loses efficiency beyond a single node.
- Method Not stated in the paper.
- Results ZeRO-100B, which combines Pos+g with ZeRO-R, reached 38 TFlops per GPU and over 15 Petaflops on 400 V100 GPUs for a 60B-parameter model, and trained models of up to 13B parameters without model parallelism.
Why replicated training hits a memory wall
Plain data parallelism keeps a full copy of the model on every device, so the memory each device needs does not fall as more devices are added. On current 32 GB GPUs this approach runs out of memory for models with more than 1.4B parameters.
Model parallelism splits each layer's computation and parameters across devices, which removes the replication, but it needs heavy communication between layers. Because of that communication, it works well inside one node and degrades quickly across nodes; the authors measured a 40B model across two DGX-2 nodes at about 5 Tflops per V100 GPU, below 5% of peak.
The authors therefore split the memory budget into two groups before designing a fix. Model states are the optimizer states, gradients and parameters, which dominate for large models; residual states are the activations, temporary buffers and fragmented memory.
Where the per-device memory goes
In mixed-precision Adam training with Ψ parameters, the fp16 parameters and the fp16 gradients take 2Ψ bytes each. The fp32 optimizer state, which holds a copy of the parameters, the momentum and the variance, takes KΨ bytes, where K = 12 for this optimizer. The model states therefore need 2Ψ + 2Ψ + KΨ = 16Ψ bytes.
For GPT-2 with 1.5 billion parameters this comes to at least 24 GB, while its fp16 parameters alone occupy 3 GB. The optimizer state therefore accounts for most of the model-state memory once mixed precision is used.
Residual memory is also large: the 1.5B GPT-2 model at sequence length 1K and batch size 32 needs about 60 GB for activations. Activation checkpointing reduces this to about 8 GB, at the cost of roughly 33% extra recomputation. Even so, activations of a 100B-parameter GPT-like model at batch size 32 still need around 60 GB with checkpointing.
Fused communication buffers add more: for a 1.5B-parameter model, a flattened fp32 buffer needs 6 GB.
Partitioning model states across data-parallel ranks
ZeRO-DP starts from the observation that data parallelism is communication-efficient but memory-inefficient, because every process stores all model states. Model parallelism saves memory by partitioning the states but reduces computational granularity and adds communication. ZeRO-DP therefore keeps the data-parallel schedule and partitions the states instead of replicating them.
The first stage, Pos, groups the optimizer states into Nd equal partitions, and each process updates only its own partition, which costs one all-gather of the updated parameters at the end of each step. Optimizer-state memory drops from 4Ψ + KΨ to 4Ψ + KΨ/Nd, so with Nd = 64 a 7.5B-parameter model needs 31.4 GB under Pos instead of 120 GB under standard DP.
The second stage, Pos+g, partitions the gradients as well, so each gradient is reduced only on the process that owns the matching parameters. This turns the gradient all-reduce into a reduce-scatter and lowers gradient memory from 2Ψ to 2Ψ/Nd.
The third stage, Pos+g+p, also partitions the parameters, so each process stores only its own 1/Nd of them and receives the rest through broadcasts when a partition is needed. Model-state memory becomes 16Ψ/Nd, and the 7.5B model needs 1.9 GB under Pos+g+p with 64-way DP.
What the three stages allow in model size
Table 1 gives the per-device model-state memory for several models across DP degrees and the three stages. With Nd = 64, the analysis gives up to 7.5B, 14B and 128B parameters for Pos, Pos+g and Pos+g+p. Without ZeRO, the largest model that DP alone can run has less than 1.5 Billion parameters.
At Nd = 1024, the analysis puts a 1T-parameter model at 15.6 GB per device under Pos+g+p, which the authors read as making a trillion-parameter model feasible on 1024 GPUs. This is a memory estimate; it does not show that such a model was trained.
The communication price of each stage
Standard DP moves 2Ψ elements per step, because an all-reduce is a reduce-scatter followed by an all-gather, each moving Ψ elements. Pos+g keeps the same total, since the reduce-scatter of gradients and the all-gather of updated parameters each move Ψ. Pos+g+p adds a parameter all-gather in the forward pass and another in the backward pass on top of the gradient reduce-scatter, for a total of 3Ψ, which is 1.5x the baseline.
For activation partitioning in ZeRO-R, the extra all-gather per transformer block costs less than 10% of the model-parallel communication volume. Moving partitioned activation checkpoints to CPU, which is Pa+cpu, doubles the data movement relative to Pa and brings activation memory to nearly zero.
Cutting residual memory with ZeRO-R
Partitioned activation checkpointing (Pa) stores each checkpoint split across the model-parallel processes rather than as a full replicated copy. A full activation is rebuilt with an all-gather only when the layer needs it, and the arithmetic intensity of GPT-2-like models, at 10K or more, is what lets this movement stay cheap. In the 100B example with batch size 32, sequence length 1024 and MP degree 16, checkpoints drop from about 33 GB per GPU to about 2 GB, which can then be moved to CPU.
ZeRO-R uses constant-size fused buffers, so the buffer does not grow with the model; a 3B-parameter model with a 32-bit fused buffer would need 12 GB. Memory defragmentation (MD) pre-allocates contiguous chunks for activation checkpoints and gradients and copies them in as they are produced, so short-lived and long-lived tensors do not interleave.
Stacking ZeRO on model parallelism
When ZeRO is combined with MP, the maximum theoretical memory reduction on each device is Nd × Nm, for DP degree Nd and MP degree Nm.
Table 2 compares the theoretical maxima with the measured sizes; for MP degree 1 the baseline reaches 2B in theory and 1.3B when measured, while ZeRO-DP with Pos reaches 7.6B in theory and 6.2B when measured. The authors state that the measured Pos sizes match the theoretical maximum closely enough to indicate the analysis gives realistic upper bounds.
The evaluation setup
The implementation, ZeRO-100B, applies Pos+g together with ZeRO-R, in PyTorch, and is compatible with any torch.nn.module. Experiments ran on a cluster of 400 V100 GPUs in 25 DGX-2 nodes with 800 Gbps internode bandwidth. Without model parallelism the baseline is PyTorch's distributed data parallel; with model parallelism the baseline is Megatron-LM, combined in the ZeRO runs with ZeRO-powered DP.
The models are GPT-2-like transformers, with the hidden dimension and layer count varied to change the parameter count.
Throughput, model size and scaling
Figure 2 plots throughput per GPU against model size for ZeRO-100B with MP and for Megatron MP alone.
ZeRO-100B sustained 15 PetaFlops, over 30% of peak, on average for models from 8B to 100B parameters. The authors report up to 10x speedup over the baseline, most clearly on large models.
For a 60B-parameter model going from 64 to 400 GPUs, the per-GPU throughput rises, which the authors attribute to Pos+g letting each GPU hold a larger batch. Throughput of 38 TFlops per GPU and an aggregate above 15 Petaflops are reported for this model.
ZeRO-100B also trained the 17B-parameter Turing-NLG model, reaching a Webtext-103 perplexity of 10.21 and a sustained 41.4 TFlops per GPU.
Which optimizations move the limits
The five configurations in Table 3 add Pos, Pos+g, Pa and cpu offloading in turn.
For cached memory, the decrease from C1 to C2 is as expected, while the change from C2 to C3 depends on whether model states or activations dominate.
Limitations
Larger batch sizes can hurt convergence, and the authors assume their large-model experiments stay in a regime where the batch size remains small enough not to affect convergence. Throughput drops slightly beyond 100B, which the authors attribute to too little memory for larger batch sizes.
The implementation evaluated is ZeRO-100B with Pos+g and ZeRO-R; stage 3 partitioning of parameters is planned for the trillion-parameter goal. The trillion-parameter results are estimates, since the current hardware compute is too limited to train a 1T model within a reasonable time. The authors estimate that training a 1T model would take 140 days on the same hardware and similar efficiency, and over a year once data samples and sequence length grow.
Paper info
- Authors
- Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase, Yuxiong He
- Venue
- arXiv · Preprint
- First published
- 2019-10-4
- Added
- 2026-10-20
- Updated
- 2020-5-13
- Version
- v3
- arXiv
- 1910.02054
- Category
- cs.LG · cs.DC · stat.ML
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Samyam Rajbhandari, Jeff Rasley, Olatunji Ruwase, Yuxiong He (2019). ZeRO: Memory Optimizations Toward Training Trillion Parameter Models. arXiv:1910.02054v3. https://arxiv.org/abs/1910.02054v3
BibTeX
@misc{rajbhandari2019zero,
title = {{ZeRO: Memory Optimizations Toward Training Trillion Parameter Models}},
author = {Samyam Rajbhandari and Jeff Rasley and Olatunji Ruwase and Yuxiong He},
year = {2019},
eprint = {1910.02054},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1910.02054v3}
}