Skip to content
ravi does things
← Writing

Why the learning rate can't be too big

Gradient descent on the simplest possible loss, with a slider, and the one line of algebra that explains when it blows up.

#ml#optimization#interactive

Every ML course tells you to “pick a small learning rate.” Here is the smallest example that shows why, and exactly where “small” ends.

The setup

Take the loss f(w)=w2f(w) = w^2. Its gradient is f′(w)=2wf'(w) = 2w, so one step of gradient descent with learning rate η\eta is

wt+1=wt−η f′(wt)=(1−2η) wt.w_{t+1} = w_t - \eta \, f'(w_t) = (1 - 2\eta)\, w_t .

That’s it: every step multiplies ww by the same number r=1−2ηr = 1 - 2\eta. After tt steps,

wt=(1−2η)t w0.w_t = (1 - 2\eta)^t \, w_0 .

Play with it

Drag the slider and press Run. Try η=0.1\eta = 0.1, then 0.50.5, then 0.80.8, then 1.051.05.

-4-2024w

step 0 · w = -4.0000 · f(w) = 16.0000

What you just saw

The whole story is the size of r=1−2ηr = 1 - 2\eta:

η\etar=1−2ηr = 1 - 2\etabehaviour
0<η<0.50 < \eta < 0.50<r<10 < r < 1slides smoothly into the minimum
η=0.5\eta = 0.5r=0r = 0lands on the minimum in one step
0.5<η<10.5 < \eta < 1−1<r<0-1 < r < 0overshoots and zig-zags, but converges
η=1\eta = 1r=−1r = -1bounces between ±w0\pm w_0 forever
η>1\eta > 1r<−1r < -1each bounce is bigger: divergence

So gradient descent converges exactly when ∣1−2η∣<1|1 - 2\eta| < 1, i.e. 0<η<10 < \eta < 1.

How this page is built

This post is an .mdx file. The math is plain $...$ / $$...$$ rendered by KaTeX at build time, and the demo is a React component dropped in as an island:

import GradientDescent from '../../components/islands/GradientDescent.tsx';

<GradientDescent client:visible />

client:visible means its JavaScript only loads when you scroll to it. Everything else on the page is static HTML.