Inferensys

Glossary

ZeRO (Zero Redundancy Optimizer)

ZeRO (Zero Redundancy Optimizer) is a memory optimization technique for distributed training that partitions optimizer states, gradients, and parameters across data parallel processes to eliminate memory redundancy and enable training of extremely large models.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
MEMORY OPTIMIZATION

What is ZeRO (Zero Redundancy Optimizer)?

ZeRO is a groundbreaking memory optimization technique for distributed training that partitions model states across GPUs to eliminate redundancy and enable the training of models with trillions of parameters.

ZeRO (Zero Redundancy Optimizer) is a memory optimization paradigm for distributed data parallel training that partitions the optimizer states, gradients, and model parameters across all participating GPUs instead of replicating them, thereby eliminating memory redundancy and enabling the training of models far larger than the memory of any single device. It achieves this through three progressive stages—ZeRO-1, ZeRO-2, and ZeRO-3—each offering greater memory savings at the cost of increased communication overhead, fundamentally changing the scalability limits of large language model (LLM) training.

The technique is foundational to frameworks like Microsoft's DeepSpeed, where it is combined with other optimizations like model parallelism and offloading. By dynamically gathering partitioned parameters only when needed for computation, ZeRO maintains the computational efficiency of data parallelism while overcoming its primary memory bottleneck, making it a critical tool for engineering teams tasked with LLM deployment and serving who must manage the extreme resource demands of foundation models.

MEMORY OPTIMIZATION

Key Features and Benefits of ZeRO

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

01

ZeRO Stage 1: Optimizer State Partitioning

ZeRO Stage 1 partitions only the optimizer states (e.g., momentum, variance for Adam) across the data parallel processes. Each GPU stores and updates only its assigned partition of the optimizer states, reducing the memory footprint of the optimizer by a factor of the data parallel degree (N). This is the most basic form of ZeRO, offering significant memory savings with minimal communication overhead.

  • Example: With 8 GPUs (N=8), the memory for Adam optimizer states is reduced by 8x.
  • Benefit: Enables training of models 8x larger with the same GPU memory, or allows the use of larger batch sizes.
02

ZeRO Stage 2: Gradient Partitioning

ZeRO Stage 2 builds on Stage 1 by also partitioning the gradients across processes. After the backward pass, each GPU only retains the gradients corresponding to its partition of the parameters. A global all-gather operation is required to collect the full gradients before the optimizer step, but they are immediately discarded after use.

  • Mechanism: Eliminates the memory redundancy of storing a full copy of gradients on every GPU.
  • Benefit: Further increases model size capacity. Combined with Stage 1, memory reduction scales with N for both optimizer states and gradients.
03

ZeRO Stage 3: Parameter Partitioning

ZeRO Stage 3 is the most memory-efficient stage, partitioning the model parameters themselves across GPUs. Each GPU stores only a fraction of the parameters. During the forward and backward passes, parameters are gathered on-demand for each layer via communication collectives and then released, a process known as the ZeRO-3 forward/backward pass.

  • Key Concept: Parameter offloading can be combined with Stage 3, where inactive parameter partitions are moved to CPU RAM, enabling training of models larger than the aggregate GPU memory.
  • Trade-off: Maximizes model size capability but introduces the highest communication overhead, requiring careful tuning for performance.
05

Communication Patterns and Overhead

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

  • All-Gather: Used in Stage 3 to collect parameters for a layer and in Stage 2 to collect gradients. This is a bandwidth-intensive operation.
  • Reduce-Scatter: Used to sum and partition gradients across GPUs during the backward pass.
  • Overhead Management: The communication overhead is often hidden by overlapping it with computation. Frameworks like DeepSpeed implement sophisticated communication scheduling to minimize the performance impact.
06

Integration with Model Parallelism

ZeRO is fundamentally a data parallelism technique. It is most powerful when combined with other forms of parallelism to train extremely large models.

  • ZeRO + Tensor/Pipeline Parallelism: A common 3D parallelism strategy. ZeRO handles data parallelism across model replicas, while tensor and pipeline parallelism split the model itself across GPUs. This combination allows scaling to thousands of GPUs.
  • Role in Training: ZeRO efficiently manages the memory footprint of the data parallel dimension, while model parallelism techniques manage the memory and compute of the model's layers.
COMPARISON

ZeRO vs. Other Parallelism Techniques

A technical comparison of ZeRO's memory optimization approach against core distributed training parallelism strategies.

Feature / DimensionZeRO (Zero Redundancy Optimizer)Data Parallelism (DP)Model Parallelism (Tensor/Pipeline)

Core Optimization Goal

Eliminate memory redundancy for optimizer states, gradients, and parameters

Scale batch size and accelerate training via replicated workers

Fit a model larger than a single GPU's memory by partitioning it

Memory Footprint per GPU

Dramatically reduced; scales inversely with number of GPUs

Full model replica + optimizer states + gradients (high redundancy)

Only a partition of the model; scales with partition size

Communication Volume

Moderate; collective operations for gradients and parameters

High; all-reduce of gradients after each backward pass

Very high; frequent exchange of activations/gradients between layers (tensor) or pipeline bubbles (pipeline)

Communication-Computation Overlap

Yes, via ZeRO-Offload and ZeRO-Infinity

Limited; synchronization is a blocking operation

Challenging; often a sequential dependency, especially in pipeline parallelism

Ease of Implementation

Integrated into DeepSpeed; requires framework support

Simple; native in most frameworks (e.g., PyTorch DDP)

Complex; requires manual model partitioning or specialized frameworks

Model Size Scalability

Extremely high; enables training of trillion-parameter models

Limited by single-GPU memory for the full model replica

High; limited by aggregate GPU memory across the partition

Compute Utilization

High; maintains data parallel efficiency while reducing memory

High, but limited by gradient synchronization overhead

Often lower due to communication overhead and idle GPU time (bubbles)

Typical Use Case

Training extremely large models where memory is the primary constraint

Training models that fit on a single GPU, needing faster iteration

Training models whose individual layers are too large for one GPU

ZERO REDUNDANCY OPTIMIZER

Implementations and Frameworks

ZeRO is a family of memory optimization techniques for distributed training, primarily implemented within the DeepSpeed library. These stages partition model states across data parallel processes to eliminate memory redundancy.

02

ZeRO Stages: 1, 2, and 3

The core ZeRO technique is implemented in three progressive stages, each partitioning more model state to save more memory:

  • ZeRO Stage 1 (Optimizer State Partitioning): Partitions the optimizer states (e.g., momentum, variance for Adam) across processes. Reduces memory by ~4x.
  • ZeRO Stage 2 (Gradient Partitioning): Adds partitioning of gradients after the backward pass. Reduces memory by ~8x.
  • ZeRO Stage 3 (Parameter Partitioning): Partitions the model parameters across processes, fetching them via all-gather only when needed for computation. Enables training of models with trillions of parameters.
03

ZeRO-Offload & ZeRO-Infinity

These extensions push memory savings beyond GPU RAM limits by leveraging CPU and storage.

  • ZeRO-Offload: Efficiently offloads optimizer states and gradients to CPU memory while keeping parameters on GPU. Enables training models 10x larger on a single GPU.
  • ZeRO-Infinity: The most advanced stage, offloading all ZeRO components—optimizer states, gradients, parameters—to both CPU and NVMe solid-state storage. This allows for training models with tens of trillions of parameters by leveraging terabytes of CPU/NVMe memory.
04

Integration with Hugging Face

ZeRO is accessible to a broad audience through tight integration with the Hugging Face Transformers and Accelerate libraries.

  • The Trainer class in Transformers natively supports DeepSpeed via a JSON configuration file.
  • Hugging Face Accelerate provides a unified interface for distributed training, supporting ZeRO configurations through its DeepSpeedPlugin.
  • This integration allows users to apply ZeRO optimizations with minimal code changes to existing training scripts.
05

PyTorch Fully Sharded Data Parallel (FSDP)

FSDP is PyTorch's native implementation of the ZeRO-3 concept, integrated into the torch.distributed module. It shards model parameters, gradients, and optimizer states across data-parallel processes.

Key comparisons with DeepSpeed ZeRO-3:

  • Tighter PyTorch Integration: Uses PyTorch's native communication primitives.
  • Flexible Sharding: Can shard parameters at the layer level for more efficient communication.
  • Simplified Configuration: Managed via wrapping model layers with FullyShardedDataParallel. Often preferred for new PyTorch-centric projects.
ZERO REDUNDANCY OPTIMIZER

Frequently Asked Questions

ZeRO (Zero Redundancy Optimizer) is a foundational memory optimization technique for distributed training of large language models. This FAQ addresses its core mechanisms, implementation, and role in modern LLMOps.

ZeRO (Zero Redundancy Optimizer) is a memory optimization paradigm for distributed data parallel 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 progressive stages of optimization:

  • ZeRO Stage 1 (Optimizer State Partitioning): The optimizer states (e.g., momentum, variance for Adam) are partitioned across processes. Each process only updates the parameters for its assigned partition, reducing memory footprint proportional to the data parallel degree.
  • ZeRO Stage 2 (Gradient Partitioning): In addition to optimizer states, gradients are also partitioned. During the backward pass, each process only stores the gradients corresponding to its parameter partition, with a collective communication operation (all-gather) to make full gradients available when needed.
  • ZeRO Stage 3 (Parameter Partitioning): The model parameters themselves are partitioned across processes. Parameters are only gathered on-demand for the forward and backward passes of a given layer, then immediately released. This enables training models far larger than the memory of any single GPU.

The technique is implemented within frameworks like DeepSpeed, allowing it to be integrated with other parallelism strategies such as tensor parallelism and pipeline parallelism.

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.