Textbook › Part III Deep Learning: what assumption you add
CHAPTER 4

How Far to Step, and When to Stop — Learning Rates and Optimisation

FREE14 min

Chapters 1 to 3 settled which way to move. Two things are left: how far to step each time (the learning rate) and when to stop.

They look like separate questions. Chapter 1 deferred the first and Chapter 2 the second, both to "Chapter 4". Arriving here, the two turn out to be two grips on the same knob — that is this chapter.

1. The learning rate has a ceiling

The update is

w  ←  w−η ∇L(w)w \;\leftarrow\; w - \eta\, \nabla L(w)
(1)

Watch what happens on the one-dimensional quadratic L(w)=12λw2L(w) = \tfrac{1}{2}\lambda w^2. With ∇L=λw\nabla L = \lambda w, one update is

w  ←  w−ηλw  =  (1−ηλ) ww \;\leftarrow\; w - \eta \lambda w \;=\; (1 - \eta\lambda)\, w

It is simply multiplied by (1−ηλ)(1-\eta\lambda) every time, so after tt steps it is (1−ηλ)tw0(1-\eta\lambda)^t w_0. That heads for zero exactly when ∣1−ηλ∣<1|1-\eta\lambda| < 1, i.e.

0  <  η  <  2λ0 \;<\; \eta \;<\; \frac{2}{\lambda}
(2)

In several dimensions the sharpest direction decides (the largest eigenvalue Lmax⁡L_{\max} of the Hessian). For nothing to diverge, η<2/Lmax⁡\eta < 2/L_{\max}. Cross it and that one direction is amplified until everything breaks.

Measured on f(x,y)=(x2+10y2)/2f(x,y) = (x^2 + 10y^2)/2 from Chapter 0-2. The curvatures are 11 and 1010, so the ceiling is 2/10=0.22/10 = 0.2. Starting from (10,1)(10,1), steps to get within radius 0.01 of the origin:

η\eta steps
0.01 688
0.05 135
0.10 66
0.18 35
0.19 44
0.199 459
0.1999 4603
0.2 never
0.21 diverges

The best value sits well below the ceiling (0.18), and performance collapses as the ceiling nears: 459 steps at 0.1990.199, 4,603 at 0.19990.1999. It becomes useless long before it falls off the cliff.

2. Why one step size cannot suit every direction

The same η\eta multiplies every direction, but curvature differs by direction. A direction with curvature λ\lambda is multiplied by (1−ηλ)(1-\eta\lambda) each step.

  • Raise η\eta and the sharpest direction starts oscillating at ∣1−ηλmax⁡∣|1-\eta\lambda_{\max}|
  • Lower η\eta and the flattest direction barely moves, at 1−ηλmin⁡≈11-\eta\lambda_{\min} \approx 1

The best is where those balance. Solving 1−ηλmin⁡=−(1−ηλmax⁡)1-\eta\lambda_{\min} = -(1-\eta\lambda_{\max}):

η∗  =  2λmin⁡+λmax⁡,giving a contraction of    κ−1κ+1(κ=λmax⁡λmin⁡)\eta^{*} \;=\; \frac{2}{\lambda_{\min} + \lambda_{\max}}, \qquad \text{giving a contraction of} \;\; \frac{\kappa - 1}{\kappa + 1} \quad \left(\kappa = \frac{\lambda_{\max}}{\lambda_{\min}}\right)
(3)

For the example, η∗=2/11=0.1818\eta^{*} = 2/11 = 0.1818. Sweeping, the minimum came out at η∈[0.180, 0.186]\eta \in [0.180,\ 0.186] with 35 steps. Estimating the count from the contraction 9/11=0.8189/11 = 0.818 gives ⌈log⁡(0.01/10.05)/log⁡(0.818)⌉=35\lceil \log(0.01/10.05)/\log(0.818) \rceil = 35 — matching the measurement.

κ\kappa is the condition number. The larger it is, the closer the contraction sits to 1 and the less progress any number of steps makes. What makes learning rates hard is not model size but κ\kappa.

FIG 1A descent path over the contours. Raise the learning rate and oscillation across the valley appears first; raise it further and the path flies out. Add momentum and the crossing cancels, leaving only the motion along the valley floor

3. Momentum — cancelling the back-and-forth

The zigzag is the component that reverses every step. Add the steps up and it cancels.

v  ←  βv+∇L(w),w  ←  w−η vv \;\leftarrow\; \beta v + \nabla L(w), \qquad w \;\leftarrow\; w - \eta\, v
(4)

β\beta says how much of the previous direction to carry. Reversing components cancel; components that keep pointing the same way (down the valley) accumulate.

Measured on the same problem with η=0.05\eta = 0.05 fixed:

β\beta 0 (none) 0.5 0.9 0.95 0.99
steps 135 59 92 160 678

β=0.5\beta = 0.5 turns 135 into 59. But past 0.9 it gets slower: carry too much and it cannot turn where it needs to, so it overshoots. As with the learning rate, more is not better.

4. Adam — a different step size per direction

The condition-number problem came from using one η\eta everywhere, so vary it: divide each coordinate by a running average of its squared gradient.

m←β1m+(1−β1)g,v←β2v+(1−β2)g2,w←w−η m^v^+εm \leftarrow \beta_1 m + (1-\beta_1)g, \quad v \leftarrow \beta_2 v + (1-\beta_2) g^2, \quad w \leftarrow w - \eta\, \frac{\hat m}{\sqrt{\hat v} + \varepsilon}
(5)

(m^,v^\hat m, \hat v correct the bias from starting at zero; the details are in the article.) Coordinates that fire often get a large v^\sqrt{\hat v} and a shortened step; rarely-moving coordinates get a longer one.

It promises no speed, though. On the same problem:

method best setting steps
gradient descent η=0.18\eta = 0.18 35
+ momentum η=0.05, β=0.5\eta=0.05,\ \beta=0.5 59
Adam η=0.3\eta = 0.3 90

Plain gradient descent wins here, because the curvature is known and η∗\eta^{*} can be chosen. Adam's worth is not speed but landing somewhere reasonable without tuning, on problems whose curvature you do not know. In deep models, where gradient magnitudes differ by orders of magnitude between layers, "reasonable without tuning" is what matters.

Compare methods at each one's own best setting. Tuning only one side measures the tuning, not the method. All three rows above were swept.

5. When to stop — the step count is capacity too

Chapter 2 listed early stopping among the remedies for overfitting, on the grounds that "the number of steps is a form of capacity." Here is the measurement.

Same data as Chapter 2 (sin⁡(2πx)+ε\sin(2\pi x) + \varepsilon, σ=0.25\sigma = 0.25, 20 points, degree 15), running gradient descent with no regularisation at all:

steps tt train RMSE test RMSE ∥w∥\lVert w \rVert
10 0.4522 0.4468 1.07
100 0.2350 0.4575 2.67
1,000 0.1583 0.3224 4.45
1,370 0.1546 0.3140 4.74
10,000 0.1512 0.3320 5.38
100,000 0.1442 0.5057 11.06
300,000 0.1392 1.0069 20.76

Training error falls to the end; test error bottoms out at t=1,370t = 1{,}370 and climbs. The U-shape Chapter 2 produced by raising the degree appears here by raising the step count.

The right-hand column says why. ∥w∥\lVert w \rVert grows the longer you run. Limiting the steps was limiting ∥w∥\lVert w \rVert.

Applying L2 (Chapter 2, equation (3)) to the same data and sweeping λ\lambda:

best setting test RMSE ∥w∥\lVert w \rVert
early stopping t=1,370t = 1{,}370 0.3140 4.74
L2 λ=0.0089\lambda = 0.0089 0.3068 4.53

The floors differ by 0.0072 and the ∥w∥\lVert w \rVert values nearly agree. The knobs — a step count and a λ\lambda — have nothing in common, and they are doing the same thing.

FIG 2Left, the same two curves against step count; right, against 1/λ. The bottoms of the two U-shapes land at nearly the same height, with nearly the same ‖w‖. Lower the learning rate and the left minimum slides right — it takes more steps to reach the same place, but the place does not change. The x-axes mean different things, so the panels sit side by side rather than overlaid
This is what Chapter 1 meant by "choosing $\eta$ and treating overfitting are two sides of one question." $\eta$, the step count and $\lambda$ are all different grips on the single knob of how freely the model may move. It is also why "run until the loss is minimal" is not a procedure (Chapter 0-3). The stopping rule is set by generalisation, not by optimisation.

A common misreading: "as long as it doesn't diverge, a bigger learning rate is faster"

Look again at section 1. The ceiling is 0.20.2.

η\eta 0.18 0.19 0.195 0.199 0.1999 0.2
steps 35 44 90 459 4603 never

The cliff is at 0.20.2, but performance starts falling from 0.180.18. 0.19990.1999 does not diverge — it converges perfectly well — and takes 131 times as long as the best.

Equation (3) explains it. Raising η\eta drives the sharpest direction's factor 1−ηλmax⁡1 - \eta\lambda_{\max} toward −1-1 (oscillation), and as η→2/λmax⁡\eta \to 2/\lambda_{\max} the contraction approaches 1: it stops shrinking. The best is where oscillation and sluggishness balance, at η∗=2/(λmin⁡+λmax⁡)\eta^{*} = 2/(\lambda_{\min}+\lambda_{\max}) — not at the ceiling.

Momentum has the same shape (section 3): best at β=0.5\beta = 0.5, and 678 steps at 0.990.99. "As large as possible without diverging" is wrong for both knobs.

This is hard to see in practice because in a deep model both $L_{\max}$ and $\kappa$ move during training. An $\eta$ that was stable early can cross the ceiling later, and learning-rate decay and warmup read as machinery for chasing a moving ceiling. When the loss spikes once and never recovers, suspect first that the ceiling was crossed on that step.

Exercises

The answers are folded away. Work them first.

Exercise 1. A problem with curvatures λmin⁡=0.5\lambda_{\min} = 0.5 and λmax⁡=50\lambda_{\max} = 50. (a) The ceiling on η\eta. (b) The best η\eta. (c) The resulting contraction, and the steps needed to cut the error to 1/1001/100.

Show the answer

(a) η<2/50=0.04\eta < 2/50 = 0.04. The ceiling depends only on the largest curvature.

(b) η∗=2/(0.5+50)=0.0396\eta^{*} = 2/(0.5+50) = 0.0396, just under the ceiling. The larger the condition number, the closer the optimum sits to the ceiling — and the more a mistake costs.

(c) Contraction (κ−1)/(κ+1)=99/101=0.9802(\kappa-1)/(\kappa+1) = 99/101 = 0.9802, and ⌈log⁡(0.01)/log⁡(0.9802)⌉=231\lceil \log(0.01)/\log(0.9802) \rceil = 231 steps. Against the κ=10\kappa=10 example (35 steps): ten times the condition number, about 6.6 times the steps. Condition number matters.

Exercise 2. You halve the learning rate. (a) In section 5's table, where does the test-error minimum move? (b) What happens to its height? (c) What follows from that?

Show the answer

(a) Roughly twice as many steps — it moves right. Each step covers half as much ground, so reaching the same place takes twice as many. Lower the figure's learning-rate slider and the left panel's minimum slides right.

(b) Almost unchanged. If you end up in the same place (the same ∥w∥\lVert w \rVert), the test error is the same.

(c) The learning rate sets how many steps, not where you land (in this setting). So you cannot substitute the learning rate for early stopping. Where to stop is a separate decision, made on validation data (Chapter 2).

Exercise 3. The loss keeps falling while the validation error starts rising. (a) What is happening? (b) Will lowering the learning rate fix it? (c) Name three things to do.

Show the answer

(a) Overfitting. Training loss falls to the very end (the left column in section 5), so watching training loss alone cannot show you this moment. Watch the direction of the validation error.

(b) No. The learning rate controls speed, not destination (Exercise 2). Lowering it takes you to the same place more slowly, and the point where validation turns up simply arrives later.

(c) ① Stop where validation bottoms out (early stopping) ② apply L2 or another regulariser ③ add data or lower capacity. As section 5 shows, ① and ② do nearly the same thing. ③ is the more reliable lever, per Chapter 2.

What this chapter does not say

  • Stochastic (minibatch) gradients are not included. Every measurement here uses the full-data gradient. The minibatch noise measured in Chapter 0-3 (σ/B\sigma/\sqrt{B}) is often said to act as a regulariser in itself; that is not measured here.
  • Learning-rate schedules (decay, warmup, one-cycle) appear only as "machinery for chasing a moving ceiling"; which to use when is not covered.
  • Adam's bias correction, the role of β2\beta_2, and its interaction with weight decay (AdamW) are left to the article.
  • "Early stopping = L2" is not an exact identity. It is a classical correspondence under a quadratic approximation, and what the text shows is that one measured setting comes out close. Nothing here claims it holds unchanged for a nonlinear model.
  • Every number was computed and checked (the learning-rate sweep against the theoretical η∗\eta^{*}, the 35 steps predicted from the contraction against the 35 measured, the momentum and Adam sweeps, the early-stopping trace and the L2 sweep, and the comparison of the two optima).

Going deeper

Comments

Sign in to comment