Zain Dana Harpernight school / F4

Backpropagation. Blame, passed backwards.

A model needs the slope for every one of its numbers. Nudging each one costs a whole run apiece. Pylon's bucket chain shows the trick that gets them all in one walk back.

The film

About 4:59, hosted by Pylon. It asks you one question and waits for your answer before it shows you. The narrated cut runs 3:50, 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 bucket chain

Train a 2-8-8-2 network (114 numbers) on two spirals, in your browser. Click any point to see its chain: the value in every bucket and the blame arriving at it. Check the walk back against nudging every number, then break one link on purpose and watch the check point at it. In the film's run, one walk back cost 208 multiply-adds against 98 for the forward pass, and the network was right on 99.8% of new points after 4,000 steps.

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

Everything the film says

Backpropagation

Backpropagation. Blame, passed backwards.

Last time I could feel the slope for two numbers. A model has thousands. Tonight, how it gets all their slopes in one go.

A chain of buckets

Here is a small network. It looks at a point on a map and says which of two spirals the point belongs to.

It has 114 numbers. Two go in at the top, pass through two layers of 8 buckets each, and come out as two guesses at the bottom.

Every bucket in the middle takes what the buckets above hand it, weighs it, adds it up, and squashes the total through a smooth curve. The last two turn their totals into two guesses that add up to one. That's the forward pass.

Feeling every slope by hand

At the bottom we measure how wrong it was: the loss. Now we want each of the 114 slopes.

The slow way: nudge one number, run the whole chain again, see how the loss moved. That's one extra run for every number. For the model from the attention lesson, that's 20,864 runs, for every single step of training.

Pass the blame back

The fast way runs the chain once, then walks it backwards.

How many backward walks does it take to get all the slopes? (the film pauses here)

Each bucket at the bottom knows how much the loss changes when its own output changes. It hands that blame up to each bucket that fed it, multiplied by how much its own output moved when that input moved. A bucket that fed several adds up the blame from all of them, then does the same, all the way to the top.

That's the chain rule from school, done in reverse order. Seppo Linnainmaa worked out this reverse order in 1970, and in 1986 Rumelhart, Hinton and Williams showed what it could do for training networks.

One walk back

One. A single walk back hands every number its slope.

Counting multiply-adds for one point, and leaving the curves aside: the forward pass takes 98, the backward pass 208, about 2.12 times as many. Not 114 extra runs. About two runs' worth.

Checking the chain

A walk back like this is easy to get slightly wrong, so we check it the slow way. Nudge every number, compare.

After training, they agree layer by layer to about one part in a billion, and the worst single number is off by about three parts in a hundred million.

Now I break one link on purpose: in the second layer, the curve's slope is written wrong. The check fails in that layer and every layer above it, and still passes in the last layer, below the break. The check doesn't just say something is wrong. It points to where.

Downhill, every number at once

Now put it together with last time: walk forward, walk back, step every number a little downhill, repeat.

On points it never trained on, the network starts out right 36 percent of the time. It is past 95 percent by step 2,000, and after 4,000 steps it gets 99.8 percent right.

The same walk, inside the language model

The model from the attention lesson walks forward and back the same way, with a backward pass written out by hand for every part: the attention, the layer norms, the bends. It steps downhill a little more cleverly, and that's next time.

We checked it the slow way too, on 36 of its numbers. In full precision the worst disagreement is a few parts in ten million.

Goodnight

Run forward once, pass the blame back once, and every number knows its slope.

Next along the hill: better ways to step than straight downhill. 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

The network is tiny and the spirals are a toy task, so it trains in well under a second. Large models are trained the same way in principle, by software that writes the backward pass automatically rather than by hand.

The count of multiply-adds leaves out the curves (tanh, exp and log) and is for one point. The general bound for reverse mode is a small constant times the cost of the function; our measured 2.12 is one network, not that bound.

Before this: Gradients (F3). Next along the hill: optimisers (F5), planned.