09 · F · Reverse
Backpropagation and Jacobians
Reverse-mode AD, the p − y collapse, RMSNorm, attention, SwiGLU, and the skip whose Jacobian is I.
Chain rule and Jacobians
Training is gradient descent on . Backprop is reverse-mode automatic differentiation: one backward sweep computes . If , , and is scalar:
- Jacobian of the local map
- vector-Jacobian product (VJP) — what is actually computed
In practice nobody materializes giant Jacobians. Frameworks compute VJPs. For a matrix multiply , with incoming gradient :
Why it mattersThose two identities run through almost the entire Transformer. Every linear map is this pair.
Softmax + cross-entropy collapses
This is the most important gradient in the whole system. Start from the definitions:
The upstream vector is . One-hot at makes that . The VJP through softmax is
Here and , so
Why it mattersYou do not backprop through softmax and log separately. The error signal is “probability assigned minus truth.” Overconfident wrong tokens get a large push; already-correct peaked predictions get a small one.
Into the residual stream and W_U
Then the final Norm Jacobian maps back to .
RMSNorm Jacobian (one vector)
Let , , .
Then follows by the product rule with . LayerNorm is the same idea after projecting orthogonal to (mean removal).
Attention backward
Fix one head. Forward: , , . Given :
RoPE’s backward pass is the inverse rotation. Then etc. give
The same for K, V. Multi-head: sum the contributions.
Residual Jacobian
Why it mattersThe first term is the skip connection. That is why deep Transformers train: there is always a path whose Jacobian is I.
SwiGLU backward
Let , , , , .
Then ordinary matmul rules for .
Embedding backward
is scattered back into the rows of (and if used):