Skip to main content

ZeRO: Deep Memory Optimization for Training Trillion-Parameter Models

In 2020, Microsoft researchers introduced ZeRO (Zero Redundancy Optimizer) via their paper "ZeRO: Memory Optimization Towards Training Trillion Parameter Models" (arXiv:1910.02054). ZeRO is a memory optimization technique that eliminates redundancy in distributed training, enabling efficient scaling to trillion-parameter models. This provides an in-depth technical breakdown of ZeRO's partitioning strategies, memory usage analysis, and integration with DeepSpeed.

1. What is ZeRO?

ZeRO eliminates redundant memory copies of model states across GPUs. Instead of replicating parameters, gradients, and optimizer states across each GPU, ZeRO partitions them across all devices. This results in near-linear memory savings as the number of GPUs increases.

2. Limitations of Traditional Data Parallelism

In standard data-parallel training, every GPU maintains:

  • Model Parameters $\theta$
  • Gradients $\nabla \theta$
  • Optimizer States $O(\theta)$
This causes memory usage to scale linearly with model size, regardless of GPU count.

3. ZeRO’s Three Optimization Stages

 Comparing the per-device memory consumption of model states, with three stages of ZeRO-DP optimizations. Ψ denotes model size (number of parameters), K denotes the memory multiplier of optimizer states, and Nd denotes DP degree. In the example, we assume a model size of Ψ = 7.5B and DP of Nd = 64 with K = 12 based on mixed-precision training with Adam optimizer.

3.1 ZeRO-1: Partitioning Optimizer States

Each GPU stores only a portion of the optimizer states (e.g., Adam's first and second moments), reducing memory from $2 \times |\theta|$ to:

$$ \text{Memory}_{optimizer} = \frac{2 \times |\theta|}{N} $$

3.2 ZeRO-2: Partitioning Gradients

Gradients are no longer reduced to all GPUs. Instead, each GPU owns and updates a subset of $\nabla \theta$, reducing redundant storage.

3.3 ZeRO-3: Partitioning Model Parameters

ZeRO-3 splits the model parameters themselves, allowing a model to scale linearly with the number of GPUs. Forward and backward passes are executed using temporary broadcasts or gathers as needed.

4. Memory Efficiency

The combined memory usage in ZeRO is:

$$ \text{Total Memory}_{ZeRO} = \frac{|\theta| + |\nabla \theta| + |O(\theta)|}{N} $$

Compared to the traditional:

$$ \text{Total Memory}_{DP} = |\theta| + |\nabla \theta| + |O(\theta)| $$

This achieves up to $N$-fold improvement in memory efficiency.

5. DeepSpeed Integration

ZeRO is fully integrated into the DeepSpeed library. DeepSpeed supports ZeRO stages, CPU/NVMe offloading, mixed precision, and efficient activation checkpointing, enabling the training of trillion-scale models with manageable hardware.

6. Experimental Results

ZeRO showed up to 10× larger model capacity and improved throughput on models like BERT-Large and GPT-2. The performance remained stable even as GPU count increased.

7. Limitations and Future Work

While ZeRO increases communication overhead, ZeRO-Infinity (2021) introduced CPU and NVMe offloading to alleviate these costs. Future directions include asynchronous data movement and hierarchical memory systems.

References

  • Rajbhandari et al., "ZeRO: Memory Optimization Towards Training Trillion Parameter Models", arXiv:1910.02054
  • https://www.deepspeed.ai/
  • ZeRO-Infinity: https://arxiv.org/abs/2104.07857

Comments

Popular

How to Fine-Tune LLaMA 3.2-1B-Instruct for Korean Instruction Tasks with LoRA and Hugging Face

LLaMA 3.2-1B-Instruct is a lightweight instruction-tuned language model released by Meta. It is designed to handle a wide range of instruction-based tasks with relatively low computational resources. Although the model was trained with multilingual capabilities, its performance on languages not included in its training set—such as Korean—is limited. This tutorial demonstrates how to fine-tune this open-source model on a Korean dataset using Hugging Face Transformers and PEFT (specifically LoRA), enabling it to better respond to Korean instructions. 1. Prerequisites Before running the example code below, ensure you have the following libraries installed: pip install torch transformers datasets peft accelerate mlflow huggingface_hub To use the LLaMA model or KoAlpaca datasets, you'll need a Hugging Face token. Additionally, you may need to handle potential CUDA Out-Of-Memory (OOM) errors. The following code takes care of both: from huggingface_hub import login login("y...

RF-DETR: Overcoming the Limitations of DETR in Object Detection

RF-DETR (Region-Focused DETR), proposed in April 2025, is an advanced object detection architecture designed to overcome fundamental drawbacks of the original DETR (DEtection TRansformer) . In this technical article, we explore RF-DETR's contributions, architecture, and how it compares with both DETR and the improved model D-FINE . We also provide experimental benchmarks and discuss its real-world applicability. RF-DETR Architecture diagram for object detection Limitations of DETR DETR revolutionized object detection by leveraging the Transformer architecture, enabling end-to-end learning without anchor boxes or NMS (Non-Maximum Suppression). However, DETR has notable limitations: Slow convergence, requiring heavy data augmentation and long training schedules Degraded performance on low-resolution objects and complex scenes Lack of locality due to global self-attention mechanisms Key Innovations in RF-DETR RF-DETR intr...

SVD and Truncated SVD Explained: Theory, Python Examples, and Applications in Machine Learning & Deep Learning

Singular Value Decomposition (SVD) is a matrix factorization method widely used in mathematics, engineering, and economics. Since it's a crucial concept applied in accelerating matrix computations and data compression, it's worth studying at least once. SVD (Singular Value Decomposition) Theory Singular Value Decomposition (SVD) is a matrix factorization technique applicable to any real or complex matrix. Any matrix  A (m×n)  can be decomposed as follows: $A = U * \Sigma * V^T$ U : Orthogonal matrix composed of left singular vectors $(m \times m)$ Σ : Diagonal matrix $(m \times n)$ with singular values on the diagonal $V^T$ : Transposed matrix of right singular vectors $(n \times n)$ The singular values represent the energy or information content of matrix A, enabling tasks like dimensionality reduction or noise filtering. Truncated SVD Truncated SVD approximates the original matrix using only the top  k  singular values and corresponding singular vectors: $A \approx...