Dive into Deep Learning · §35.5
Adaptive Methods
AdaGrad · RMSProp · Adam & bias correction · scale invariance · rotation sensitivity · AdamW · warmup · K-FAC & Muon
Motivation
Modern neural networks have 10^7 to 10^{11} parameters whose curvatures differ by orders of magnitude across layers and coordinates. On f(\mathbf{x}) = \tfrac12(x_1^2 + 1000\,x_2^2) from (1, 1) to f(\mathbf{x}) < 10^{-8}:
Per-Coordinate Scaling
On a diagonal bowl f(\mathbf{x}) = \tfrac12\sum_i h_i x_i^2, each coordinate updates via x_{t+1,i} = (1 - \eta_i h_i)x_{t,i}:
AdaGrad
AdaGrad accumulates the sum of squared gradients \mathbf{s}_t elementwise and divides each step by \sqrt{s_{t,i}}:
\mathbf{s}_t = \mathbf{s}_{t-1} + \mathbf{g}_t \odot \mathbf{g}_t, \qquad \mathbf{x}_{t+1} = \mathbf{x}_t - \frac{\eta}{\sqrt{\mathbf{s}_t} + \epsilon}\,\mathbf{g}_t
AdaGrad
AdaGrad was designed for online convex optimization, minimizing cumulative regret \sum_{t=1}^T f_t(\mathbf{x}_t) - \min_{\mathbf{x}} \sum_{t=1}^T f_t(\mathbf{x}):
RMSProp
RMSProp replaces AdaGrad’s all-time sum with an exponential moving average (EMA) of squared gradients:
\mathbf{v}_t = \beta_2\,\mathbf{v}_{t-1} + (1 - \beta_2)\,\mathbf{g}_t^2, \qquad \mathbf{x}_{t+1} = \mathbf{x}_t - \frac{\eta}{\sqrt{\mathbf{v}_t} + \epsilon}\,\mathbf{g}_t
Adam
Adam pairs RMSProp’s second-moment EMA \mathbf{v}_t with a first-moment momentum EMA \mathbf{m}_t, correcting both for zero initialization:
\hat{\mathbf{m}}_t = \frac{\mathbf{m}_t}{1 - \beta_1^t}, \quad \hat{\mathbf{v}}_t = \frac{\mathbf{v}_t}{1 - \beta_2^t}, \quad \mathbf{x}_{t+1} = \mathbf{x}_t - \eta\,\frac{\hat{\mathbf{m}}_t}{\sqrt{\hat{\mathbf{v}}_t} + \epsilon}
Adam
If the squared gradient scale is stationary (\mathbb{E}[\mathbf{g}_\tau^2] = \overline{\mathbf{g}^2}), summing the geometric series gives:
\mathbb{E}[\mathbf{v}_t] = (1 - \beta_2)\,\overline{\mathbf{g}^2}\sum_{\tau=1}^t \beta_2^{t-\tau} = \big(1 - \beta_2^t\big)\,\overline{\mathbf{g}^2}
Scale Invariance
When \epsilon = 0 and \nabla\tilde{f}(\mathbf{x}) = \mathrm{diag}(c_1, \ldots, c_d)\nabla f(\mathbf{x}) (c_i > 0), linearity of the EMAs gives \tilde{m}_{t,i} = c_i m_{t,i} and \tilde{v}_{t,i} = c_i^2 v_{t,i}:
\frac{\hat{\tilde{m}}_{t,i}}{\sqrt{\hat{\tilde{v}}_{t,i}}} = \frac{c_i\,\hat{m}_{t,i}}{\sqrt{c_i^2\,\hat{v}_{t,i}}} = \frac{\hat{m}_{t,i}}{\sqrt{\hat{v}_{t,i}}}
Scale Invariance
Applying the scale-invariance theorem to f(\mathbf{x}) = \tfrac12\sum_{i=1}^d h_i x_i^2 explains both Adam’s strength on aligned valleys and its structural boundaries:
Rotation Sensitivity
We compare optimally tuned GD and Heavy Ball (given the exact eigenvalues \mu = 1, L = 1000) against a 7-point learning-rate sweep for Adam (\beta_1 = 0 scaling-only vs. \beta_1 = 0.9) on the aligned valley and the valley rotated by \theta = 45^\circ:
steps to f < 1e-8 aligned rotated 45
GD, eta = 2/(mu + L) 6160 6160
heavy ball, tuned 296 296
Adam, eta = 0.002 0.0063 0.02 0.063 0.2 0.63 2
beta1 = 0.0, aligned 2122 760 249 78 22 never never
beta1 = 0.0, rotated 45 never never never never never never never
beta1 = 0.9, aligned 2033 648 195 165 205 170 196
beta1 = 0.9, rotated 45 12862 9292 5898 3171 1581 799 559
Rotation Sensitivity
Rotation Sensitivity
On the aligned valley (\beta_1 = 0, \eta = 0.1, \epsilon = 0), Adam discovers the 1000{:}1 curvature ratio on step 1 from gradient magnitudes alone:
t = 1: x = 0.9, 0.9; eta/sqrt(v_hat) = 0.1, 0.0001
t = 10: x = 0.262, 0.262; eta/sqrt(v_hat) = 0.152, 0.000152
t = 48: x = 3.91e-06, 3.91e-06; eta/sqrt(v_hat) = 0.329, 0.000329
largest |x_1 - x_2| over the run: 5.6e-17
steps to f < 1e-8 at curvature ratios 1, 1e3, 1e5: 40 48 54
steps from (100, 100) at ratio 1e3: 4145
Convergence Limits
On x \in [-1, 1], consider the 3-periodic convex losses (+4x, -x, -x) with average slope +2 and unique optimum x^\star = -1:
Convergence Limits
AMSGrad repairs the Reddi counterexample by replacing \mathbf{v}_t in the denominator with its running maximum \tilde{\mathbf{v}}_t = \max(\tilde{\mathbf{v}}_{t-1}, \mathbf{v}_t), guaranteeing nonincreasing effective steps \eta_t / \sqrt{\tilde{\mathbf{v}}_t}:
x_t at t = 30 300 3000 15000 (x* = -1)
adam 0.745 1.000 1.000 1.000
amsgrad -0.953 -0.985 -0.995 -0.998
sgd -0.954 -0.986 -0.995 -0.998
Decoupled Weight Decay
In plain SGD, adding an \ell_2 penalty \tfrac{\lambda}{2}\|\mathbf{w}\|^2 to the loss (\mathbf{g}_t \leftarrow \mathbf{g}_t + \lambda\mathbf{w}_t) is identical to multiplying weights by (1 - \eta\lambda) at every step. In Adam, passing \lambda\mathbf{w}_t through the preconditioner \sqrt{\hat{\mathbf{v}}_t} couples decay to gradient scale:
\text{Coupled ($\ell_2$ inside Adam):}\quad \Delta w_{t,i}^{\mathrm{decay}} = -\frac{\eta\lambda}{\sqrt{\hat{v}_{t,i}} + \epsilon}\,w_{t,i} \qquad \text{vs.} \qquad \text{Decoupled (AdamW):}\quad \Delta w_{t,i}^{\mathrm{decay}} = -\eta\lambda\,w_{t,i}
Decoupled Weight Decay
Simulate two groups of 10^4 weights initialized at w_0 = 1 receiving pure zero-mean Gaussian gradient noise at scales \sigma_1 = 10 and \sigma_2 = 0.1 over T = 4{,}000 steps (\eta = 10^{-3}, \lambda = 0.1):
per-step decay rates: coupled [1.e-05 1.e-03] AdamW 0.0001
mean w, coupled: [0.961 0.027] predictions exp(-eta lam T / sigma): [0.961 0.018]
mean w, AdamW: [0.67 0.67] prediction (1 - eta lam)^T: 0.67
Decoupled Weight Decay
When exact gradients settle (\hat{\mathbf{m}}_t \to \mathbf{u}, \hat{\mathbf{v}}_t \to \mathbf{u}^2), coupled Adam and AdamW converge to distinct stationary points:
\lambda\,w_i\big(|g_i| + \epsilon\big) = -g_i \implies |w_i| = \frac{|g_i|}{\lambda(|g_i| + \epsilon)} < \frac{1}{\lambda}
Warmup Dynamics
At step t = 1, bias correction gives \hat{\mathbf{m}}_1 = \mathbf{g}_1 and \hat{\mathbf{v}}_1 = \mathbf{g}_1^2, so Adam’s very first update is a full sign step in every coordinate:
\mathbf{x}_2 = \mathbf{x}_1 - \eta\,\frac{\mathbf{g}_1}{|\mathbf{g}_1| + \epsilon} \approx \mathbf{x}_1 - \eta\,\mathrm{sign}(\mathbf{g}_1)
Warmup Dynamics
Tracking the RMS update (in units of \eta) across 20{,}000 independent noise coordinates separates the role of the momentum window, bias correction, and linear warmup:
t: 1 2 3 10 20 30 100 1000 3000
Adam: 1.00 0.71 0.58 0.33 0.26 0.24 0.23 0.23 0.23
exact variance: 1.00 0.71 0.58 0.33 0.26 0.24 0.23 0.23 0.23
no bias correction: 3.16 3.02 2.87 2.17 1.61 1.32 0.74 0.29 0.24
warmup over 20 steps: 0.05 0.07 0.09 0.17 0.26 0.24 0.23 0.23 0.23
Warmup Dynamics
Structured Preconditioners
To handle rotated valleys where curvature mixes coordinates without paying O(d^2) storage for a full d \times d preconditioner, structured methods exploit the matrix shape of neural network layers:
Structured Preconditioners
For a single 4096 \times 4096 Transformer weight matrix (d = mn \approx 1.68 \times 10^7 parameters), compare a full (mn) \times (mn) curvature matrix against two 4096 \times 4096 Kronecker factors:
stored entries: full 2.8e+14, two factors 3.4e+07
flops to invert: full 4.7e+21, two factors 1.4e+11
Structured Preconditioners
Modern matrix optimizers apply two-sided preconditioning \mathbf{G} \mapsto \mathbf{P}_{\mathrm{l}}^{-a}\mathbf{G}\mathbf{P}_{\mathrm{r}}^{-a} to an m \times n gradient/momentum matrix \mathbf{G} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top:
\big(\mathbf{G}\mathbf{G}^\top\big)^{-1/4}\,\mathbf{G}\,\big(\mathbf{G}^\top\mathbf{G}\big)^{-1/4} = \mathbf{U}\mathbf{V}^\top
Concept Check
Test your understanding of adaptive and matrix-preconditioned optimizers:
Answers: (1) At t = 1, \hat{m}_{1,i}/\sqrt{\hat{v}_{1,i}} = \mathrm{sign}(g_{1,i}), so the step size is \eta \frac{10^{-6}}{10^{-6} + 10^{-8}} \approx \mathbf{0.99\,\eta}. The half-life for \beta_2 = 0.999 is \frac{\log 2}{1 - 0.999} \approx \mathbf{693\text{ steps}}. (2) Coupled Adam solves (w - 3) + \lambda w = 0 \implies w^\star = \frac{3}{1+1} = \mathbf{1.5}. AdamW clips the unconstrained minimizer w = 3 to the \ell_\infty box |w| \le 1/\lambda = 1, resting at w^\star = \mathbf{1.0}. (3) A 45^\circ rotation mixes coordinates so both axes see the steep mode (\hat{v}_1 \approx \hat{v}_2), reducing Adam’s diagonal preconditioner to a scalar identity. By contrast, under orthogonal rotations \mathbf{Q}_1\mathbf{G}\mathbf{Q}_2^\top = (\mathbf{Q}_1\mathbf{U})\boldsymbol{\Sigma}(\mathbf{Q}_2\mathbf{V})^\top, the polar factor maps to \mathbf{Q}_1(\mathbf{U}\mathbf{V}^\top)\mathbf{Q}_2^\top, rotating cleanly with the basis.
Key Takeaways
| Optimizer | Preconditioner / Update Form | Invariance Property | Memory Overhead | Primary Strength & Limitation |
|---|---|---|---|---|
| AdaGrad | \mathbf{s}_t = \sum_{\tau \le t}\mathbf{g}_\tau^2, step \propto \mathbf{s}_t^{-1/2}\mathbf{g}_t | Diagonal coordinate scale | 1 vector (d) | Optimal sparse convex regret; 1/\sqrt{t} decay stalls on deep nets |
| RMSProp | \mathbf{v}_t = \beta_2\mathbf{v}_{t-1} + (1-\beta_2)\mathbf{g}_t^2 | Diagonal coordinate scale | 1 vector (d) | Non-vanishing steps; noisy without momentum smoothing |
| Adam / AMSGrad | Bias-corrected \hat{\mathbf{m}}_t / (\sqrt{\hat{\mathbf{v}}_t} + \epsilon) | Exact diagonal scale (\epsilon=0) | 2 vectors (2d) | Fast & robust on axis-aligned valleys; fails under 45^\circ rotation |
| AdamW | Decoupled (1-\eta\lambda)\mathbf{w}_t - \eta\hat{\mathbf{m}}_t/\sqrt{\hat{\mathbf{v}}_t} | Uniform decay across scales | 2 vectors (2d) | Default for Transformers; fixed points lie in \ell_\infty box \|\mathbf{w}\|_\infty \le 1/\lambda |
| K-FAC / Shampoo | Two-sided \mathbf{P}_{\mathrm{l}}^{-a}\mathbf{G}\mathbf{P}_{\mathrm{r}}^{-a} (m \times n layer) | Layer row/column transforms | m^2 + n^2 per layer | Captures cross-coordinate correlations; periodic matrix roots/inverses |
| Muon | Orthogonal polar factor \mathbf{U}\mathbf{V}^\top of \mathbf{M}_t | Orthogonal row/col rotations | 1 matrix (mn) | Equalizes singular values via fast Newton–Schulz matmuls |