Simple Algorithm
Deep Learning · Emergence · 30 min

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 2.8×10142.8\times10^{14} 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 θ←θ−ηP−1g\boldsymbol\theta\leftarrow\boldsymbol\theta-\eta P^{-1}\mathbf g, which curvature matrices PP approximates, and why no diagonal PP can fix ill-conditioning along rotated directions.
  • Derive K-FAC's Kronecker factorization of a layer's Fisher block and its update G−1(∇WL)A−1G^{-1}(\nabla_W\loss)A^{-1}, with damping.
  • Derive Shampoo's update L−1/4GR−1/4L^{-1/4}GR^{-1/4} 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 θ←θ−ηP−1∇L\boldsymbol\theta\leftarrow\boldsymbol\theta-\eta P^{-1}\nabla\loss for a positive definite PP. It is plain gradient descent in the coordinates ϕ=P1/2θ\boldsymbol\phi=P^{1/2}\boldsymbol\theta, where the Hessian becomes P−1/2HP−1/2P^{-1/2}HP^{-1/2}. With P=HP=H the transformed Hessian is the identity, every direction has the same curvature, and one step of size η=1\eta=1 solves a quadratic: Newton's method.

Deep-learning preconditioners approximate one of three curvature matrices. The Hessian HH is indefinite away from minima. The Gauss–Newton matrix J⊤HoutJJ^\top H_{\text{out}}J, with JJ the Jacobian of the network's outputs and HoutH_{\text{out}} the Hessian of the loss in those outputs, drops the second-derivative terms of the network and is positive semidefinite. The Fisher matrix F=E[∇log⁡p ∇log⁡p⊤]F=\E[\nabla\log p\,\nabla\log p^\top], 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 FF is the natural gradient (Amari, 1998).

DerivationA rotated valley defeats every diagonal preconditioner
  1. H=(50.549.549.550.5)H=\begin{pmatrix}50.5&49.5\\49.5&50.5\end{pmatrix}

    Take the quadratic with curvatures 100100 and 11, rotated by 45°45°: H=R diag⁡(100,1) R⊤H=R\,\diag(100,1)\,R^\top with RR the rotation by 45°45°. Its condition number is 100100, and its two diagonal entries are equal:

  2. diag⁡(H)−1/2H diag⁡(H)−1/2=H50.5⟹κ=1001=100\diag(H)^{-1/2}H\,\diag(H)^{-1/2}=\frac{H}{50.5}\quad\Longrightarrow\quad\kappa=\frac{100}{1}=100

    Jacobi scaling, P=diag⁡(H)P=\diag(H), multiplies HH by 1/50.51/50.5, which leaves the condition number at 100100. No diagonal preconditioner does better. For P=diag⁡(d1,d2)P=\diag(d_1,d_2) the preconditioned matrix has trace 50.5 (d1+d2)/(d1d2)50.5\,(d_1+d_2)/(d_1d_2) and determinant 100/(d1d2)100/(d_1d_2), so (1+κ)2/κ=Tr⁡2/det⁡=50.52(d1+d2)2/(100 d1d2)(1+\kappa)^2/\kappa=\Tr^2/\det=50.5^2(d_1+d_2)^2/(100\,d_1d_2), smallest at d1=d2d_1=d_2, where κ=100\kappa=100.

  3. P=H⟹P−1/2HP−1/2=I,κ=1P=H\quad\Longrightarrow\quad P^{-1/2}HP^{-1/2}=I,\qquad\kappa=1

    A non-diagonal PP can rotate. With P=HP=H, 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.

Predict before you look

For the rotated valley above, after Jacobi preconditioning by the diagonal of HH, what is the condition number of the preconditioned problem?

Show the answer

100

The diagonal of HH is (50.5,50.5)(50.5,50.5), so the scaling is uniform and the eigenvalues 100100 and 11 are merely divided by 50.550.5: the ratio stays 100100. 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 z=Wa\mathbf z=W\mathbf a with W∈Rnout×ninW\in\R^{n_{\text{out}}\times n_{\text{in}}}, input activations a\mathbf a and backpropagated gradient δ=∂ℓ/∂z\boldsymbol\delta=\partial\ell/\partial\mathbf z, so that ∇Wℓ=δa⊤\nabla_W\ell=\boldsymbol\delta\mathbf a^\top.

DerivationThe K-FAC update
  1. FW=E[(a⊗δ)(a⊗δ)⊤]=E[aa⊤⊗δδ⊤]F_W=\E\big[(\mathbf a\otimes\boldsymbol\delta)(\mathbf a\otimes\boldsymbol\delta)^\top\big]=\E\big[\mathbf a\mathbf a^\top\otimes\boldsymbol\delta\boldsymbol\delta^\top\big]

    Stack the columns of the gradient into a vector. For an outer product, vec⁡(δa⊤)=a⊗δ\operatorname{vec}(\boldsymbol\delta\mathbf a^\top)=\mathbf a\otimes\boldsymbol\delta, and the mixed-product rule gives the layer's Fisher block as an expectation of Kronecker products:

  2. FW≈E[aa⊤]⏟A (nin×nin)⊗E[δδ⊤]⏟G (nout×nout)F_W\approx\underbrace{\E[\mathbf a\mathbf a^\top]}_{A\ (n_{\text{in}}\times n_{\text{in}})}\otimes\underbrace{\E[\boldsymbol\delta\boldsymbol\delta^\top]}_{G\ (n_{\text{out}}\times n_{\text{out}})}

    The approximation: treat activations and backpropagated gradients as independent, so the expectation of the product factors. (δ\boldsymbol\delta 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.)

  3. (A⊗G)−1vec⁡(∇WL)=vec⁡(G−1 ∇WL A−1)⟹W←W−η G−1(∇WL)A−1(A\otimes G)^{-1}\operatorname{vec}(\nabla_W\loss)=\operatorname{vec}\big(G^{-1}\,\nabla_W\loss\,A^{-1}\big)\quad\Longrightarrow\quad W\leftarrow W-\eta\,G^{-1}(\nabla_W\loss)A^{-1}

    A Kronecker product inverts factor by factor, (A⊗G)−1=A−1⊗G−1(A\otimes G)^{-1}=A^{-1}\otimes G^{-1}, and (B⊗C)vec⁡(X)=vec⁡(CXB⊤)(B\otimes C)\operatorname{vec}(X)=\operatorname{vec}(CXB^\top) turns the preconditioned step back into a matrix:

  4. full block: (ninnout)2 entriesversusfactors: nin2+nout2\text{full block: }(n_{\text{in}}n_{\text{out}})^2\ \text{entries}\qquad\text{versus}\qquad\text{factors: }n_{\text{in}}^2+n_{\text{out}}^2

    In practice AA and GG are running averages over mini-batches, damped before inversion, (A+λAI)(A+\lambda_AI) and (G+λGI)(G+\lambda_GI), with the damping adapted during training in Levenberg–Marquardt fashion, and the inverses are refreshed only every so many steps.

For a 4096×40964096\times4096 layer, the exact Fisher block would have 2.8×10142.8\times10^{14} entries, about a petabyte in 32-bit floats, while the two factors have 3.4×1073.4\times10^7, 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 AA and GG) but tracking a separate diagonal of variances in that eigenbasis, an idea that returns in SOAP below.

Check your understanding

For a layer with W∈Rnout×ninW\in\R^{n_{\text{out}}\times n_{\text{in}}}, A=E[aa⊤]A=\E[\mathbf a\mathbf a^\top] and G=E[δδ⊤]G=\E[\boldsymbol\delta\boldsymbol\delta^\top], which expression is K-FAC's preconditioned gradient?

  1. A−1(∇WL) G−1A^{-1}(\nabla_W\loss)\,G^{-1}
  2. (A⊗G)vec⁡(∇WL)(A\otimes G)\operatorname{vec}(\nabla_W\loss)
  3. G−1(∇WL) A−1G^{-1}(\nabla_W\loss)\,A^{-1}
  4. ∇WL\nabla_W\loss divided elementwise by diag⁡(A) diag⁡(G)⊤\sqrt{\diag(A)\,\diag(G)^\top}
Show the answer

C. G−1(∇WL) A−1G^{-1}(\nabla_W\loss)\,A^{-1}

GG is nout×noutn_{\text{out}}\times n_{\text{out}} and acts on the left (the output side), AA is nin×ninn_{\text{in}}\times n_{\text{in}} and acts on the right (the input side). This follows from (A⊗G)−1=A−1⊗G−1(A\otimes G)^{-1}=A^{-1}\otimes G^{-1} and (B⊗C)vec⁡(X)=vec⁡(CXB⊤)(B\otimes C)\operatorname{vec}(X)=\operatorname{vec}(CXB^\top).

Shampoo and SOAP

Full-matrix AdaGrad preconditions with (ϵI+∑sgsgs⊤)1/2\big(\epsilon I+\sum_s\mathbf g_s\mathbf g_s^\top\big)^{1/2}, the square root of the accumulated gradient outer products. It rotates with the problem, but for a layer with mnmn weights it needs an mn×mnmn\times mn matrix. Shampoo (Gupta, Koren & Singer, 2018) keeps one small statistic per side of each weight matrix instead.

DerivationShampoo as a Kronecker-factored full-matrix AdaGrad
  1. Lt=ϵIm+∑s≤tGsGs⊤,Rt=ϵIn+∑s≤tGs⊤Gs,W←W−η Lt−1/4 Gt Rt−1/4L_t=\epsilon I_m+\sum_{s\le t}G_sG_s^\top,\qquad R_t=\epsilon I_n+\sum_{s\le t}G_s^\top G_s,\qquad W\leftarrow W-\eta\,L_t^{-1/4}\,G_t\,R_t^{-1/4}

    For W∈Rm×nW\in\R^{m\times n} with gradients GtG_t, accumulate a left and a right statistic and precondition on both sides:

  2. 1r∑sgsgs⊤⪯Lt1/2⊗Rt1/2⟹1r(∑sgsgs⊤)1/2⪯Lt1/4⊗Rt1/4\frac1r\sum_s\mathbf g_s\mathbf g_s^\top\preceq L_t^{1/2}\otimes R_t^{1/2}\quad\Longrightarrow\quad\frac{1}{\sqrt r}\Big(\sum_s\mathbf g_s\mathbf g_s^\top\Big)^{1/2}\preceq L_t^{1/4}\otimes R_t^{1/4}

    Why quarter powers? If every gradient has rank at most rr, Gupta et al.'s Lemma 8 bounds the full-matrix statistic of the vectorized gradients gs\mathbf g_s (the rows of GsG_s 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 (L1/2⊗R1/2)1/2=L1/4⊗R1/4(L^{1/2}\otimes R^{1/2})^{1/2}=L^{1/4}\otimes R^{1/4}:

  3. GG⊤=∥a∥2 δδ⊤,G⊤G=∥δ∥2 aa⊤GG^\top=\norm{\mathbf a}^2\,\boldsymbol\delta\boldsymbol\delta^\top,\qquad G^\top G=\norm{\boldsymbol\delta}^2\,\mathbf a\mathbf a^\top

    So Shampoo's preconditioner dominates full-matrix AdaGrad's, up to r\sqrt r, using an m×mm\times m and an n×nn\times n matrix; the quarter powers also give the O(1/t)\order{1/\sqrt t} step decay typical of AdaGrad. (An order-kk tensor gets one statistic per mode with exponent −1/(2k)-1/(2k).) For a single example, G=δa⊤G=\boldsymbol\delta\mathbf a^\top, 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 12\frac12 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 L=QLΛLQL⊤L=Q_L\Lambda_LQ_L^\top and R=QRΛRQR⊤R=Q_R\Lambda_RQ_R^\top, rotate each gradient into the eigenbasis, take an Adam step there, and rotate back:

G~=QL⊤G QR,U~=AdamStep⁡(G~),W←W−η QLU~ QR⊤\tilde G=Q_L^\top G\,Q_R,\qquad\tilde U=\operatorname{AdamStep}(\tilde G),\qquad W\leftarrow W-\eta\,Q_L\tilde U\,Q_R^\top
The eigenbases are refreshed only every so many steps, while Adam's moments keep updating every step in the current basis; that is what keeps infrequent eigendecompositions from hurting. The only new hyperparameter is the refresh frequency. In large-batch language-model pretraining at about 360 million and 660 million parameters, SOAP needed over 40% fewer iterations and over 35% less wall-clock time than AdamW, and about 20% less of each than Shampoo. The idea of a diagonal correction in a Kronecker eigenbasis goes back to George et al. (2018).
Check your understanding

What does SOAP change relative to Shampoo?

  1. It replaces the Kronecker factors by a diagonal, as in Adam
  2. It runs Adam on the gradient expressed in the eigenbasis of Shampoo's factors LL and RR, refreshing the eigenbasis periodically
  3. It inverts LL and RR exactly at every step instead of taking fourth roots
  4. 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 LL and RR, refreshing the eigenbasis periodically

SOAP keeps Shampoo's rotations (QLQ_L, QRQ_R) 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

MethodExtra state for an m×nm\times n layerExpensive operation
Adam2mn2mnnone
K-FACm2+n2m^2+n^2 factors and their inversestwo damped inverses, O(m3+n3)\order{m^3+n^3}, refreshed every few to hundreds of steps
Shampoom2+n2m^2+n^2 statistics and their rootsinverse fourth roots, by eigendecomposition or coupled Newton iterations, O(m3+n3)\order{m^3+n^3}
SOAPm2+n2m^2+n^2 plus Adam's 2mn2mn in the rotated basisperiodic eigendecompositions, O(m3+n3)\order{m^3+n^3}
An eigendecomposition of a 4096×40964096\times4096 factor takes of order 40963≈7×10104096^3\approx7\times10^{10} operations times a modest constant: small next to a large-batch training step, but sequential, hard to parallelize and numerically delicate, so it is done in 32-bit or 64-bit precision and only every few dozen steps.

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 PP is gradient descent after the change of variables ϕ=P1/2θ\boldsymbol\phi=P^{1/2}\boldsymbol\theta. Deep-learning preconditioners approximate the Hessian, Gauss–Newton or Fisher matrix, and a diagonal PP, such as Adam's, cannot fix ill-conditioning along rotated directions.
  • K-FAC approximates each layer's Fisher block by A⊗GA\otimes G, from input activations and backpropagated gradients, assuming they are independent; the update G−1(∇WL)A−1G^{-1}(\nabla_W\loss)A^{-1} needs only an nin×ninn_{\text{in}}\times n_{\text{in}} and an nout×noutn_{\text{out}}\times n_{\text{out}} inverse, damped and refreshed periodically.
  • Shampoo updates W←W−ηL−1/4GR−1/4W\leftarrow W-\eta L^{-1/4}GR^{-1/4} with L=∑GG⊤L=\sum GG^\top and R=∑G⊤GR=\sum G^\top G; since 1r∑gg⊤⪯L1/2⊗R1/2\frac1r\sum\mathbf g\mathbf g^\top\preceq L^{1/2}\otimes R^{1/2}, 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.

Question 1

Why can Adam not fix the ill-conditioning of a quadratic whose sharp and flat directions are rotated 45°45° from the coordinate axes?

  1. Because Adam's bias correction is wrong for quadratics
  2. 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
  3. Because Adam uses momentum, which amplifies the sharp direction
  4. 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 PP rescales axes but cannot rotate them, and for this valley the best diagonal PP is a multiple of the identity, which leaves the condition number at 100100. A Kronecker or full preconditioner can align with the rotated eigenvectors.

Question 2

Why does Shampoo raise each of its two statistics to the power −14-\frac14 for a matrix parameter?

  1. Because L1/4⊗R1/4=(L1/2⊗R1/2)1/2L^{1/4}\otimes R^{1/4}=(L^{1/2}\otimes R^{1/2})^{1/2}, and L1/2⊗R1/2L^{1/2}\otimes R^{1/2} bounds the full-matrix statistic, so the product mimics full-matrix AdaGrad's square root
  2. Because the fourth root is cheaper to compute than the inverse
  3. Because Newton's method requires the inverse fourth root of the Hessian
  4. Because each statistic is a fourth power of the gradient
Show the answer

A. Because L1/4⊗R1/4=(L1/2⊗R1/2)1/2L^{1/4}\otimes R^{1/4}=(L^{1/2}\otimes R^{1/2})^{1/2}, and L1/2⊗R1/2L^{1/2}\otimes R^{1/2} bounds the full-matrix statistic, so the product mimics full-matrix AdaGrad's square root

Full-matrix AdaGrad uses the square root of ∑gg⊤\sum\mathbf g\mathbf g^\top. Lemma 8 bounds that sum (divided by the rank rr) by L1/2⊗R1/2L^{1/2}\otimes R^{1/2}; splitting the remaining square root between the two sides gives a quarter power each.

Question 3

Compared with Adam, what is the main extra cost of Shampoo for an m×nm\times n layer?

  1. An extra backward pass at every step
  2. Storing the full mn×mnmn\times mn curvature matrix
  3. Statistics of size m2+n2m^2+n^2 and periodic inverse roots costing O(m3+n3)\order{m^3+n^3}, amortized by refreshing every few dozen steps and blocking large dimensions
  4. Nothing: Shampoo's per-step cost is identical to Adam's
Show the answer

C. Statistics of size m2+n2m^2+n^2 and periodic inverse roots costing O(m3+n3)\order{m^3+n^3}, amortized by refreshing every few dozen steps and blocking large dimensions

The gradient computation is unchanged; the extra work is maintaining LL and RR 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).