TL;DR
Second-order optimizers like Shampoo converge incredibly fast but are notorious memory hogs, limiting the size of the models you can train. This paper introduces 4-bit Shampoo, the first second-order optimizer to compress its memory-heavy matrix states down to 4 bits. By cleverly quantizing the preconditioner's eigenvector matrix instead of the matrix itself, it slashes memory usage while matching the accuracy and speed of the standard 32-bit version.
What Problem Does This Paper Address?
In deep learning, first-order optimizers (like SGD and AdamW) are the standard. They are memory-efficient but often require many steps to converge. Second-order optimizers (like Shampoo, K-FAC, or AdaBK) use curvature information to take smarter, more direct steps, drastically speeding up convergence.
However, this speed comes at a steep cost: memory. Second-order optimizers maintain large matrices called preconditioners and their inverse roots. Storing these matrices in 32-bit floating-point precision eats up precious GPU memory that could otherwise be used for larger models or bigger batch sizes.
While researchers have successfully compressed first-order optimizer states to 8-bit or 4-bit, doing this for second-order optimizers is much harder. First-order states are simple element-wise vectors, but second-order states rely on complex matrix operations. If you naively quantize a preconditioner matrix to 4 bits, the mathematical errors explode, and the optimizer fails. This paper figures out how to make 4-bit quantization work for matrix-based optimizers.
Methods
The authors propose a quantization pipeline specifically designed to survive the rigorous math of second-order optimization.
- The Core Trick: Quantizing Eigenvectors, Not Preconditioners. Shampoo requires computing the inverse 4-th root of the preconditioner matrix. If you naively quantize the preconditioner directly, you slightly alter its smallest singular values. When you take an inverse root, those tiny errors blow up, ruining the optimizer.
Instead, the authors use Singular Value Decomposition (SVD) and quantize only the eigenvector matrix to 4 bits, leaving the singular values alone.
- Orthogonal Rectification: An eigenvector matrix is naturally orthogonal (its vectors are at right angles to each other). Quantizing it to 4 bits ruins this orthogonality. To fix this, the authors apply Björck orthonormalization—a lightweight, iterative mathematical process—to "rectify" the matrix and restore its orthogonality after it is dequantized.
- Linear Square Quantization: The authors tested different ways to map real numbers to 4-bit bins. They found that a "Linear-2" (linear square) quantization mapping slightly outperformed the popular Dynamic Tree (DT) quantization for these specific matrix states.
Datasets
The authors evaluated 4-bit Shampoo across both computer vision and natural language processing tasks:
- Vision: CIFAR-100, Tiny-ImageNet, and ImageNet-1k.
- Language: OpenWebText (OWT) and the C4 dataset.
Key Insights and Ideas
- Small singular values are the Achilles' heel of quantization: The "aha" moment of the paper is the realization that direct quantization fails because of the inverse root operation. By isolating the singular values from the quantization process, the math remains stable.
- Orthogonality is fragile but easily repaired: You can't just quantize an orthogonal matrix and expect it to behave. However, applying just a single iteration of Björck orthonormalization is enough to pull the matrix back into a usable state, making the inverse root computation fast and accurate.
- The technique generalizes: While the paper focuses on Shampoo, the authors proved their eigenvector-quantization trick also works for other second-order optimizers like K-FAC, AdaBK, and CASPR.
Key Results
- Lossless Performance: 4-bit Shampoo matches the test accuracy of 32-bit Shampoo almost perfectly (differences ranged from a mere -0.7% to +0.5% across all tasks).
- Massive Memory Savings: It reduces total GPU memory consumption by 4.5% to 41% compared to 32-bit Shampoo.
- Competitive with AdamW: Compared to standard first-order optimizers (like AdamW), 4-bit Shampoo only increases memory usage by a tiny margin (0.8% to 12.7%) but delivers the much faster convergence typical of second-order methods.
- Unlocking LLM Scaling: When training a LLAMA2-7B model on a single 80GB A800 GPU, standard 32-bit Shampoo ran out of memory at a tiny batch size of 2. 4-bit Shampoo comfortably trained the 7B model with a batch size of 64.
Limitations and Future Work
- The Symmetry Trade-off: Standard preconditioner matrices are symmetric, meaning you only need to store half of the matrix in memory. Eigenvector matrices are not symmetric. Therefore, storing a 4-bit eigenvector matrix takes the same amount of memory as storing an 8-bit symmetric preconditioner. (However, the authors note that the 4-bit eigenvector approach still yields much lower mathematical error than an 8-bit preconditioner).
- Compute Constraints: Due to limited academic compute resources, the authors could not test 4-bit Shampoo on massive, state-of-the-art frontier models (e.g., models with tens or hundreds of billions of parameters), though their 7B parameter tests are highly promising.
Summary updated