Simple Algorithm
Machine Learning · Convergence · 28 min

Training Dynamics & the Edge of Stability

Large learning rates, sharpness and catapults.

Classical optimization theory says: keep the learning rate below 2/L2/L, where LL bounds the curvature, and every step will lower the loss. Neural networks are routinely trained at learning rates that break this rule, and they train well. This lesson derives the stability threshold, then follows what happens beyond it: progressive sharpening and the edge of stability, the self-stabilizing mechanism behind them, and the catapult in which the loss spikes and the curvature collapses. It ends with what warmup, batch size and large learning rates do through curvature, and what that may mean for generalization.

What you’ll learn

  • Derive the stability thresholds η<2/λmax⁡\eta<2/\lambda_{\max} for gradient descent and η<2(1+β)/λmax⁡\eta<2(1+\beta)/\lambda_{\max} for heavy-ball momentum, and explain why gradient descent can only settle stably at minima with sharpness at most 2/η2/\eta.
  • Describe progressive sharpening and the edge of stability, and derive the self-stabilization mechanism from a cubic Taylor expansion.
  • Solve the catapult dynamics of a wide two-layer linear model exactly, and identify its lazy, catapult and divergent phases.
  • Explain how warmup, batch size and large initial learning rates act through curvature, and separate what is established about generalization from what is debated.

Stability on a quadratic

DerivationWhen does gradient descent converge on a quadratic?
  1. θt+1−θ⋆=(I−ηH)(θt−θ⋆)⟹et+1,i=(1−ηλi) et,i\boldsymbol\theta_{t+1}-\boldsymbol\theta^\star=(I-\eta H)(\boldsymbol\theta_t-\boldsymbol\theta^\star)\quad\Longrightarrow\quad e_{t+1,i}=(1-\eta\lambda_i)\,e_{t,i}

    Let f(θ)=12(θ−θ⋆)⊤H(θ−θ⋆)f(\boldsymbol\theta)=\tfrac12(\boldsymbol\theta-\boldsymbol\theta^\star)^\top H(\boldsymbol\theta-\boldsymbol\theta^\star) with H=∑iλiuiui⊤⪰0H=\sum_i\lambda_i\mathbf u_i\mathbf u_i^\top\succeq0. A gradient step multiplies the error by I−ηHI-\eta H, so in the eigenbasis each coordinate evolves on its own:

  2. gradient descent converges  ⟺  0<η<2λmax⁡(H)\text{gradient descent converges}\iff0<\eta<\frac2{\lambda_{\max}(H)}

    Every coordinate with λi>0\lambda_i>0 shrinks if and only if ∣1−ηλi∣<1\abs{1-\eta\lambda_i}<1. For 1/λi<η<2/λi1/\lambda_i<\eta<2/\lambda_i it flips sign at every step while shrinking; above 2/λi2/\lambda_i it grows geometrically along ui\mathbf u_i. The largest eigenvalue decides:

  3. 0<ηλ<2(1+β)⟹η<2(1+β)λmax⁡(=3.8/λmax⁡ for β=0.9)0<\eta\lambda<2(1+\beta)\qquad\Longrightarrow\qquad\eta<\frac{2(1+\beta)}{\lambda_{\max}}\quad(=3.8/\lambda_{\max}\text{ for }\beta=0.9)

    Heavy-ball momentum, v←βv+∇f\mathbf v\leftarrow\beta\mathbf v+\nabla f, θ←θ−ηv\boldsymbol\theta\leftarrow\boldsymbol\theta-\eta\mathbf v, gives et+1=(1+β−ηλ)et−βet−1e_{t+1}=(1+\beta-\eta\lambda)e_t-\beta e_{t-1} per coordinate, with characteristic polynomial r2−(1+β−ηλ)r+βr^2-(1+\beta-\eta\lambda)r+\beta. Both roots lie inside the unit circle exactly when (for 0≤β<10\le\beta<1)

  4. θ⋆ a stable limit of gradient descent with step η ⟹ S(θ⋆)≤2η\boldsymbol\theta^\star\ \text{a stable limit of gradient descent with step }\eta\ \Longrightarrow\ S(\boldsymbol\theta^\star)\le\frac2\eta

    Near a minimum of a non-quadratic loss, linearize: a minimum is linearly stable for gradient descent with step η\eta only if its sharpness S=λmax⁡(∇2f)S=\lambda_{\max}(\nabla^2f) is at most 2/η2/\eta. So gradient descent cannot converge to a minimum sharper than 2/η2/\eta, except from exceptional starting points (the minimum itself, for one): the learning rate selects among minima. With mini-batches the condition also involves how much the per-example curvatures vary, so stochastic gradient descent is selective in a different way (Wu, Ma & E, 2018).

Progressive sharpening and the edge of stability

The classical guarantees (Convergence Rates of Gradient Descent) assume η<2/L\eta<2/L for the curvature bound LL of the whole path, which makes the loss decrease monotonically. Cohen, Kaur, Li, Kolter & Talwalkar (2021) measured what full-batch gradient descent actually does on standard networks (fully connected, convolutional and Transformer models, with squared or cross-entropy loss), and found two regularities:

  • Progressive sharpening. The sharpness S(θt)S(\boldsymbol\theta_t) rises steadily during training, until it reaches 2/η2/\eta (with cross-entropy loss it often drops again near the end of training).
  • The edge of stability. It then stops rising, and instead of diverging, gradient descent keeps the sharpness hovering just above 2/η2/\eta for the rest of training. The loss goes up and down over short timescales, yet keeps decreasing over long ones. Lower η\eta mid-run and the sharpness climbs to the new 2/η2/\eta.

So for neural networks, the step size is not chosen to fit the curvature; the curvature adapts to the step size. The analog for adaptive methods holds for a preconditioned sharpness: for Adam with β1=0.9\beta_1=0.9 it equilibrates near 38/η38/\eta, the stability threshold of the method (Cohen et al., 2022), though unlike gradient descent, Adam can keep advancing into higher-curvature regions while its preconditioner adapts.

Think first Where does Adam's threshold 38/η38/\eta come from? (Adam's momentum is an exponential average, m←β1m+(1−β1)g\mathbf m\leftarrow\beta_1\mathbf m+(1-\beta_1)\mathbf g.)

An exponential average is heavy-ball momentum with the step rescaled: θ←θ−ηm\boldsymbol\theta\leftarrow\boldsymbol\theta-\eta\mathbf m is the heavy ball with effective step η(1−β1)\eta(1-\beta_1). The heavy-ball condition η(1−β1)λ<2(1+β1)\eta(1-\beta_1)\lambda<2(1+\beta_1) gives λ<2(1+β1)(1−β1)η=3.80.1 η=38η\lambda<\frac{2(1+\beta_1)}{(1-\beta_1)\eta}=\frac{3.8}{0.1\,\eta}=\frac{38}\eta, applied to the eigenvalues of the Hessian after preconditioning by Adam's per-coordinate scaling (treated as fixed, and ignoring the bias correction, which tends to 1).

Why does gradient descent not simply diverge once S>2/ηS>2/\eta? On a quadratic the curvature is fixed, so nothing can stop the growing oscillation. In a network the curvature depends on θ\boldsymbol\theta, and the oscillation itself moves θ\boldsymbol\theta to places where the curvature is lower.

Self-stabilization

DerivationThe cubic term pushes the sharpness down (Damian, Nichani & Lee, 2023)
  1. S(θt)≈2η+ytS(\boldsymbol\theta_t)\approx\frac2\eta+y_t

    Expand around a reference point θ†\boldsymbol\theta^\dagger where S=2/ηS=2/\eta. Let u\mathbf u be the top Hessian eigenvector and ∇S\nabla S the gradient of the sharpness, and track two numbers: the displacement along the unstable direction, xt=u⊤(θt−θ†)x_t=\mathbf u^\top(\boldsymbol\theta_t-\boldsymbol\theta^\dagger), and the excess sharpness, yt=∇S⊤(θt−θ†)≈S(θt)−2/ηy_t=\nabla S^\top(\boldsymbol\theta_t-\boldsymbol\theta^\dagger)\approx S(\boldsymbol\theta_t)-2/\eta.

  2. xt+1≈−(1+η yt) xtx_{t+1}\approx-\big(1+\eta\,y_t\big)\,x_t

    Along u\mathbf u, a gradient step multiplies xx by 1−ηS=1−η(2/η+y)1-\eta S=1-\eta(2/\eta+y). Above the threshold (y>0y>0) the oscillation grows; below it, it shrinks:

  3. yt+1≈yt+η(α−β2 xt2),α=−∇L⊤∇S,β=∥∇S∥2y_{t+1}\approx y_t+\eta\Big(\alpha-\frac\beta2\,x_t^2\Big),\qquad\alpha=-\nabla\mathcal L^\top\nabla S,\quad\beta=\norm{\nabla S}^2

    The cubic term. A third-order Taylor expansion of the loss L\mathcal L adds 12x2∇3L[u,u]\tfrac12x^2\nabla^3\mathcal L[\mathbf u,\mathbf u] to the gradient, and ∇3L[u,u]=∇S\nabla^3\mathcal L[\mathbf u,\mathbf u]=\nabla S is exactly the gradient of the top eigenvalue. So the oscillation itself produces a step down the sharpness gradient, of size proportional to x2x^2. Meanwhile the rest of the gradient raises the sharpness at the progressive-sharpening rate α\alpha. Assuming, as their sketch does, that ∇S⊥u\nabla S\perp\mathbf u, and with their normalization of β\beta:

  4. x2‾≈2αβ,S‾≈2η\overline{x^2}\approx\frac{2\alpha}\beta,\qquad\overline{S}\approx\frac2\eta

    The two equations form a negative feedback loop. Sharpness above 2/η2/\eta makes the oscillation grow; a large oscillation drives the sharpness below 2/η2/\eta; then the oscillation decays and progressive sharpening resumes. Over a cycle the sharpness hovers at 2/η2/\eta, and the drift of yy cancels when the average x2x^2 equals 2α/β2\alpha/\beta: the oscillation is exactly as large as needed to cancel progressive sharpening. Damian, Nichani & Lee prove that, under their assumptions, gradient descent at the edge of stability stays close to projected gradient descent on the set {S(θ)≤2/η}\{S(\boldsymbol\theta)\le2/\eta\}: an implicit bias toward stable, flatter regions.

A related line of work proves edge-of-stability behavior in simplified settings. Arora, Li & Panigrahi (2022) showed that normalized gradient descent, and gradient descent on L−min⁡L\sqrt{\mathcal L-\min\mathcal L}, provably enter the edge of stability and then move along the manifold of minimizers by a deterministic flow that decreases the sharpness. In both pictures the instability is not noise to be tolerated: it is a mechanism that steers training toward flatter regions.

Check your understanding

In the self-stabilization picture, what brings the sharpness back down after it overshoots 2/η2/\eta?

  1. The oscillation that builds up along the top eigenvector: through the loss's cubic term it adds 12x2∇S\tfrac12x^2\nabla S to the gradient, so each step moves the parameters by −12ηx2∇S-\tfrac12\eta x^2\nabla S, lowering the sharpness
  2. The noise of stochastic gradients
  3. An automatic reduction of the learning rate
  4. Weight decay shrinking the weights
Show the answer

A. The oscillation that builds up along the top eigenvector: through the loss's cubic term it adds 12x2∇S\tfrac12x^2\nabla S to the gradient, so each step moves the parameters by −12ηx2∇S-\tfrac12\eta x^2\nabla S, lowering the sharpness

The analysis is for full-batch gradient descent with a fixed step and no regularization. The oscillation xx is caused by the instability itself, and its square, through ∇3L[u,u]=∇S\nabla^3\mathcal L[\mathbf u,\mathbf u]=\nabla S, pushes the parameters down the sharpness gradient until S<2/ηS<2/\eta again.

Catapults: the large-learning-rate phase

Lewkowycz, Bahri, Dyer, Sohl-Dickstein & Gur-Ari (2020) found a model in which large-learning-rate training can be solved exactly: a two-layer linear network of width mm, f=1mv⊤uf=\tfrac1{\sqrt m}\mathbf v^\top\mathbf u, fitting one example with input 1 and target 0 under L=12f2\mathcal L=\tfrac12f^2. Its neural tangent kernel is the scalar λ=(∥u∥2+∥v∥2)/m\lambda=(\norm{\mathbf u}^2+\norm{\mathbf v}^2)/m, which plays the role of the curvature.

DerivationTwo exact update equations
  1. ft+1=1m(v−ηfmu) ⁣⊤(u−ηfmv)=ft(1−ηλt+η2ft2m)f_{t+1}=\frac1{\sqrt m}\Big(\mathbf v-\tfrac{\eta f}{\sqrt m}\mathbf u\Big)^{\!\top}\Big(\mathbf u-\tfrac{\eta f}{\sqrt m}\mathbf v\Big)=f_t\Big(1-\eta\lambda_t+\frac{\eta^2f_t^2}m\Big)

    Gradient descent updates u←u−ηfv/m\mathbf u\leftarrow\mathbf u-\eta f\mathbf v/\sqrt m and v←v−ηfu/m\mathbf v\leftarrow\mathbf v-\eta f\mathbf u/\sqrt m. Multiply out v⊤u\mathbf v^\top\mathbf u after the step:

  2. λt+1=λt+ηft2m(ηλt−4)\lambda_{t+1}=\lambda_t+\frac{\eta f_t^2}m\big(\eta\lambda_t-4\big)

    Expand ∥u∥2+∥v∥2\norm{\mathbf u}^2+\norm{\mathbf v}^2 after the step in the same way; the cross terms contribute −4ηf2/m-4\eta f^2/m and the squared terms η2f2λ/m\eta^2f^2\lambda/m:

  3. η<2λ0: lazy,2λ0<η<4λ0: catapult,η>4λ0: divergence\eta<\frac2{\lambda_0}:\ \text{lazy},\qquad\frac2{\lambda_0}<\eta<\frac4{\lambda_0}:\ \text{catapult},\qquad\eta>\frac4{\lambda_0}:\ \text{divergence}

    For large mm and f0=O(1)f_0=\order1, read off three phases. Lazy (η<2/λ0\eta<2/\lambda_0): ∣1−ηλ∣<1\abs{1-\eta\lambda}<1, f→0f\to0 and λ\lambda moves only by O(1/m)\order{1/m}, the NTK regime. Catapult (2/λ0<η<4/λ02/\lambda_0<\eta<4/\lambda_0): ∣f∣\abs{f} grows exponentially until f2f^2 is of order mm; then the second equation, with ηλ−4<0\eta\lambda-4<0, drives λ\lambda down until ηλ<2\eta\lambda<2, and ff converges: the loss spikes, the curvature collapses, and training ends somewhere flatter. Divergent (η>4/λ0\eta>4/\lambda_0): ηλ−4>0\eta\lambda-4>0, so a growing ff raises λ\lambda, which makes ff grow faster.

Predict before you look

In this model with λ0=2\lambda_0=2 and a large width, what is the largest learning rate at which training still converges?

Show the answer

2

4/λ0=24/\lambda_0=2. Between 11 (=2/λ0=2/\lambda_0) and 22, training catapults: in a simulation with m=1000m=1000 and λ0≈2.03\lambda_0\approx2.03, a step of 1.51.5 drove the loss from about 0.90.9 up to about 160160 before it fell to zero, and the curvature ended near 0.120.12, far below 2/η≈1.332/\eta\approx1.33. A step of 2.052.05 diverged. The peak loss is of order mm, so wider models spike higher.

Lewkowycz et al. found the same three regimes in realistic deep networks, with a narrow band of large but stable learning rates beyond the lazy phase, and the best test performance often inside that band. The catapult and the edge of stability can be read as two faces of one fact: gradient descent at a large step size reduces curvature until the step is stable.

Warmup, batch size and large learning rates

Warmup. Many models start training in regions of high curvature, where the learning rate that works well later would be unstable. A warmup raises η\eta gradually over the first steps (Goyal et al., 2017, used a linear warmup to train ImageNet models with very large batches). Gilmer et al. (2022) studied the Hessian across many tasks and found that successful choices of initialization, architecture and heuristics let the early trajectory avoid or escape high-curvature regions into flatter ones that tolerate larger steps; in their experiments warmup improved stability as much as batch normalization, layer normalization or Fixup. In the language of this lesson, warmup gives self-stabilization time to lower the sharpness before 2/η2/\eta gets small.

Batch size. With mini-batches the stability condition tightens: each step uses a noisy Hessian, and the fluctuations add to the effective curvature. The smaller the batch, the smaller the largest stable step.

Large learning rates and generalization. Since gradient descent can only settle where the sharpness is at most 2/η2/\eta, a large learning rate restricts training to flatter regions; Jastrzębski et al. (2020) found that the early learning rate shapes the rest of the trajectory: a large one reduces the variance of the gradient and improves the conditioning of its covariance, while a small one leaves the loss surface badly conditioned. Whether that helps generalization is a separate question.

Li, Wei & Ma (2019) constructed a two-layer setting where it provably does, and traced the effect to the order in which patterns are learned: a small learning rate first memorizes patterns that are easy to generalize but hard to fit, and then generalizes worse on patterns that are hard to generalize but easy to fit, while a large initial rate picks up the hard-to-fit patterns only after it is annealed. In CIFAR-10 experiments, a small patch added to the images was memorized at once by the small-learning-rate model but ignored by the large-learning-rate model until annealing, and it hurt the small-learning-rate model's accuracy on unmodified images. But flatness is not invariant under reparameterization, and no general theorem links sharpness to test error; the evidence is weighed in Why Big Networks Generalize.

Key takeaways

  • On a quadratic, gradient descent converges iff η<2/λmax⁡\eta<2/\lambda_{\max}, and heavy-ball momentum iff η<2(1+β)/λmax⁡\eta<2(1+\beta)/\lambda_{\max}. Near a minimum this becomes a selection rule: gradient descent can only settle where the sharpness is at most 2/η2/\eta.
  • Full-batch training of networks shows progressive sharpening up to 2/η2/\eta and then the edge of stability, where the sharpness stays near 2/η2/\eta while the loss keeps falling, non-monotonically. Adam's analog equilibrates near 38/η38/\eta for a preconditioned sharpness.
  • Self-stabilization: growing oscillations along the top eigenvector, through the loss's cubic term, push the sharpness back below 2/η2/\eta; in effect, gradient descent tracks projected gradient descent on {S≤2/η}\{S\le2/\eta\}.
  • In the two-layer linear model, ft+1=ft(1−ηλt+η2ft2/m)f_{t+1}=f_t(1-\eta\lambda_t+\eta^2f_t^2/m) and λt+1=λt+ηft2(ηλt−4)/m\lambda_{t+1}=\lambda_t+\eta f_t^2(\eta\lambda_t-4)/m give lazy (η<2/λ0\eta<2/\lambda_0), catapult (2/λ0<η<4/λ02/\lambda_0<\eta<4/\lambda_0) and divergent phases.
  • Warmup lets curvature fall before large steps; smaller batches lower the stable step size; large initial learning rates reach flatter regions, and in some settings provably generalize better, but the link from flatness to generalization is not settled.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Gradient descent runs on a quadratic whose Hessian has largest eigenvalue 50. For which step sizes does it converge?

  1. η<0.02\eta<0.02
  2. η<0.04\eta<0.04
  3. η<0.1\eta<0.1
  4. Any η\eta, since the function is convex
Show the answer

B. η<0.04\eta<0.04

Convergence needs ∣1−50η∣<1\abs{1-50\eta}<1, i.e. η<2/50=0.04\eta<2/50=0.04. Between 0.020.02 and 0.040.04 the top coordinate overshoots and flips sign each step but still shrinks.

Question 2

Heavy-ball momentum (v←βv+∇f\mathbf v\leftarrow\beta\mathbf v+\nabla f, θ←θ−ηv\boldsymbol\theta\leftarrow\boldsymbol\theta-\eta\mathbf v) with β=0.9\beta=0.9 runs on the same quadratic, λmax⁡=50\lambda_{\max}=50. What is its stability limit?

  1. η<0.04\eta<0.04, the same as gradient descent
  2. η<0.004\eta<0.004
  3. η<0.076\eta<0.076
  4. η<0.4\eta<0.4
Show the answer

C. η<0.076\eta<0.076

The characteristic roots lie inside the unit circle iff ηλ<2(1+β)=3.8\eta\lambda<2(1+\beta)=3.8, so η<3.8/50=0.076\eta<3.8/50=0.076. Momentum tolerates larger steps, at the price of slower, oscillating convergence near the limit.

Question 3

A network trained at a step size of η=0.02\eta=0.02 sits at the edge of stability, its sharpness near 2/η=1002/\eta=100. You cut the step to η=0.01\eta=0.01 and keep training with full batches. What did Cohen et al. (2021) observe in this experiment?

  1. The sharpness falls to about 50, to stay at the edge of stability
  2. The sharpness stays near 100 for the rest of training, since training is now stable
  3. Training diverges: the oscillation that held the sharpness down is suddenly too weak
  4. The sharpness starts rising again, up to the new threshold 2/η=2002/\eta=200, and hovers there
Show the answer

D. The sharpness starts rising again, up to the new threshold 2/η=2002/\eta=200, and hovers there

Halving η\eta doubles the threshold to 2/η=2002/\eta=200. Gradient descent is stable again, so progressive sharpening resumes, and the sharpness climbs until it meets the new threshold (or training ends). At the edge of stability gradient descent acts like constrained optimization: the step size caps the sharpness, and the cap moves with η\eta.

Question 4

In the two-layer linear model of Lewkowycz et al., with λ0=2\lambda_0=2, you train with η=1.5\eta=1.5. What happens?

  1. The loss decreases monotonically and λ\lambda stays near 2, as in the NTK regime
  2. The loss diverges, because η>2/λ0\eta>2/\lambda_0
  3. The loss first grows, then λ\lambda drops below 2/η≈1.332/\eta\approx1.33 and the loss converges to zero
  4. Nothing: the parameters do not move
Show the answer

C. The loss first grows, then λ\lambda drops below 2/η≈1.332/\eta\approx1.33 and the loss converges to zero

ηλ0=3\eta\lambda_0=3 lies between 2 and 4: the catapult phase. ∣1−ηλ∣=2\abs{1-\eta\lambda}=2 makes ff grow until f2∼mf^2\sim m, the update λ+=ηf2(ηλ−4)/m\lambda\mathrel{+}=\eta f^2(\eta\lambda-4)/m then lowers λ\lambda until ηλ<2\eta\lambda<2, and training converges in a flatter region.

Further reading

  • J. M. Cohen, S. Kaur, Y. Li, J. Z. Kolter & A. Talwalkar, "Gradient descent on neural networks typically occurs at the edge of stability," International Conference on Learning Representations (ICLR) (2021).
  • A. Damian, E. Nichani & J. D. Lee, "Self-stabilization: the implicit bias of gradient descent at the edge of stability," ICLR (2023).
  • A. Lewkowycz, Y. Bahri, E. Dyer, J. Sohl-Dickstein & G. Gur-Ari, "The large learning rate phase of deep learning: the catapult mechanism," arXiv:2003.02218 (2020).
  • Y. Li, C. Wei & T. Ma, "Towards explaining the regularization effect of initial large learning rate in training neural networks," Advances in Neural Information Processing Systems 32 (2019).
  • J. Gilmer, B. Ghorbani, A. Garg, S. Kudugunta, B. Neyshabur, D. Cardoze, G. E. Dahl, Z. Nado & O. Firat, "A loss curvature perspective on training instabilities of deep learning models," International Conference on Learning Representations (ICLR) (2022).