Inferensys

Glossary

Zero Redundancy Optimizer (ZeRO)

ZeRO is a memory optimization technique for distributed AI training that partitions model states across GPUs to eliminate redundancy, enabling training of models larger than a single device's memory.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
HARDWARE-AWARE MODEL OPTIMIZATION

What is Zero Redundancy Optimizer (ZeRO)?

A memory optimization technique for distributed training that partitions model states across devices to eliminate redundancy.

The Zero Redundancy Optimizer (ZeRO) is a memory optimization paradigm for data-parallel training that partitions the optimizer states, gradients, and model parameters across all devices in a distributed system to eliminate memory redundancy. Developed by Microsoft, it enables the training of models whose size far exceeds the memory capacity of any single accelerator, such as a GPU or NPU, by ensuring each device stores only a unique shard of the model's total memory footprint.

ZeRO operates through three progressive stages: ZeRO-1 partitions only the optimizer states, ZeRO-2 adds gradient partitioning, and ZeRO-3 partitions all model parameters. This approach transforms the classic data-parallel strategy, where each device holds a full model replica, into a hybrid data-and-model-parallel system. It requires communication to gather parameters or gradients as needed during the forward and backward passes, trading increased network traffic for dramatically reduced per-device memory consumption, which is critical for training large language models and vision transformers.

MEMORY OPTIMIZATION

Key Features of ZeRO

The Zero Redundancy Optimizer (ZeRO) is a suite of memory optimization stages for data-parallel training. It systematically partitions optimizer states, gradients, and model parameters across devices to eliminate memory redundancy, enabling the training of models far larger than a single device's memory capacity.

01

ZeRO Stage 1: Optimizer State Partitioning (P_os)

This is the foundational stage of ZeRO. It partitions the optimizer states (e.g., momentum, variance for Adam) across all data-parallel processes. Each GPU stores and updates only its assigned portion of the optimizer states, reducing memory usage proportional to the data-parallel degree.

  • Memory Reduction: The memory footprint for optimizer states is divided by the number of GPUs (D_pp).
  • Communication Overhead: Minimal. Only requires a single all-gather operation when the full optimizer state is needed for a parameter update, which is infrequent.
  • Impact: Enables training models with ~3x larger batch sizes or model sizes compared to standard data parallelism.
02

ZeRO Stage 2: Gradient Partitioning (P_os+g)

Builds on Stage 1 by also partitioning the gradients across devices. After the backward pass, each GPU only retains the gradients corresponding to its assigned portion of the parameters. A reduction operation is performed to aggregate gradients across devices only for the locally owned slices.

  • Memory Reduction: Eliminates the memory redundancy for gradients, in addition to optimizer states.
  • Communication Pattern: Uses a reduce-scatter operation during gradient synchronization instead of an all-reduce. This is more communication-efficient for this purpose.
  • Impact: Enables training models roughly 8x larger than possible with standard data parallelism, as both major training memory components (optimizer states and gradients) are partitioned.
03

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

The most memory-aggressive stage. It partitions the model parameters themselves across GPUs. Each GPU stores only the slice of parameters it is responsible for. Parameters are gathered on-demand from all devices just before computation in the forward or backward pass and are discarded immediately after.

  • Memory Reduction: The model's parameter memory is divided by the number of GPUs. This enables training models with trillions of parameters.
  • Communication Overhead: Significant. Requires all-gather operations before every layer's computation in both forward and backward passes, and reduce-scatter after backward passes. This trades increased communication for massive memory savings.
  • Use Case: Essential for training the largest foundational models (e.g., models with hundreds of billions to trillions of parameters).
05

Communication Patterns & Overlap

ZeRO's performance depends critically on optimizing communication. It replaces standard all-reduce with more efficient collective operations and overlaps them with computation.

  • Reduce-Scatter: Used in Stage 2/3 for gradient synchronization. Each GPU ends up with a unique slice of the summed gradients.
  • All-Gather: Used in Stage 3 to collect parameters from all GPUs before computation.
  • Overlap Strategy: Modern implementations (e.g., in DeepSpeed) carefully schedule these communications to overlap with independent computation (e.g., the forward pass of one layer with the all-gather for the next layer), hiding much of the communication latency.
06

Integration with Model & Pipeline Parallelism

ZeRO is primarily a data parallelism optimizer. For maximum scalability, it is combined with other forms of parallelism in 3D Parallelism.

  • ZeRO + Model Parallelism (Tensor Parallelism): ZeRO partitions data-parallel groups, while tensor parallelism splits individual layers (e.g., attention heads, MLP blocks) across devices within a group. This combination reduces memory per device and communication volume for very large layers.
  • ZeRO + Pipeline Parallelism: Pipeline parallelism splits the model vertically by layers. ZeRO can be applied within each pipeline stage to further reduce memory usage for the layers resident on that stage's devices.
  • Orchestration: Frameworks like DeepSpeed and PyTorch Fully Sharded Data Parallel (FSDP) manage this complex orchestration, allowing the training of the world's largest AI models.
MEMORY OPTIMIZATION

How ZeRO Works: The Three Stages

The Zero Redundancy Optimizer (ZeRO) eliminates memory waste in distributed training by partitioning model states across devices. It operates through three progressive stages, each offering greater memory savings at the cost of increased communication.

ZeRO Stage 1 (Optimizer State Partitioning) partitions only the optimizer states (e.g., momentum, variance) across data-parallel processes. Each GPU stores and updates only its assigned partition, reducing memory footprint proportional to the data-parallel degree. This stage requires a single all-gather communication during the optimizer step to collect the full state for updating each GPU's local model parameters.

ZeRO Stage 2 (Gradient Partitioning) extends partitioning to the gradients, in addition to the optimizer states. Gradients are reduced across devices in a partitioned manner, where each GPU only stores and aggregates the slice of gradients corresponding to its optimizer state partition. This requires an all-gather for gradients before the weight update and eliminates gradient memory redundancy, enabling the training of larger models or the use of larger batches.

MEMORY AND COMMUNICATION OVERHEAD COMPARISON

ZeRO vs. Other Parallelism Strategies

This table compares the core memory optimization and communication characteristics of the Zero Redundancy Optimizer (ZeRO) against other fundamental distributed training strategies.

Feature / MetricZeRO (Zero Redundancy Optimizer)Data Parallelism (DP)Model Parallelism (MP)Pipeline Parallelism (PP)

Primary Optimization Goal

Eliminate memory redundancy of states/parameters

Increase batch size and throughput

Fit a single layer on a device

Overlap computation across layers

Memory Reduction per Device

Up to 8x (ZeRO-3) vs. DP

None (full model replica)

Proportional to layer split

Proportional to stage split

Communication Volume

High (gradients, parameters)

High (gradients only)

Very High (activations, gradients)

Moderate (activations between stages)

Communication Synchronization

All-reduce per optimizer step

All-reduce per backward pass

Point-to-point between layers

Point-to-point between pipeline stages

Ideal Model Size

Extremely Large (>> single GPU memory)

Fits in single GPU memory

Single layer > GPU memory

Model depth >> GPU count

Implementation Complexity

High (requires framework integration)

Low (standard in frameworks)

Very High (manual layer splitting)

High (requires careful bubble management)

Supports Layer Dropout/BatchNorm

Requires Model Code Modification

HARDWARE-AWARE MODEL OPTIMIZATION

Frameworks & Implementations

The Zero Redundancy Optimizer (ZeRO) is a foundational memory optimization technique for distributed deep learning training. It systematically partitions model states across devices to eliminate memory redundancies, enabling the training of models with trillions of parameters.

01

Core Optimization Stages

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

  • ZeRO Stage 1 (P_os): Partitions optimizer states (e.g., momentum, variance) across data-parallel processes. Reduces memory by ~4x.
  • ZeRO Stage 2 (P_os+g): Adds partitioning of gradients. Each process only stores gradients for its assigned parameters, reducing memory by ~8x.
  • ZeRO Stage 3 (P_os+g+p): Partitions the model parameters themselves. Parameters are gathered on-demand for the forward/backward pass and discarded afterward, enabling near-linear memory scaling with the number of GPUs.
03

ZeRO vs. Classic Data Parallelism

ZeRO enhances, rather than replaces, standard Data Parallel (DP) training.

  • Classic DP: Replicates the entire model, optimizer states, and gradients on every GPU. Communication is a single all-reduce of gradients. Memory usage is identical on all devices.
  • ZeRO-powered DP: Maintains the data parallelism paradigm but partitions the model states. It uses a reduce-scatter operation to distribute gradient aggregation and an all-gather to collect parameters, trading increased communication for massive memory savings. The computational workload per device remains the same.
04

Communication Overhead & Optimizations

ZeRO Stage 3 introduces significant communication for gathering parameters. Key optimizations mitigate this cost:

  • Overlapping Communication and Computation: Parameters for the next layer are gathered while the current layer computes.
  • Parameter Persistence: Keeping a small subset of critical parameters (e.g., embedding layers) resident on each GPU.
  • Hierarchical Partitioning: In multi-node setups, parameters are partitioned first across nodes, then within nodes, to optimize for slower inter-node links. The communication volume is approximately 1.5x that of classic DP, but the enabling of larger batch sizes often results in better aggregate throughput.
05

Related Concept: Mixture of Experts (MoE) with ZeRO

ZeRO is particularly effective for training Mixture of Experts (MoE) models like Google's Switch Transformers.

  • In MoE models, only a subset of 'expert' layers are activated per token, creating a naturally sparse, massive model.
  • Applying ZeRO Stage 1 to the shared optimizer states and ZeRO Stage 2 to the sparse gradients is highly efficient.
  • The combination allows for models with over a trillion parameters while keeping the computational cost per token similar to a dense model 1/10th the size.
06

Integration with Other Parallelism Strategies

ZeRO is often combined with other forms of parallelism for training extreme-scale models:

  • ZeRO + Tensor Parallelism: ZeRO handles data parallelism across nodes, while tensor parallelism splits individual layers (e.g., attention heads, MLP blocks) across GPUs within a node. This is used in Megatron-DeepSpeed.
  • ZeRO + Pipeline Parallelism: ZeRO optimizes memory within a pipeline stage, while pipeline parallelism splits the model layers sequentially across devices. This hybrid approach is standard for models exceeding hundreds of billions of parameters.
  • The choice of hybrid strategy depends on the cluster topology, model architecture, and communication bandwidth.
ZERO REDUNDANCY OPTIMIZER (ZERO)

Frequently Asked Questions

The Zero Redundancy Optimizer (ZeRO) is a foundational memory optimization technique for training massive neural networks across multiple devices. It systematically partitions optimizer states, gradients, and model parameters to eliminate memory redundancy, enabling the training of models far larger than the memory of any single accelerator.

The Zero Redundancy Optimizer (ZeRO) is a memory optimization technique for data-parallel training that partitions optimizer states, gradients, and model parameters across devices to eliminate memory redundancy. It works through three progressive stages (ZeRO-1, ZeRO-2, ZeRO-3) that incrementally offload different components of the training state. In ZeRO-1, the optimizer states (e.g., momentum, variance) are partitioned, with each device storing and updating only its assigned slice, requiring an all-gather communication during the optimizer step. ZeRO-2 adds the partitioning of gradients, further reducing memory by ensuring each device only holds the gradients corresponding to its slice of the parameters. ZeRO-3, the most aggressive stage, partitions the model parameters themselves. Each device stores only the parameters for which it is responsible, requiring all-gather communication before the forward and backward passes to materialize the full layers temporarily.

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.