Backpropagation, One VJP per Layer
An interactive live film: real numbers flow forward and gradients flow back through a small network; nudge a weight and check the backward pass against the real change on the 3D loss surface.
Narration
Here is the chapter's network with real numbers: two inputs, a linear layer W one, a sigmoid, a second linear layer W two, and the squared error loss.
The forward pass runs from left to right and writes every value on the way. It keeps x and h, the amber tags, because the backward pass will need them.
Now the backward pass runs from right to left, in purple. The loss hands back y hat minus y, and each box multiplies by its own Jacobian, transposed: one V J P per box.
On the way back, the two linear layers drop off their weight gradients as outer products. Watch the cells of nabla W one light up: a column times a row.
Below, the loss is drawn as a surface over two of the weights, the first entry of W one and the first entry of W two. The dot is our network, and the red arrow is the gradient that backpropagation just computed: the steepest way up.
Does backpropagation tell the truth? The slider nudges the first weight. The dashed line predicts the change in the loss from the gradient, and the surface shows the real change. For small nudges they agree; for large ones they drift apart.
Your turn. Drag the slider, or drag the dot to move both weights, and find a nudge that lowers the loss.
Any small nudge against the gradient lowers the loss, at the rate backpropagation predicted, and the backward pass read only x and h, never z. Keep exploring: every number above follows the dot.
More from Chapter 11
Preview1:27Partial Derivatives Are Two SlicesChapter 11
Preview1:34The Gradient Is the Steepest DirectionChapter 11
Preview1:42Jacobian Matrix: Linearizing a MapChapter 11
Preview1:43The Derivative of the Matrix InverseChapter 11
Preview1:54Forward or Reverse: Filling the JacobianChapter 11
Preview1:32Taylor Expansion, One Term at a TimeChapter 11
Preview1:30Second-Order Taylor: Where the Quadratic Model Can Be TrustedChapter 11
Preview1:38A Hessian-Vector Product from Two GradientsChapter 11
Preview1:34The Gauss–Newton MatrixChapter 11
Preview1:44Hessian Matrix: Bowls, Saddles and Curvature DirectionsChapter 11
Preview1:37Why the Hessian Is SymmetricChapter 11
Preview1:26The Newton Step: Jumping to the Taylor Bowl's BottomChapter 11
Preview2:36Corners, Maxima and Steps in the Chain RuleChapter 11
Preview1:59GPTQ: Rounding with the HessianChapter 11
Preview2:12AWQ: Activation-Aware Weight QuantizationChapter 11
Preview1:41The Implicit Function TheoremChapter 11