Zain Dana Harpernight school / F5

Optimisers. Better ways to step.

Plain gradient descent crawls along narrow valleys. Pylon gives her walker weight, then a pair of shoes, and races all three on hills where each one wins.

The film

About 5:50, hosted by Pylon. It asks you one question and waits for your answer before it shows you. The narrated cut runs 4:30, voiced by Pylon in a synthesized voice made from the author's own voice; the author approved these cuts for publishing. Captions are on by default. The live version under it draws the same film in your browser, waits for your answer at each question, and runs a little longer; the full words are also below.

Nothing loads until you press play.

The lab: Pylon's race

Race careful steps, the heavy ball and Adam on three hills, each with the step you give it, from wherever you click. On the long narrow valley, at the steps the film chose, the heavy ball got down to stay in 285 updates, careful steps in 6,217 and Adam in 16,790. Then train the spiral network from the bucket chain with any walker and step, and compare the runs.

Everything is computed on your computer, in this page. Nothing is sent anywhere.

Everything the film says

Optimisers

Optimisers. Better ways to step.

Last time I walked downhill one careful step at a time. Tonight the walker gets weight, and then a pair of shoes.

The trouble with careful steps

Remember the long, narrow valley. Steep across, nearly flat along.

Careful steps have to stay small for the steep way, so along the floor they crawl. At the best step we tried, it takes 6,217 steps to get the loss under a ten-thousandth and keep it there.

Give the walker weight

Now make the walker heavy. Each step keeps 90 percent of the last step's motion and adds the new slope on top.

Across the valley, the slopes keep flipping, so they cancel. Along the floor they all point the same way, so they add up. The walker picks up speed exactly where it was crawling.

Boris Polyak described it in 1964. It's known as the heavy ball method.

Shoes for every direction

The other idea is shoes that adjust to the ground. Adam keeps a running average of each slope, and a running average of each slope squared.

It divides the first by the square root of the second. So a direction with a steady slope gets a step of about the same size, however steep or gentle it is: steep directions are slowed down, gentle ones sped up. A direction whose slope keeps flipping gets a short step.

Both averages start at zero, so at first they're too small. Adam scales them back up, so its very first step is the step size you chose, to within a hair, in every direction that has any slope at all.

The race

Same valley, same start. Each walker gets the best step from a few we tried.

Which walker gets down this valley first? (the film pauses here)

The heavy ball, by a mile: 285 steps. Careful steps take 6,217. Adam dips under the line at step 10,346, keeps wandering around it, and only stays under after 16,790.

And on the gentle bowl from last time, careful steps win: 33 steps, against 146 for the other two. No walker is best on every hill.

Past the edge

Remember the edge on the bowl: past a step of 0.5, careful steps fly off. Try 0.6.

Careful steps fly off, as before. The heavy ball's edge here is 0.95, so it gets down. Adam's steps don't grow with the slope, so it doesn't fly off, and here it gets down too.

Changing the step as you go

The step size doesn't have to stay fixed. Many models start with a warmup, small steps while everything is new, then let the step size fall away along a smooth curve.

And AdamW adds one more thing: almost every number shrinks by a small fraction at each step, kept separate from Adam's own step. It pulls numbers that aren't earning their keep back towards zero.

On real networks

On the spirals from the bucket chain, with each walker's step chosen on a separate set of points, careful steps first pass 95 percent on new points at step 2,000, the heavy ball at 1,300, and Adam at 900.

But run five different starting networks and batch orders, and Adam's final score ranges from 91.8 to 99.3 percent, while careful steps stay between 99.0 and 99.8. Fast, and on this network, less steady.

The language model from the attention lesson trains with AdamW. For its first 400 steps, with the same start and the same sentences, AdamW reaches a held-out loss of 0.85, the heavy ball 0.89, and careful steps 0.96.

What a race can't tell you

Every number tonight depends on the hill and on the handful of steps we tried for each walker. Try more, or a different hill, and the order can change.

And four hundred steps is the first fifth of the language model's training. It has barely started to copy, so this shows who gets off the line fastest, not who finishes best.

Goodnight

Weight carries you through the zigzags. Shoes give every direction its own stride. Neither wins every hill.

Next along the hill: learning a harbour by heart, and why that's a trap. Goodnight.

Sources

Every claim in the film, with where it comes from and what that source does not prove. The numbers about the model are computed from its weights, which you can load and check: facts.json.

What this lesson leaves out

Which walker wins depends on the hill and on the handful of steps tried for each; comparisons between optimisers are sensitive to how carefully each one is tuned, and these are small, chosen surfaces.

The language model comparison covers its first 400 updates only, a fifth of its training, before it has properly learned to copy; it shows who gets off the line fastest, not who finishes best.

Before this: Backpropagation (F4). Next: The held-out set (F6).