8-bit Optimizers via Block-wise Quantization
Introduction
Researchers have developed the first 8-bit optimizers that match the performance of standard 32-bit states while slashing the memory footprint of optimizer statistics by up to 75%. By using a novel block-wise dynamic quantization technique and a "stable embedding layer," these optimizers allow for training significantly larger models on existing hardware with just a two-line code change.
The Memory Bottleneck
When training massive neural networks like GPT-3 or T5, the model weights aren't the only components taking up space. "Stateful" optimizers like Adam or SGD with momentum need to track moving averages of gradients (the "optimizer state").
In many cases, these states are the primary memory bottleneck, consuming 33% to 75% of the total memory footprint. For example, the optimizer states for a large T5 model can take up 41 GB of VRAM—often more than the model weights themselves. While researchers have tried using 16-bit states, they often face stability issues with models larger than 1 billion parameters. Moving to 8-bit is even harder because you only have 256 possible values to represent a vast range of numbers.
Core Methods
The authors introduce three key components to make 8-bit optimization viable:
1. Block-wise Dynamic Quantization Instead of normalizing an entire tensor at once (where one massive outlier can ruin the precision for everyone else), they divide tensors into small blocks (e.g., 2048 elements). Each block is quantized independently. This "quarantines" outliers to a single block, ensuring high precision for the rest of the data.
2. Dynamic Quantization They use a non-linear mapping (similar to a logarithmic scale) that provides high resolution for both very small and very large values. For strictly positive states (like Adam’s squared gradient moving average), they even repurpose the sign bit to gain more precision.
3. Stable Embedding Layer Large language models often suffer from extreme gradient variance due to the non-uniform distribution of input tokens. The authors add a LayerNorm and specific initialization (Xavier uniform) to the embedding layer to keep gradients stable enough for 8-bit precision.
Crucially, the actual optimizer update happens in 32-bit registers after dequantizing on the fly, meaning there is no loss in the precision of the weight update itself—only in how the statistics are stored.
Key Insights and Results
The authors validated their approach across a massive range of standard benchmarks, including Language Modeling (1.5B and 355M parameter models), NLP Tasks (GLUE), Computer Vision (ImageNet, MoCo v2), and Machine Translation (WMT’14/16).
- Outliers are the Enemy: The "aha moment" is that optimizer states aren't uniformly distributed. A few large gradients usually dictate the scale for the entire tensor in standard quantization. By breaking the tensor into blocks, the authors ensure that 99% of the parameters get the high-resolution quantization they need.
- Performance Parity: Across all tasks, 8-bit Adam/Momentum matched or slightly exceeded the accuracy/perplexity of 32-bit Adam/Momentum.
- Massive Memory Savings: For a 1.5B parameter model, 8-bit Adam saved 8.5 GB of VRAM. For RoBERTa pretraining, it saved 2.0 GB.
- 8-bit is Faster, Not Just Smaller: You might expect quantization to add overhead. However, because 8-bit tensors require much less data movement (memory bandwidth is often the bottleneck in deep learning), these 8-bit optimizers are actually faster than standard 32-bit implementations in PyTorch or Apex. On a V100 GPU, 8-bit Adam was significantly faster than the standard PyTorch 32-bit implementation (47ms vs 145ms per update per 1B parameters).
- No Hyperparameter Tuning Needed: One of the most practical insights is that this is a "drop-in" replacement. You don't need to change your learning rate, betas, or epsilon values to get 32-bit performance.
- Scaling Up: The authors showed that with 8-bit optimizers, a single 24GB GPU (like an RTX 3090) can finetune a 1.5B parameter GPT-2 model, which previously required much more expensive hardware.
Limitations and Future Work
- AdaGrad Issues: The method didn't work as well for the AdaGrad optimizer. The authors hypothesize this is because AdaGrad accumulates statistics over the entire training run, leading to a range of values too wide for 8-bit without stochastic rounding.
- Activation Memory: While this solves the optimizer state bottleneck, it doesn't reduce the memory used by "activations" (the intermediate outputs of layers). For models with very high activation memory (like certain CNNs), the relative memory savings are smaller.
- Full Compression: This paper focused on optimizer states while keeping weights and gradients in 16-bit mixed precision. Future work could look into compressing all three simultaneously for even greater gains.
Summary updated