ZeRO Optimization
ZeRO is a family of memory optimization techniques proposed by DeepSpeed, whose core idea is to partition model states among the replicas of data parallelism instead of keeping a full copy on every device. It makes data parallelism scalable in memory and is infrastructure that contemporary large-model training cannot do without.
Core Principles
In standard data parallelism every device stores the full parameters, gradients and optimizer states; adaptive optimizers, for instance, typically maintain two momentum-like statistics per parameter, and with the parameter copies required by mixed-precision training the memory overhead can reach more than ten times the parameter count. ZeRO's insight is that these states are completely redundant across devices and there is no need for each to hold a copy.
From this follow three progressive stages. The first stage partitions only the optimizer states, each device holding one shard and gathering what it needs during training, which is the easiest to adopt with a quite substantial payoff. The second stage partitions the gradients as well, each device keeping only the gradient shard it is responsible for, so the communication volume grows only modestly while memory keeps falling. The third stage also partitions the parameters themselves, each device keeping only one fragment of the full parameters and temporarily gathering the complete parameters of the layer it needs during the forward and backward passes, releasing them once used. At this point the memory usage of data parallelism is almost inversely proportional to the number of devices, at the cost of a marked increase in communication. On top of this there are extensions that offload optimizer states and parameters to CPU memory or even to solid-state drives, for training larger models under limited memory,
Intuitively, ZeRO turns the public ledger that every device used to keep a full copy of into volumes held in turn by everyone and broadcast for combination when needed. This idea raises the scale ceiling of data parallelism markedly and lets many scenarios that previously had to resort to complex model parallelism get by; its value is not in making each step faster but in making scales that could not run at all trainable and usable, thereby widening the choices of training scale.
Key Points
Three progressive stages: partition optimizer states, partition gradients, partition parameters; the memory savings grow stage by stage and so does the communication overhead, so you usually choose where to stop according to cluster bandwidth.
Trading communication for memory: the third stage needs one parameter broadcast in the forward pass and one in the backward pass, so the traffic is roughly several times the parameter count and may not pay off in low-bandwidth cross-machine environments.
The cost of offloading: moving states to CPU memory or disk greatly expands capacity, but it is limited by host memory bandwidth and interconnect speed and often lengthens each step noticeably.
Paired with model parallelism: in large-scale training it is often combined with tensor parallelism and pipeline parallelism,
Usability and tuning: shard size, communication bucket size and offload ratio all affect performance, so benchmarks against the actual cluster are usually needed before fixing the configuration.
Common Misconceptions
A common misunderstanding is that the third stage of ZeRO is always optimal, when in fact it has the highest communication overhead and may not be more economical than the first or second stage outside bandwidth-rich settings. Another is to treat it as a pure memory trick and ignore its effect on the time per iteration, so total training time may actually grow.
Application Scenarios
Large-model pretraining, single-machine multi-device fine-tuning, full-parameter fine-tuning under constrained memory, ultra-long-context training, and large-model experiments on the limited hardware of academic institutions.