Inferensys

Glossary

ZeRO (Zero Redundancy Optimizer)

ZeRO is a memory optimization technique 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.
DYNAMIC NEURAL ARCHITECTURES

What is ZeRO (Zero Redundancy Optimizer)?

ZeRO (Zero Redundancy Optimizer) is a memory optimization technique for distributed training that partitions optimizer states, gradients, and parameters across devices to eliminate memory redundancy, enabling the training of models with trillions of parameters.

ZeRO is a memory optimization technique for distributed deep learning that eliminates memory redundancy by partitioning the model's optimizer states, gradients, and parameters across all available GPUs. Unlike traditional data parallelism, where each device holds a full copy of the model, ZeRO ensures each GPU stores only a unique slice of these tensors. This partitioning strategy dramatically reduces the per-device memory footprint, enabling the training of models that are an order of magnitude larger than the memory of any single GPU. It is a foundational technology for training modern large language models (LLMs).

The technique operates across three progressive stages: ZeRO-1 partitions only the optimizer states, ZeRO-2 adds gradient partitioning, and ZeRO-3 partitions all model parameters. During the forward and backward passes, the required partitioned data is gathered via all-gather collective operations across the network as needed, then re-partitioned afterward. This communication-for-memory trade-off is managed efficiently to minimize overhead. ZeRO is often integrated with model parallelism strategies and is a core component of frameworks like Microsoft DeepSpeed, allowing for the efficient scaling of model training to thousands of GPUs.

MEMORY OPTIMIZATION

Key Features of ZeRO

ZeRO (Zero Redundancy Optimizer) is a suite of memory optimization stages for distributed training that partitions model states across devices to eliminate redundancy, enabling the training of models with trillions of parameters.

01

ZeRO Stage 1: Optimizer State Partitioning (P_os)

Partitions the optimizer states (e.g., momentum, variance for Adam) across all data-parallel processes. Each GPU stores and updates only its assigned slice of the optimizer states for the entire model.

  • Memory Reduction: Reduces memory footprint proportional to the data-parallel degree (1/N_dp).
  • Communication Overhead: Requires an all-gather operation before the optimizer step and a reduce-scatter after the backward pass to synchronize the partitioned states.
  • Impact: Enables training of models roughly 4x larger than standard data parallelism with the same number of GPUs.
02

ZeRO Stage 2: Gradient Partitioning (P_os+g)

Extends Stage 1 by also partitioning the model gradients across data-parallel processes. Gradients are reduced to their respective owning GPUs during the backward pass, eliminating their redundancy.

  • Memory Reduction: Further reduces memory compared to Stage 1, as full gradients are not stored on any single device.
  • Communication Pattern: Uses a reduce-scatter operation during backward pass instead of an all-reduce, which is more communication efficient for this purpose.
  • Benefit: Allows for even larger model sizes or larger batch sizes per GPU by freeing gradient memory.
03

ZeRO Stage 3: Parameter Partitioning (P_os+g+p)

The most memory-efficient stage. Partitions the model parameters themselves across GPUs. Each GPU stores only the slice of parameters it owns.

  • Memory Reduction: Memory consumption per GPU is reduced almost linearly with the number of data-parallel processes.
  • On-Demand Activation: Parameters are gathered just-in-time for the forward or backward pass and are released immediately after use.
  • Trade-off: Introduces additional communication overhead (all-gather/reduce-scatter) for each layer's computation, which can impact throughput. Often used with ZeRO-Infinity for offloading to CPU/NVMe.
05

Communication Overlap & Optimizations

ZeRO employs several strategies to mitigate the communication overhead introduced by partitioning.

  • Overlapped Communication: The all-gather for parameters (Stage 3) is overlapped with the computation of the previous layer, hiding latency.
  • Reduced Precision Communication: Gradients and optimizer states can be communicated in lower precision (e.g., FP16) while maintaining master weights in FP32 for stability.
  • Contiguous Memory Buffers: Aggregates small communication operations into larger, contiguous buffers to maximize network bandwidth utilization.
06

Integration with 3D Parallelism

ZeRO is designed to complement, not replace, other forms of model parallelism. It is most powerful when combined into 3D Parallelism:

  • Data Parallelism (DP): ZeRO operates within this dimension.
  • Tensor Model Parallelism (TP): Splits individual layers across GPUs (e.g., Megatron-LM).
  • Pipeline Model Parallelism (PP): Splits the model into sequential stages.

ZeRO (specifically ZeRO-3) can be combined with TP and PP. In this hybrid strategy, parameters are partitioned within each data-parallel group, while TP and PP handle intra-layer and inter-layer partitioning, respectively. This allows for training models at an unprecedented scale.

MEMORY AND COMMUNICATION COMPARISON

ZeRO vs. Traditional Parallelism Strategies

This table compares the core memory optimization and communication characteristics of ZeRO with traditional data and model parallelism strategies for distributed training of large models.

Feature / MetricData Parallelism (DP)Model Parallelism (MP)Pipeline Parallelism (PP)ZeRO (Zero Redundancy Optimizer)

Primary Optimization Goal

Batch processing speed

Model size per device

Layer execution latency

Aggregate memory footprint

Memory Redundancy

High (Full model/optimizer state on each device)

Low (Unique model partitions)

Low (Unique pipeline stages)

None (Partitioned states)

Communication Volume Per Step

Gradient All-Reduce (2x model size)

Activation/Gradient forwarding (layer-dependent)

Activation micro-bubble forwarding

Gather/Reduce-Scatter (configurable)

Maximum Model Size (Theoretical)

Limited by single-device memory

Model size * Number of devices

Model size * Pipeline depth

Model size * Number of devices (with full ZeRO-3)

Inter-Device Dependency

Synchronous per batch

Sequential per layer (tensor-slicing)

Sequential per pipeline stage

Configurable (ZeRO-1,2,3)

Optimizer State Memory

Replicated on all devices

Partitioned with model

Partitioned with pipeline stage

Partitioned across all devices (ZeRO-1)

Gradient Memory

Replicated during All-Reduce

Partitioned with model

Partitioned with pipeline stage

Partitioned across all devices (ZeRO-2)

Parameter Memory

Replicated on all devices

Partitioned across devices

Partitioned across pipeline stages

Partitioned across all devices (ZeRO-3)

Code Modification Complexity

Low (Framework-managed)

High (Manual layer splitting)

Medium (Manual stage definition)

Low (Integrated into DeepSpeed)

Best Suited For

Dense models fitting on one GPU

Extremely wide layers (e.g., large FFNs)

Models with many sequential layers

Massive models with limited per-device memory

DYNAMIC NEURAL ARCHITECTURES

Frameworks and Implementations

ZeRO (Zero Redundancy Optimizer) is a foundational memory optimization technique for distributed training, enabling the training of models with trillions of parameters by partitioning optimizer states, gradients, and parameters across devices to eliminate memory redundancy.

01

Core Optimization Stages

ZeRO operates in three progressive stages, each eliminating a different type of memory redundancy:

  • ZeRO Stage 1 (P_{os}): Partitions the optimizer states (e.g., momentum, variance) across GPUs. Each GPU stores and updates only its assigned partition.
  • ZeRO Stage 2 (P_{os+g}): Adds partitioning of gradients to Stage 1. Gradients are reduced across devices only for the partition each GPU is responsible for, slashing memory further.
  • ZeRO Stage 3 (P_{os+g+p}): The most memory-efficient stage. Partitions the model parameters themselves. Each GPU stores only the parameters for its partition, with parameters gathered via communication as needed during the forward and backward passes.
02

ZeRO-Offload & ZeRO-Infinity

These are advanced extensions that push memory savings beyond GPU RAM limits.

  • ZeRO-Offload: Intelligently offloads optimizer states and gradients to CPU memory, while keeping parameters on GPU. It uses optimized asynchronous data movement to minimize performance impact, enabling training of models 10x larger on a single GPU.
  • ZeRO-Infinity: Extends offloading to include model parameters, leveraging both CPU RAM and NVMe storage. It uses innovative techniques like infinity_offload and block-level management to enable training of models with trillions of parameters (e.g., 1-100T scale) on limited GPU clusters.
04

Communication Patterns & Overhead

ZeRO's memory savings come with a trade-off in inter-GPU communication, which is carefully managed.

  • All-Gather: In Stage 3, parameters are gathered from all GPUs before a layer's forward/backward pass, then discarded afterward.
  • Reduce-Scatter: Gradients are reduced and scattered to their respective partition owners after the backward pass.
  • Overhead Mitigation: Overlap communication with computation to hide latency. For example, while one layer is computing, parameters for the next layer can be gathered asynchronously. The overhead is often minimal compared to the memory gains, especially on high-bandwidth interconnects like NVLink.
05

Comparison to Standard Data Parallelism

ZeRO solves the fundamental memory inefficiency of Data Parallelism (DP).

  • DP Redundancy: In standard DP, the entire model (parameters, gradients, optimizer states) is replicated on every GPU. This limits model size to what fits on a single GPU.
  • ZeRO Solution: ZeRO removes this replication by partitioning. It maintains the same computational granularity as DP (each GPU processes a micro-batch) but with linear reduction in memory consumption per GPU as more devices are added.
  • Result: Enables model sizes that scale almost linearly with the total aggregate GPU memory of the cluster, not the memory of a single device.
06

Use with Mixture of Experts (MoE)

ZeRO is particularly synergistic with Sparse Mixture of Experts models, leading to the ZeRO-MoE system.

  • Challenge: MoE models have a massive number of parameters (experts), but only a small subset is active per token. Standard parallelism is inefficient.
  • Solution: ZeRO Stage 3 partitions the enormous set of experts across devices. The MoE gating network routes tokens to the devices holding their required experts. ZeRO handles the communication for the shared non-expert layers (e.g., attention).
  • Outcome: This combination allows for training and inference of models with effectively hundreds of billions to trillions of parameters while maintaining manageable computational cost per token.
ZERO REDUNDANCY OPTIMIZER

Frequently Asked Questions

ZeRO (Zero Redundancy Optimizer) is a foundational memory optimization technique for distributed deep learning training. These questions address its core mechanisms, practical applications, and relationship to other advanced training paradigms.

ZeRO (Zero Redundancy Optimizer) is a memory optimization paradigm for distributed training that partitions the three primary memory-consuming states—optimizer states, gradients, and model parameters—across data-parallel processes to eliminate memory redundancy. It works through three progressive stages (ZeRO-1, ZeRO-2, ZeRO-3), each partitioning an additional component. In ZeRO-1, only the optimizer states (e.g., momentum, variance) are partitioned; each GPU stores only its shard, reducing memory by the number of GPUs. ZeRO-2 adds gradient partitioning, where each GPU is responsible for updating and storing a shard of the gradients, with all-reduce operations used to gather them as needed. ZeRO-3 extends this to full model parameter partitioning, where each GPU holds only a shard of the parameters, and parameters are gathered via communication (all-gather) just before computation in the forward and backward passes, then discarded afterward. This staged approach allows training models with trillions of parameters by aggregating the GPU memory of an entire cluster.

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.