Curvature-Aware Optimizers: K-FAC & Shampoo
Kronecker-factored preconditioners that make second-order ideas scale.
Adam rescales each coordinate but never rotates them, so it is helpless against curvature that runs along diagonal directions. A true second-order method would fix that, but the curvature matrix of a single 4096 × 4096 layer has entries. K-FAC and Shampoo find a middle way: approximate each layer's curvature by a Kronecker product of two small matrices, which can be inverted, or raised to a fractional power, cheaply. A descendant of Shampoo won the external-tuning track of the AlgoPerf training-algorithms competition.
What you’ll learn
- Explain preconditioned descent , which curvature matrices approximates, and why no diagonal can fix ill-conditioning along rotated directions.
- Derive K-FAC's Kronecker factorization of a layer's Fisher block and its update , with damping.
- Derive Shampoo's update and its relation to full-matrix AdaGrad, and explain SOAP as Adam run in Shampoo's eigenbasis.
- Count the costs (matrix roots, refresh frequency, memory) and summarize the benchmark evidence as of the mid-2020s.
What a diagonal preconditioner cannot do
A preconditioned method takes the step for a positive definite . It is plain gradient descent in the coordinates , where the Hessian becomes . With the transformed Hessian is the identity, every direction has the same curvature, and one step of size solves a quadratic: Newton's method.
Deep-learning preconditioners approximate one of three curvature matrices. The Hessian is indefinite away from minima. The Gauss–Newton matrix , with the Jacobian of the network's outputs and the Hessian of the loss in those outputs, drops the second-derivative terms of the network and is positive semidefinite. The Fisher matrix , with labels drawn from the model's own predictive distribution, coincides with the Gauss–Newton matrix for the usual losses, squared error and softmax cross-entropy. Preconditioning by is the natural gradient (Amari, 1998).
Take the quadratic with curvatures and , rotated by : with the rotation by . Its condition number is , and its two diagonal entries are equal:
Jacobi scaling, , multiplies by , which leaves the condition number at . No diagonal preconditioner does better. For the preconditioned matrix has trace and determinant , so , smallest at , where .
A non-diagonal can rotate. With , or any good approximation of it, the transformed problem is perfectly conditioned. The question is how to get rotations for a billion parameters without forming a billion-by-billion matrix.
For the rotated valley above, after Jacobi preconditioning by the diagonal of , what is the condition number of the preconditioned problem?
Show the answer
100
The diagonal of is , so the scaling is uniform and the eigenvalues and are merely divided by : the ratio stays . Axis-aligned methods such as Adam help only when the ill-conditioning is aligned with the coordinates, which is why the rotation test in Why Adam Beats SGD on Transformers is informative.
K-FAC: Kronecker-factored curvature
Martens & Grosse (2015) approximate the Fisher matrix by a block-diagonal matrix with one block per layer, and each block by a Kronecker product. Take a fully connected layer with , input activations and backpropagated gradient , so that .
Stack the columns of the gradient into a vector. For an outer product, , and the mixed-product rule gives the layer's Fisher block as an expectation of Kronecker products:
The approximation: treat activations and backpropagated gradients as independent, so the expectation of the product factors. ( is computed with labels sampled from the model, as the Fisher requires; using the training labels gives the "empirical Fisher", a different and often worse matrix.)
A Kronecker product inverts factor by factor, , and turns the preconditioned step back into a matrix:
In practice and are running averages over mini-batches, damped before inversion, and , with the damping adapted during training in Levenberg–Marquardt fashion, and the inverses are refreshed only every so many steps.
For a layer, the exact Fisher block would have entries, about a petabyte in 32-bit floats, while the two factors have , about 134 MB. Martens & Grosse report that the updates cost only several times as much as a plain stochastic gradient, and that storing and inverting the approximation does not depend on the amount of data used to estimate it. George, Laurent, Bouthillier, Ballas & Vincent (2018) improved on it by keeping K-FAC's eigenvectors (those of and ) but tracking a separate diagonal of variances in that eigenbasis, an idea that returns in SOAP below.
For a layer with , and , which expression is K-FAC's preconditioned gradient?
- divided elementwise by
Show the answer
C.
is and acts on the left (the output side), is and acts on the right (the input side). This follows from and .
Shampoo and SOAP
Full-matrix AdaGrad preconditions with , the square root of the accumulated gradient outer products. It rotates with the problem, but for a layer with weights it needs an matrix. Shampoo (Gupta, Koren & Singer, 2018) keeps one small statistic per side of each weight matrix instead.
For with gradients , accumulate a left and a right statistic and precondition on both sides:
Why quarter powers? If every gradient has rank at most , Gupta et al.'s Lemma 8 bounds the full-matrix statistic of the vectorized gradients (the rows of stacked; with the column stacking used for K-FAC above, the two factors trade places) by a Kronecker product. Square roots preserve the ordering of positive semidefinite matrices, and :
So Shampoo's preconditioner dominates full-matrix AdaGrad's, up to , using an and an matrix; the quarter powers also give the step decay typical of AdaGrad. (An order- tensor gets one statistic per mode with exponent .) For a single example, , the statistics are K-FAC's factors in disguise, weighted by norms; K-FAC inverts them like Newton, Shampoo takes inverse fourth roots like AdaGrad:
SOAP. Vyas, Morwani, Zhao, Kwun, Shapira, Brandfonbrener, Janson & Kakade (2025) showed that Shampoo with the power is equivalent to running Adafactor, a memory-saving relative of Adam, in the eigenbasis of Shampoo's preconditioner. Their optimizer, SOAP, runs full Adam in that basis instead. Diagonalize and , rotate each gradient into the eigenbasis, take an Adam step there, and rotate back:
What does SOAP change relative to Shampoo?
- It replaces the Kronecker factors by a diagonal, as in Adam
- It runs Adam on the gradient expressed in the eigenbasis of Shampoo's factors and , refreshing the eigenbasis periodically
- It inverts and exactly at every step instead of taking fourth roots
- It removes the second-moment statistics and keeps only momentum
Show the answer
B. It runs Adam on the gradient expressed in the eigenbasis of Shampoo's factors and , refreshing the eigenbasis periodically
SOAP keeps Shampoo's rotations (, ) and replaces the fixed fourth-root scaling by Adam's adaptive per-coordinate scaling in the rotated coordinates. That combines the rotation a diagonal method lacks with Adam's well-tuned behavior.
Costs and evidence
| Method | Extra state for an layer | Expensive operation |
|---|---|---|
| Adam | none | |
| K-FAC | factors and their inverses | two damped inverses, , refreshed every few to hundreds of steps |
| Shampoo | statistics and their roots | inverse fourth roots, by eigendecomposition or coupled Newton iterations, |
| SOAP | plus Adam's in the rotated basis | periodic eigendecompositions, |
What it takes in practice. The PyTorch implementation of distributed Shampoo by Shi et al. (2023) shows the engineering involved. Inverse roots come from symmetric eigendecompositions in 32-bit precision, retried in 64-bit if they fail, with the last good root reused otherwise. Roots are recomputed only every precondition_frequency steps (every 50 steps worked for ImageNet). Large dimensions are cut into blocks, with block sizes of 1024 to 8192 working well. Learning-rate grafting rescales each layer's Shampoo direction to the norm of another optimizer's step, such as SGD, AdaGrad or Adam, so existing learning-rate schedules carry over. With all this, the per-step wall-clock overhead was at most 10% over diagonal methods, and on ResNet-50 for ImageNet, 60 epochs of Shampoo matched 90 epochs of SGD with Nesterov momentum, a 1.35-fold wall-clock gain. Anil, Gupta, Koren, Regan & Singer (2020) earlier scaled Shampoo by computing preconditioners on the host CPUs alongside the accelerators.
Benchmarks. AlgoPerf measures time to reach a target on a fixed set of workloads and fixed hardware, with separate rulesets for externally tuned and self-tuning algorithms (Dahl et al., 2023). In its first competition, the external-tuning ruleset was won by a submission based on Distributed Shampoo, which beat Adam-style baselines even in wall-clock time, while the self-tuning ruleset was won by Schedule-Free AdamW (Kasimbeg et al., 2025; see Schedules Without a Horizon).
Key takeaways
- Preconditioning by is gradient descent after the change of variables . Deep-learning preconditioners approximate the Hessian, Gauss–Newton or Fisher matrix, and a diagonal , such as Adam's, cannot fix ill-conditioning along rotated directions.
- K-FAC approximates each layer's Fisher block by , from input activations and backpropagated gradients, assuming they are independent; the update needs only an and an inverse, damped and refreshed periodically.
- Shampoo updates with and ; since , it is a Kronecker-factored full-matrix AdaGrad. SOAP runs Adam in Shampoo's eigenbasis.
- Practical Kronecker methods need eigendecompositions in high precision, refreshed every few dozen steps, blocking and grafting. Distributed Shampoo won AlgoPerf's external-tuning ruleset, but AdamW remains the default for large language models as of the mid-2020s.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why can Adam not fix the ill-conditioning of a quadratic whose sharp and flat directions are rotated from the coordinate axes?
- Because Adam's bias correction is wrong for quadratics
- Because its preconditioner is diagonal: it can rescale the two axes but not rotate them, and no rescaling of the axes lowers this valley's condition number
- Because Adam uses momentum, which amplifies the sharp direction
- It can: Adam's per-coordinate step sizes adapt to any curvature
Show the answer
B. Because its preconditioner is diagonal: it can rescale the two axes but not rotate them, and no rescaling of the axes lowers this valley's condition number
A diagonal rescales axes but cannot rotate them, and for this valley the best diagonal is a multiple of the identity, which leaves the condition number at . A Kronecker or full preconditioner can align with the rotated eigenvectors.
Why does Shampoo raise each of its two statistics to the power for a matrix parameter?
- Because , and bounds the full-matrix statistic, so the product mimics full-matrix AdaGrad's square root
- Because the fourth root is cheaper to compute than the inverse
- Because Newton's method requires the inverse fourth root of the Hessian
- Because each statistic is a fourth power of the gradient
Show the answer
A. Because , and bounds the full-matrix statistic, so the product mimics full-matrix AdaGrad's square root
Full-matrix AdaGrad uses the square root of . Lemma 8 bounds that sum (divided by the rank ) by ; splitting the remaining square root between the two sides gives a quarter power each.
Compared with Adam, what is the main extra cost of Shampoo for an layer?
- An extra backward pass at every step
- Storing the full curvature matrix
- Statistics of size and periodic inverse roots costing , amortized by refreshing every few dozen steps and blocking large dimensions
- Nothing: Shampoo's per-step cost is identical to Adam's
Show the answer
C. Statistics of size and periodic inverse roots costing , amortized by refreshing every few dozen steps and blocking large dimensions
The gradient computation is unchanged; the extra work is maintaining and and computing their roots. Refreshing roots every few dozen steps, blocking dimensions above a few thousand and grafting keep the measured overhead to about 10% per step.
Further reading
- J. Martens & R. Grosse, "Optimizing neural networks with Kronecker-factored approximate curvature," ICML (2015).
- V. Gupta, T. Koren & Y. Singer, "Shampoo: Preconditioned stochastic tensor optimization," ICML (2018).
- H.-J. M. Shi, T.-H. Lee, S. Iwasaki, J. Gallego-Posada, Z. Li, K. Rangadurai, D. Mudigere & M. Rabbat, "A distributed data-parallel PyTorch implementation of the distributed Shampoo optimizer for training neural networks at-scale," arXiv:2309.06497 (2023).
- N. Vyas, D. Morwani, R. Zhao, M. Kwun, I. Shapira, D. Brandfonbrener, L. Janson & S. Kakade, "SOAP: Improving and stabilizing Shampoo using Adam for language modeling," ICLR (2025).
- P. Kasimbeg et al., "Accelerating neural network training: An analysis of the AlgoPerf competition," ICLR (2025).