Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Optimization for ML

Natural Gradient, K-FAC and Shampoo

Gradient descent depends on how you write down your model: change the parameterization and the steps change. The natural gradient fixes this by measuring step size in the space of probability distributions (KL divergence), preconditioning by the Fisher information matrix. For neural networks the Fisher is far too big to invert, so K-FAC approximates it per layer as a Kronecker product, and Shampoo uses two-sided matrix-root preconditioners. You will derive the Fisher metric, verify reparameterization invariance, and solve a matrix regression in one K-FAC step.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Step sizes in the right units

Suppose you’re tuning a model’s “temperature”. You could write it in kelvin or in log-kelvin. A plain gradient step behaves completely differently in the two, though the model is the same. That’s like walking a fixed number of map-centimetres regardless of the map’s scale.

The natural gradient measures each step by how much it changes the model’s predictions, not by how much the numbers change. It takes the same sensible step whatever coordinates you chose.

Same model, different coordinates: the natural gradient
mean μ →std σ
■ GD in (μ, σ): 139 steps■ GD in (μ, log σ): 121 steps■ natural gradient: 83 steps
Plain gradient descent depends on how you parameterize the model. In (μ, σ) the gradient for μ is divided by σ², so a wide initial σ makes the mean crawl, and a narrow one makes steps explode. Switching to log σ changes the path completely. The natural gradient preconditions by the Fisher information (1/σ² for μ, 2 for log σ), measuring steps in "distribution space" (KL divergence) rather than parameter space. Its path is the same in any parameterization (to first order) and needs no hand-tuned scaling.
Why engineers care

Natural-gradient ideas underlie TRPO and PPO in reinforcement learning (trust regions in distribution space), variational inference, and second-order optimizers like K-FAC and Shampoo that train large networks in fewer steps. Shampoo-style preconditioning has won recent optimizer benchmarks for large models.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Plain gradient descent depends on…
  2. 2. The natural gradient measures steps by…
  3. 3. The matrix that defines this distance is the…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The Fisher information matrix

For a model pθ(y∣x)p_\theta(y\mid x):

F(θ)=E[∇θlog⁡pθ(y∣x) ∇θlog⁡pθ(y∣x)⊤]F(\theta) = \mathbb E\big[\nabla_\theta\log p_\theta(y\mid x)\,\nabla_\theta\log p_\theta(y\mid x)^\top\big]

It’s the local curvature of the KL divergence: KL⁡(pθ ∥ pθ+δ)≈12δ⊤Fδ\operatorname{KL}(p_\theta\,\|\,p_{\theta + \delta})\approx\frac12\delta^\top F\delta.

Examples:

  • Bernoulli(pp): F=1/(p(1−p))F = 1/(p(1 - p)) in pp, and p(1−p)p(1 - p) in the logit.
  • N(μ,σ2)\mathcal N(\mu, \sigma^2): F=diag⁡(1/σ2,2/σ2)F = \operatorname{diag}(1/\sigma^2, 2/\sigma^2) in (μ,σ)(\mu, \sigma).

Natural gradient descent (Amari, 1998)

θk+1=θk−η F(θk)−1∇θL(θk)\theta_{k+1} = \theta_k - \eta\,F(\theta_k)^{-1}\nabla_\theta L(\theta_k)

It’s the steepest-descent direction when distance is measured by KL rather than Euclidean length. For exponential families with η = 1, it jumps straight to the maximum-likelihood estimate.

📝 Quick check (Level 1)
0/3 answered
  1. 1. KL(p_θ ‖ p_θ+δ) ≈
  2. 2. Fisher information of Bernoulli(p) in p is…
  3. 3. The natural gradient update uses…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Relation to Newton and Gauss–Newton

For log-likelihood losses with well-specified models, the Fisher equals the expected Hessian of the negative log-likelihood, and it’s always PSD. For Gaussian outputs, natural gradient = Gauss–Newton (A6.1-4). The “empirical Fisher” (squared per-sample gradients, as in Adam’s vv) is a cruder proxy that can behave differently (Kunstner, Hennig and Balles, 2019).

K-FAC (Martens and Grosse, 2015)

For a layer s=Was = Wa, the Fisher block is E[(aa⊤)⊗(gg⊤)]\mathbb E[(aa^\top)\otimes(gg^\top)], where g=∂log⁡p/∂sg = \partial\log p/\partial s. K-FAC approximates it by A⊗GA\otimes G with A=E[aa⊤]A = \mathbb E[aa^\top] and G=E[gg⊤]G = \mathbb E[gg^\top]. Then

(A⊗G)−1vec⁡(∇W)=vec⁡(G−1∇WA−1)(A\otimes G)^{-1}\operatorname{vec}(\nabla_W) = \operatorname{vec}(G^{-1}\nabla_WA^{-1})

Two small inverses (din2+dout2d_{\text{in}}^2 + d_{\text{out}}^2 numbers) replace one of size (dindout)2(d_{\text{in}}d_{\text{out}})^2.

Shampoo (Gupta, Koren and Singer, 2018)

Accumulate L=∑GtGt⊤L = \sum G_tG_t^\top and R=∑Gt⊤GtR = \sum G_t^\top G_t for each weight matrix and update with L−1/4GtR−1/4L^{-1/4}G_tR^{-1/4}. It’s a full-matrix AdaGrad that is affordable per layer. Distributed Shampoo has won the AlgoPerf training-speed benchmark (Dahl et al., 2023). SOAP and Muon (A6.4-6) are close relatives.

🐍 Exercise 1: reparameterization invariance
Take one gradient step on a Bernoulli likelihood in the probability and logit parameterizations, with and without Fisher preconditioning. Show that the natural step with η = 1 hits the MLE and that small natural steps agree across parameterizations while vanilla steps don't.
📝 Quick check (Level 2)
0/3 answered
  1. 1. K-FAC approximates a layer's Fisher block as…
  2. 2. For Gaussian outputs, the natural gradient equals…
  3. 3. Shampoo preconditions the gradient G by…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Fisher information of the Bernoulli

log⁡p(y)=ylog⁡p+(1−y)log⁡(1−p)\log p(y) = y\log p + (1 - y)\log(1 - p), so the score is yp−1−y1−p\frac yp - \frac{1 - y}{1 - p}. Its variance is p⋅1p2+(1−p)1(1−p)2=1p(1−p)p\cdot\frac1{p^2} + (1 - p)\frac1{(1 - p)^2} = \frac1{p(1 - p)}. In the logit θ\theta, the score is y−py - p with variance p(1−p)p(1 - p). ∎

Invariance to reparameterization (first order)

Let θ=h(ϕ)\theta = h(\phi) with Jacobian JJ. Then ∇ϕL=J⊤∇θL\nabla_\phi L = J^\top\nabla_\theta L and Fϕ=J⊤FθJF_\phi = J^\top F_\theta J. The natural step in ϕ\phi is Δϕ=−η(J⊤FθJ)−1J⊤∇θL=−ηJ−1Fθ−1∇θL\Delta\phi = -\eta(J^\top F_\theta J)^{-1}J^\top\nabla_\theta L = -\eta J^{-1}F_\theta^{-1}\nabla_\theta L. It maps to Δθ≈JΔϕ=−ηFθ−1∇θL\Delta\theta\approx J\Delta\phi = -\eta F_\theta^{-1}\nabla_\theta L, the natural step in θ\theta. ∎ Plain gradient steps transform with JJ⊤JJ^\top and are not invariant.

The Kronecker identity

(A⊗G)vec⁡(V)=vec⁡(GVA⊤)(A\otimes G)\operatorname{vec}(V) = \operatorname{vec}(GVA^\top). For symmetric invertible A,GA, G, the inverse is therefore vec⁡(G−1VA−1)\operatorname{vec}(G^{-1}VA^{-1}). ∎

Exercise 3.1: KL of a small mean shift

For N(μ,1)→N(μ+0.1,1)\mathcal N(\mu, 1)\to\mathcal N(\mu + 0.1, 1): 12⋅0.12⋅1=0.005\frac12\cdot0.1^2\cdot1 = 0.005. This is exact for a Gaussian mean shift.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Under θ = h(φ), the Fisher transforms as…
  2. 2. Bernoulli Fisher in the logit parameterization is…
  3. 3. (A ⊗ G) vec(V) =

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

One K-FAC step vs two thousand GD steps

A linear layer maps 12 sensor inputs (scales spanning 1.5 decades) to 4 outputs, with Gaussian noise. Its Fisher is exactly A⊗IA\otimes I, so the K-FAC step ∇WA−1\nabla_WA^{-1} is the exact natural gradient, and Newton’s step. One step solves the least-squares problem to the damping level. GD with step 1/L1/L still has a 5% weight error after 2000 steps, because the low-variance inputs barely move. Shampoo, with no model knowledge, also converges, using 160 preconditioner numbers instead of the full Fisher’s 2304.

🐍 Exercise 2 (research): K-FAC and Shampoo for matrix regression
Fit a multi-output linear layer with GD, K-FAC and Shampoo. Compare relative weight error after a given number of steps, and preconditioner memory.

Natural-gradient ideas in AI, robotics and aerospace

  • Policy optimization: natural policy gradient (Kakade, 2001), TRPO’s KL trust region (Schulman et al., 2015) and PPO’s clipped surrogate are standard for robot learning.
  • Variational inference: natural-gradient VI and Bayesian deep learning (Khan and Nielsen, 2018; Osawa et al., 2019).
  • Large-model training: K-FAC (Martens and Grosse, 2015), Shampoo (Gupta, Koren and Singer, 2018; Anil et al., 2020) and SOAP (Vyas et al., 2024).
  • Estimation theory: the Fisher metric is the Cramér–Rao bound’s matrix (A5.1-4), connecting optimization to sensor-fusion precision.

References

  1. S. Amari (1998). “Natural gradient works efficiently in learning.” Neural Computation, 10(2).
  2. J. Martens (2020). “New insights and perspectives on the natural gradient method.” JMLR, 21.
  3. J. Martens, R. Grosse (2015). “Optimizing neural networks with Kronecker-factored approximate curvature.” ICML.
  4. V. Gupta, T. Koren, Y. Singer (2018). “Shampoo: preconditioned stochastic tensor optimization.” ICML.
  5. R. Anil et al. (2020). “Scalable second order optimization for deep learning.” arXiv:2002.09018.
  6. G. Dahl et al. (2023). “Benchmarking neural network training algorithms.” arXiv:2306.07179 (AlgoPerf).
  7. F. Kunstner, P. Hennig, L. Balles (2019). “Limitations of the empirical Fisher approximation for natural gradient descent.” NeurIPS.
  8. S. Kakade (2001). “A natural policy gradient.” NeurIPS.
  9. J. Schulman et al. (2015). “Trust region policy optimization.” ICML.
  10. N. Vyas et al. (2024). “SOAP: improving and stabilizing Shampoo using Adam.” arXiv:2409.11321.