Foundations
Backpropagation, visualized
Reverse-mode differentiation gets every parameter's gradient in one backward sweep whose cost is of the same order as evaluating the graph — the only reason a 27-billion-parameter model can be trained at all.
Updated
01 · Concept
Concept
Lesson 2.4 produced a single number: the loss. To improve the model you need to know, for every parameter, whether nudging it up or down would make that number smaller. There is an obvious way to find out. Perturb one parameter by a tiny amount, run the model again, see how the loss moved, and divide. Repeat for the next parameter.
Price that plan honestly, because it is the wrong turn worth walking into. A careful two-sided estimate needs two forward passes per parameter. For a small network with ten thousand parameters that is twenty thousand forward passes per gradient — slow but survivable. For Qwen3.8-27B, with roughly 27 billion parameters (Qwen3.8-27B Model Card, 2026), it is 54 billion forward passes to obtain the gradient for a single training step. If one forward pass took a millisecond, one step would take about twenty months. Finite differences do not scale badly; they do not scale at all.
Backpropagation is what replaces it, and the improvement is not incremental. One backward sweep produces the gradient for every parameter at once, at a cost of roughly the same order as evaluating the graph. A larger model still makes both passes more expensive; the saving is that reverse mode does not require a separate evaluation for every parameter.
The mechanism is the chain rule applied to a recorded graph. The forward pass evaluates operations in order, saving the intermediate values that derivatives will need. The backward pass starts at the end with and walks the operations in reverse, and at every operation the rule is the same: upstream gradient times local derivative. Each operation only needs to know how its own outputs respond to its own inputs; it never needs to know anything about the rest of the network.
Do one by hand, using the loss from lesson 2.4. Take three logits with the observed class being the first. Forward: exponentials are about , , and , summing to , so and . Backward: for softmax followed by cross-entropy the gradient with respect to the logits collapses to the beautifully simple , which here is . Read it as an instruction. The correct class carries a negative gradient, so gradient descent will raise its logit. The two wrong classes carry positive gradients in exact proportion to the probability they took, so their logits get pushed down, the more confidently wrong one hardest. Now suppose those logits came from for a hidden vector . The same rule continues: , , and — that last one is the message handed to the layer below, which will apply the identical procedure with its own local derivative.
Graphs branch, and branching is where implementations get subtle. If a value influences the loss along two paths, its gradient is the sum of the two contributions, because that is what the multivariable chain rule says. This is why autodiff frameworks accumulate into gradient buffers rather than overwriting them, and consequently why a training loop must zero those buffers at batch boundaries: summation is the mathematically correct default for repeated use, and only the loop knows where one batch ends.
The bill arrives as memory rather than time. The backward pass needs values the forward pass computed, so training holds activations alive from the moment they are produced until their gradients are consumed. Multiply that by 64 layers, by the intermediate width of 17408 inside each feed-forward block, by every token position in the batch, and activation memory rivals or exceeds parameter memory. Gradient checkpointing buys memory back by storing only selected boundaries and recomputing the rest during backward — more compute for less memory, and a lever lesson 5.10 turns explicitly.
Two habits keep this honest. For any new custom operation, gradient-check it against finite differences on a tiny input — the method that fails at scale is perfectly good as a unit test, given sensible precision and step size, away from non-differentiable points. And before a long run, confirm that every parameter you expect to train has a finite, nonzero gradient after one loss. The enduring picture is a reverse flow of responsibility through a recorded graph, where purely local rules compose into global sensitivity, and where the optimizer of lesson 2.7 has not yet done anything at all.
02 · Analogy
Analogy
A bakery records every transformation from flour to finished loaves. When the final loaf is too dense, a reviewer walks the ledger backward. At each station, they combine the complaint arriving from downstream with that station's local sensitivity: how kneading affected rise, how water affected dough, and how flour affected water absorption. Shared ingredients receive complaints from every path. The backward audit assigns responsibility efficiently without baking one new loaf per knob.
03 · Teach it back
Teach it back
Explain forward pass, computational graph, upstream gradient, local derivative, and accumulation — then say why reverse mode rather than finite differences is what makes training a 27B-parameter model feasible.
Compare with a model answer
The forward pass computes intermediates and a scalar loss, recording a graph of operations. Reverse mode starts from dL/dL=1, and each node multiplies the incoming upstream gradient by its own local derivative before passing contributions to its parents; when a value feeds several consumers, the contributions add. The whole backward sweep costs a small constant multiple of evaluating that graph rather than one new evaluation per parameter; a larger graph still costs more. Estimating the same gradients by finite differences would need two forward passes per parameter — tens of billions of them for a model such as Qwen3.8-27B — which is why reverse mode is not an optimization but a precondition.
04 · Check your understanding
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
◎ · Evidence marker
Sources
- David E. Rumelhart, Geoffrey E. Hinton, and Ronald J. Williams (1986). Learning representations by back-propagating errors.
- JAX Team (2026). Forward- and reverse-mode autodiff in JAX.
- Qwen Team (2026). Qwen3.8-27B Model Card.