Inferensys

Glossary

Zero Redundancy Optimizer (ZeRO)

ZeRO is a memory optimization paradigm for distributed training that partitions optimizer states, gradients, and parameters across devices to eliminate memory redundancy.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
MEMORY COMPRESSION TECHNIQUE

What is Zero Redundancy Optimizer (ZeRO)?

The Zero Redundancy Optimizer (ZeRO) is a memory optimization paradigm for distributed training that partitions optimizer states, gradients, and parameters across devices to eliminate memory redundancy.

The Zero Redundancy Optimizer (ZeRO) is a suite of memory optimization techniques for distributed deep learning that partitions the model state—comprising optimizer states, gradients, and parameters—across all available devices. This eliminates the memory redundancy inherent in traditional data-parallel training, where each GPU holds a full copy of the entire model. By sharding these components, ZeRO enables the training of models that are orders of magnitude larger than the memory of any single accelerator.

ZeRO operates through three progressive stages: ZeRO-1 shards only the optimizer states, ZeRO-2 adds gradient partitioning, and ZeRO-3 partitions all model parameters. During forward and backward passes, parameters are gathered on-demand from across the device cluster and subsequently released, a process managed by the ZeRO-Offload and ZeRO-Infinity extensions. This approach transforms aggregate device memory into a pooled resource, fundamentally addressing the memory wall for large language models and other massive neural networks.

MEMORY COMPRESSION TECHNIQUES

Core Technical Characteristics

The Zero Redundancy Optimizer (ZeRO) is a memory optimization paradigm for distributed training that partitions optimizer states, gradients, and parameters across devices to eliminate memory redundancy. It enables the training of models with trillions of parameters by removing the memory replication inherent in traditional data-parallel training.

01

ZeRO Stage 1: Optimizer State Partitioning

In ZeRO Stage 1 (ZeRO-1), only the optimizer states (e.g., momentum, variance for Adam) are partitioned across the available GPUs. Each GPU stores and updates only a slice of the total optimizer states, reducing the per-GPU memory footprint of the optimizer by a factor of the number of data-parallel processes (N_d).

  • Mechanism: The full model parameters and gradients are still replicated on each GPU.
  • Memory Reduction: Optimizer state memory is reduced from O(P) to O(P/N_d), where P is the number of model parameters.
  • Communication: Requires an all-gather of parameters before the forward pass and a reduce-scatter of gradients after the backward pass, but optimizer updates are local.
02

ZeRO Stage 2: Gradient Partitioning

ZeRO Stage 2 (ZeRO-2) builds on Stage 1 by also partitioning the model gradients across GPUs. After the backward pass, each GPU only retains the gradients corresponding to its slice of the parameters.

  • Mechanism: Optimizer states and gradients are partitioned. Full parameters are still replicated.
  • Memory Reduction: Gradient memory is reduced from O(P) to O(P/N_d). Combined with Stage 1, this significantly reduces memory during the backward pass.
  • Communication: Maintains the same all-gather/reduce-scatter pattern for parameters/gradients. Since each GPU has the gradients needed for its slice of optimizer states, updates remain local.
03

ZeRO Stage 3: Parameter Partitioning

ZeRO Stage 3 (ZeRO-3) is the most memory-efficient stage, partitioning the model parameters themselves across GPUs, in addition to optimizer states and gradients. At any given time, a GPU only holds a fraction of the full model.

  • Mechanism: Implements full model parallelism for memory purposes. Parameters are all-gathered on-demand for forward/backward computation and then released immediately after use.
  • Memory Reduction: Model parameter memory is reduced from O(P) to O(P/N_d). This enables training models larger than the memory of any single GPU.
  • Communication Overhead: Highest among ZeRO stages, due to frequent all-gather and reduce-scatter operations for parameters.
05

Communication Patterns & Overhead

ZeRO's memory savings come with increased inter-GPU communication, which is managed through specific collective operations.

  • All-Gather: Used to collect partitioned tensors (e.g., parameters in ZeRO-3) from all GPUs to form a complete tensor for computation.
  • Reduce-Scatter: Used to distribute and sum a complete tensor (e.g., gradients) across GPUs, so each GPU gets a unique slice of the result.
  • Bandwidth vs. Memory Trade-off: ZeRO trades higher network bandwidth utilization for drastically lower GPU memory consumption. The overhead is often acceptable as modern interconnects (e.g., NVLink, InfiniBand) provide high bandwidth.
  • Optimization: Techniques like communication overlapping (hiding communication behind computation) are critical for maintaining training throughput.
06

Integration with Model Parallelism

ZeRO is fundamentally a data parallelism technique. It is often combined with other forms of parallelism for maximum scalability.

  • Pipeline Parallelism: ZeRO can be used within a pipeline stage to reduce memory for the model chunk residing on a set of GPUs. This combination is common in frameworks like DeepSpeed.
  • Tensor Parallelism: ZeRO can be layered on top of tensor (intra-layer) parallelism. Here, ZeRO's data-parallel group is formed across tensor-parallel groups, partitioning the already-sharded model further.
  • 3D Parallelism: The combination of ZeRO (Data Parallelism), Pipeline Parallelism, and Tensor Parallelism is termed 3D parallelism. It is the state-of-the-art strategy for training the largest foundation models, allowing independent scaling across the three dimensions of compute resources.
MEMORY OPTIMIZATION

How ZeRO Works: The Partitioning Mechanism

The Zero Redundancy Optimizer (ZeRO) is a memory optimization paradigm for distributed training that partitions optimizer states, gradients, and parameters across devices to eliminate memory redundancy.

ZeRO eliminates memory redundancy by partitioning the three primary memory components of a model—optimizer states, gradients, and parameters—across all available GPUs in a data-parallel group. Instead of each device holding a full copy, each GPU stores only a unique shard of these tensors. During the forward and backward passes, the framework orchestrates all-gather operations to temporarily reconstruct the full parameters needed for computation, before scattering the updated data back to their respective shard owners. This partitioning is the core mechanism that enables the training of models far larger than the memory of any single device.

The strategy is implemented in progressive stages: ZeRO-Stage 1 partitions only the optimizer states, ZeRO-Stage 2 adds gradient partitioning, and ZeRO-Stage 3 partitions all model parameters. Each stage increases memory savings at the cost of additional communication overhead. Crucially, ZeRO operates within a data-parallel framework, meaning each GPU processes a different mini-batch, preserving training efficiency while dramatically reducing the per-device memory footprint. This makes it foundational for training modern large language models (LLMs) and other massive neural networks.

ZERO REDUNDANCY OPTIMIZER (ZERO)

Frequently Asked Questions

The Zero Redundancy Optimizer (ZeRO) is a foundational memory optimization paradigm for distributed deep learning training. It systematically partitions model states across devices to eliminate memory redundancy, enabling the training of models with trillions of parameters. This FAQ addresses its core mechanisms, stages, and practical implications for engineers.

The Zero Redundancy Optimizer (ZeRO) is a memory optimization paradigm for distributed training that partitions the optimizer states, gradients, and model parameters across all available devices (e.g., GPUs) to eliminate memory redundancy. It works by sharding these components so that each processor stores and updates only a unique slice, using collective communication operations to gather the necessary data on-demand during the forward and backward passes. This approach transforms the classical data-parallel training workflow, where every GPU holds a full copy of the model, into a memory-efficient distributed system, dramatically increasing the feasible model size for a given hardware configuration.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.