Deriving the layer recurrence from the graph
symbolic▲▲△Symbolic throughout; no numbers.
STATEMENT
Derive the two equations every implementation of backpropagation contains — the recurrence that carries an adjoint from one layer to the previous one, and the outer product that turns an adjoint into a weight gradient — from the graph rule (I.6.2) alone. Nothing else may be assumed.
GIVEN
One layer of an MLP, written as three nodes so that each has a Jacobian that can be stated:
with , and applied elementwise. A scalar loss sits at the sink. Write .
FIND
Expressions for , and in terms of and quantities the forward pass already stored.
STRATEGY
Work one node at a time and never write down a full Jacobian. Each step asks the same question: given the adjoint of this node’s output, what is the adjoint of its input? That is the vector–Jacobian product of Definition 7, and for these three operations it has a closed form in each case.
SOLUTION
Step 1 — through the nonlinearity. acts elementwise, so is zero unless . The Jacobian is diagonal, and multiplying by a diagonal matrix is multiplying elementwise:
This is the first place the forward pass is consumed: is evaluated at the stored , and without it there is nothing to multiply.
Step 2 — the bias. In the bias enters with coefficient one, so and the local Jacobian is the identity. By (I.6.2) the adjoint passes through unchanged:
Step 3 — the weights. Take one entry. Only the -th output involves , and it involves it linearly with coefficient :
So the sum over consumers in (I.6.2) collapses to a single term:
Every entry is a product of one input coordinate and one output adjoint, which is exactly an outer product:
The shapes confirm it: gives , the shape of . A gradient always has the shape of the thing it differentiates.
Step 4 — back to the previous layer. Now differentiate with respect to the input rather than the parameters. Coordinate feeds every output , so this time the sum does not collapse:
which is the -th entry of :
The transpose is not a convention. Forwards, maps coordinates to ; backwards, the adjoint must travel from back to , and the only way to do that with the same matrix is to use it the other way round.
Step 5 — combine. Applying Step 1 at layer to the result of Step 4 gives the recurrence:
which is (I.6.3), and Steps 2 and 3 are (I.6.4). Both came from (I.6.2) and three local Jacobians, and no Jacobian was ever written out in full.
Answer
Check — sanity
Every gradient has the shape of its parameter. for the weights, and is for the bias. This is the cheapest check there is and it catches a transposed derivation immediately.
The recurrence terminates. comes from the loss, and each application of the recurrence produces one layer earlier, so steps reach the input. Nothing in the derivation refers to a layer that has not been reached, which is what makes reverse topological order the right traversal.
Only stored quantities appear. , and — all present after the forward pass. No re-evaluation of or of any matrix product is required, which is why the backward pass costs about what the forward pass cost rather than twice it.
Where this breaks
The derivation assumes is elementwise, which is what makes its Jacobian diagonal and its VJP a Hadamard product. Softmax is not elementwise: its Jacobian is , dense and of size , and Step 1 does not apply to it. Every layer that mixes coordinates — softmax, normalisation over a feature dimension, attention — needs its own VJP derived separately, and treating one of them as elementwise produces a gradient that is wrong in a way no shape check detects, because the shapes are unchanged.
It also assumes each of , and has exactly one consumer. Tie a weight across two layers and Step 3 acquires a second term, by (I.6.2); I.6.X04 is that case, and the failure of forgetting it is not subtle.
Variation
Redo Steps 3 and 4 for a batch of examples, where and . One of the two results acquires a sum over the batch and the other does not. Which, and why?