Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Preconditioning rows and columns
Adam gives each weight its own step size, but it treats weights as independent. When the loss depends on combinations of weights, for example because input features are correlated, per-weight step sizes cannot fix the problem. The ideal fix, a full matrix over all pairs of weights, is far too large: a 1000 × 1000 layer has 10¹² pairs. Shampoo keeps one matrix for the layer’s rows (1000 × 1000) and one for its columns, and combines them. That captures most of the correlation at a tiny fraction of the cost.
Second-order-style optimisers can cut the number of training steps substantially, which matters when each step costs a large cluster’s time. Shampoo is the most practical of them for large networks. Its distributed implementation won the external-tuning track of the AlgoPerf training-speed benchmark in 2024.
- 1. Shampoo keeps, for each weight matrix,…
- 2. It captures what Adam cannot:…
- 3. A full preconditioner for a 1000 × 1000 layer has about…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Statistics: for gradient G (m × n), accumulate L ← L + GGᵀ (m × m) and R ← R + GᵀG (n × n).
- Update: W ← W − η L^(−1/4) G R^(−1/4).
- Example: G = [[1, 2], [0, 1]] gives L = [[5, 2], [2, 1]] and R = [[1, 2], [2, 5]].
- Matrix powers: computed by eigendecomposition: M^p = V diag(λᵢ^p) Vᵀ. For diag(16, 81), M^(−1/4) = diag(1/2, 1/3).
- One gradient: if G = USVᵀ, then L^(−1/4) = US^(−1/2)Uᵀ and R^(−1/4) = VS^(−1/2)Vᵀ, so the step is UVᵀ. Shampoo keeps G’s singular directions and sets all singular values to 1.
- Cost: stores m² + n² numbers instead of (mn)²; for 1000 × 1000 that is 2 × 10⁶ versus 10¹².
- 1. L is…
- 2. With one gradient G = USVᵀ, Shampoo's step is…
- 3. diag(16, 81)^(−1/4) is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Shampoo in code
Exercise 1.
- For one gradient with singular values 25.5, 1.88, 0.19 and 0.011, the Shampoo step equalled UVᵀ: every singular value became 1.
- For a history of 8 gradients, r(L^(1/2) ⊗ R^(1/2)) − Σ vec(G)vec(G)ᵀ had smallest eigenvalue 37.2 ≥ 0: the Kronecker statistics upper-bound full-matrix AdaGrad’s (Gupta et al.).
- Rotating every gradient as Q₁GQ₂ with orthogonal Q’s rotated the step the same way. Shampoo does not depend on the coordinate axes.
Practice.
- Recompute the matrix roots only every 10–100 steps: eigendecompositions are the expensive part.
- Use an exponential moving average of L and R rather than a plain sum, and add εI before taking roots.
- Grafting: keep Shampoo’s direction but take the step’s size from Adam’s step for the same layer. This lets Shampoo reuse Adam’s learning-rate schedule.
- Very large or one-dimensional parameters (embeddings, biases) are blocked into pieces or handled by Adam.
# Distributed Shampoo (Meta): github.com/facebookresearch/optimizers- 1. Matrix roots are usually recomputed…
- 2. Grafting takes the step size from…
- 3. Rotating the gradients' rows and columns makes Shampoo's step…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Full-matrix AdaGrad preconditions with H^(−1/2), H = Σ ggᵀ over the flattened gradients. Its regret bound adapts to the geometry of the gradients, but storing H costs (mn)² and inverting it (mn)³.
Kronecker bound (Gupta, Koren and Singer, 2018). If every G has rank at most r, then H ≼ r(L^(1/2) ⊗ R^(1/2)). Shampoo’s preconditioner (L^(1/4) ⊗ R^(1/4)) is therefore, up to a factor, an upper bound on H^(1/2), and the method keeps an AdaGrad-style regret bound. The exponents −1/4 on each side make the combined preconditioner behave like H^(−1/2).
Rotation invariance. If every gradient becomes Q₁GQ₂, then L becomes Q₁LQ₁ᵀ and R becomes Q₂ᵀRQ₂, so the step becomes Q₁(step)Q₂. A diagonal method like Adam has no such property: rotating the problem changes its behaviour.
Connection to Muon. With no accumulation (one gradient), the step is the orthogonal part of G. Muon (E3-19) uses this directly on the momentum.
- 1. The Kronecker bound says H ≼…
- 2. Adam is not invariant to…
- 3. Shampoo's one-gradient step relates to…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Rotated ill-conditioning
History.
- J. Duchi, E. Hazan and Y. Singer (2011) introduced full-matrix and diagonal AdaGrad.
- J. Martens and R. Grosse (2015) introduced K-FAC, a Kronecker-factored natural-gradient method.
- V. Gupta, T. Koren and Y. Singer (2018) introduced Shampoo.
- R. Anil et al. (2020) made it scalable. H.-J. M. Shi et al. (2023) released Distributed Shampoo, which won the AlgoPerf external-tuning track in 2024.
Exercise 2. Matrix least squares f(W) = ½‖(XW − Y)D‖²/n with W of size 20 × 10. X has correlated columns, D weights the outputs, and the Hessian has condition number about 10⁵.
- In the axis-aligned version X’s ill-conditioning is along the coordinate axes.
- In the rotated version the same spectrum is randomly rotated.
- Each method’s learning rate was tuned over a 9-point grid; the table shows the best steps to reach 10⁻⁶ of the starting loss for two seeds.
| conditioning | GD | Adam | Shampoo |
|---|---|---|---|
| axis-aligned | not within 1000 | 124, 123 | 138, 147 |
| rotated | not within 1000 | 227, 217 | 139, 139 |
- Gradient descent at its largest stable rate reached only 10⁻³ of the starting loss in 1000 steps.
- Adam was the fastest when the conditioning was axis-aligned, which suits its per-coordinate scaling, but slowed by 1.8× when the same conditioning was rotated.
- Shampoo took about 140 steps in both cases: its row and column preconditioners do not care how the problem is oriented.
- Lesson: Shampoo’s advantage is in problems with correlated parameters, which deep networks typically have; on axis-aligned problems the cheaper Adam is as good.
Shampoo in AI, robotics and aerospace
- Large-model training: Distributed Shampoo has trained recommendation and language models with fewer steps than Adam.
- Benchmarking training speed: AlgoPerf measures time-to-result across workloads; Shampoo was the strongest submission in the external-tuning track.
- Models with strongly correlated inputs, such as physical sensor channels, are where non-diagonal preconditioning helps most.
References
- V. Gupta, T. Koren, Y. Singer (2018). “Shampoo: preconditioned stochastic tensor optimization.” Proc. ICML.
- R. Anil, V. Gupta, T. Koren, K. Regan, Y. Singer (2020). “Scalable second order optimization for deep learning.” arXiv:2002.09018.
- H.-J. M. Shi, T.-H. Lee, S. Iwasaki, J. Gallego-Posada, Z. Li, K. Rangadurai, D. Mudigere, M. Rabbat (2023). “A distributed data-parallel PyTorch implementation of the distributed Shampoo optimizer.” arXiv:2309.06497.
- J. Duchi, E. Hazan, Y. Singer (2011). “Adaptive subgradient methods for online learning and stochastic optimization.” JMLR 12.