ZeRO Optimisation
Plain data parallelism has an awkward secret: every GPU holds an identical copy of the model, its gradients and its optimiser state, so extra hardware buys speed but no extra room. ZeRO — the Zero Redundancy Optimizer, part of Microsoft's DeepSpeed — deletes that duplication rather than the model.
Three stages of shardingTraining state is split across the data-parallel ranks, each holding one slice, and gathered only when it is needed. Mixed-precision Adam costs roughly sixteen bytes per parameter once master weights, momentum and variance are counted, and the stages peel that back in order:
- Stage 1 shards the optimiser state, the largest single consumer, cutting memory about fourfold;
- Stage 2 adds the gradients, roughly eightfold;
- Stage 3 adds the parameters themselves, so per-GPU memory falls in proportion to the number of GPUs; each layer's weights are all-gathered just before use and released immediately after.
Stages 1 and 2 move no more data than ordinary data parallelism, which makes them close to free; stage 3 adds communication, and on a slow interconnect that surfaces as idle accelerators. ZeRO-Offload and ZeRO-Infinity push slices further out, to CPU memory or NVMe, trading bandwidth for capacity when the GPUs are simply too few. The deeper point is that sharding leaves the mathematics untouched: unlike tensor or pipeline parallelism, you keep an unmodified model definition and one familiar training loop, which is why it is the first thing to reach for when a model will not fit. PyTorch's FSDP is the same design built into the framework, and BLOOM was trained with ZeRO alongside tensor and pipeline parallelism.
ZeRO (Zero Redundancy Optimizer), from DeepSpeed, removes the duplication in data-parallel training by sharding optimiser state (stage 1), gradients (stage 2) and parameters (stage 3) across devices, gathering each slice only while it is in use. Per-device memory then falls roughly in proportion to device count, letting multi-billion-parameter models train with an unmodified model definition and an ordinary training loop. PyTorch's FSDP implements the same design.
Training a large language model takes many machines working together. The simple way is to give every machine the whole model and a different pile of examples — but then every machine stores the same enormous thing, so adding machines never makes room for a bigger model. ZeRO fixes that waste. Instead of everyone keeping a full copy, each machine keeps one slice and passes it round when the others need it, rather like a study group sharing a single set of reference books instead of each buying the set. Nothing is lost, and models far too large for any one machine suddenly fit.