29 July 2026
ZeRO: Splitting Training Memory Across GPUs
When I started looking at how big models are trained across many GPUs, one name kept coming up: ZeRO (Zero Redundancy Optimizer), from DeepSpeed. In one sentence: store things split up, gather them only when you need them, and let every GPU update only its own piece. It took me a while to see what exactly gets split and when, so today I will go through it step by step.

The problem with plain data parallel
In standard DDP (Distributed Data Parallel), every GPU (each one is a rank):
- keeps a full, identical copy of the model state
- processes a different mini-batch
- runs forward and backward on its own
- averages gradients with every other GPU using
All-Reduce - applies the same optimizer update
With GPUs and local gradients , the synced gradient is:
The catch is that the memory per GPU does not go down as you add GPUs. More GPUs give you more throughput, but a model that does not fit on one card still does not fit.
Why one parameter costs 16 bytes
The ZeRO paper uses the classic FP16 mixed precision + Adam setup. For every trainable parameter we keep:
| State | Precision | Bytes |
|---|---|---|
| Working parameters | FP16 | 2 |
| Gradients | FP16 | 2 |
| Master weights | FP32 | 4 |
| Adam first moment | FP32 | 4 |
| Adam second moment | FP32 | 4 |
| Total | 16 |
So with parameters, DDP needs bytes on every GPU, and of that is optimizer-related. The forward pass only uses 2 bytes per parameter, but stable updates need the FP32 master weights plus Adam's and . That is where most of the memory goes.
These are only model states. Activations, temporary buffers, communication buffers and memory fragmentation come on top.
The three stages
ZeRO removes the duplicates one type at a time. Each stage keeps everything from the stage before and splits one more thing:
| Mode | Parameters | Gradients | Optimizer states | Memory per GPU |
|---|---|---|---|---|
| DDP | copied | copied | copied | |
| ZeRO-1 | copied | copied | split | |
| ZeRO-2 | copied | split | split | |
| ZeRO-3 | split | split | split |
(The paper also has ZeRO-R for the other memory: activation checkpointing, fixed-size buffers and defragmentation. ZeRO-1/2/3 usually only means the first part.)
ZeRO-1: split the optimizer states
Every GPU still has full FP16 parameters and gradients, but rank only keeps the FP32 master weights, and for its own slice . After backward, each rank updates only its slice, then an All-Gather sends the new FP16 slices to everyone.
Think of it as: everyone still has a copy of the model and the gradients, but the biggest items are divided up.
ZeRO-2: also split the gradients
As soon as a group of gradients is ready during backward, a Reduce-Scatter averages them across GPUs and hands each rank only the slice it owns:
The other gradient slices are freed. Each GPU still keeps the full FP16 model, so the model itself must still fit on one card.
ZeRO-3: split the parameters too
This is the stage I misunderstood the most. Now every GPU only keeps its own slice of everything. The full parameters of a layer only exist temporarily, while that layer is being computed. The picture in my head: normally each GPU keeps its own piece; when a layer is needed, everyone puts that layer together; when it is done, it is taken apart again.
The full loop for one step:
- Forward: before each layer,
All-Gatherthat layer's parameters. Every GPU computes its own batch, then frees the borrowed slices. - Loss: each GPU computes its own local loss.
- Backward: gather the layer's parameters again, compute local gradients, then
Reduce-Scatterso each rank keeps only its averaged gradient slice. - Update: each rank updates only its own slice with its own master weights, and . Nothing is collected on one central GPU.
All-Gather has no central rank. Every GPU sends its slice and receives everyone else's at the same time.
You trade bandwidth for memory
ZeRO does not make the model states disappear. It uses communication to bring slices in when needed and drop them afterwards.
- Standard DDP moves about elements per step (
All-Reduce=Reduce-Scatter+All-Gather). - ZeRO-1 and ZeRO-2 reorder this into gradient
Reduce-Scatter+ parameterAll-Gather, so they also move about . - ZeRO-3 needs a gather in forward (), a gather in backward () and a gradient
Reduce-Scatter(), so about , roughly 1.5× DDP.
So ZeRO-3 is not free memory. It replaces stored copies with more parameter gathers.
How the update works with FP16
With FP16 training, small gradients can underflow during backward, so we multiply the loss by a scale first, then divide it back out before the update:
Adam then runs in FP32 on the master weights, and the result is cast back to FP16 for the next forward. Casting the FP16 gradient to FP32 does not bring back lost precision. The real point of the FP32 master weights is that tiny updates can add up there instead of being rounded away in FP16. (BF16 has FP32's range, so it usually does not need loss scaling. I wrote more about that in Floating-Point Precision in LLMs.)
A worked example: 2B parameters on 4 GPUs
| Mode | Parameters | Gradients | Optimizer states | Total per GPU |
|---|---|---|---|---|
| DDP | 4 GB | 4 GB | 24 GB | 32 GB |
| ZeRO-1 | 4 GB | 4 GB | 6 GB | 14 GB |
| ZeRO-2 | 4 GB | 1 GB | 6 GB | 11 GB |
| ZeRO-3 | 1 GB | 1 GB | 6 GB | 8 GB |
These are model states only. They tell you how much is stored long-term, not whether training will run out of memory. For that you still have to add activations, temporary unsplit buffers and communication buffers.