Skip to content

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:

(9.1)
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 :

(9.2)

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:

(9.3)

The upstream vector is . One-hot at makes that . The VJP through softmax is

(9.3b)

Here and , so

(9.4)
(9.5)

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

(9.6)

Then the final Norm Jacobian maps back to .

RMSNorm Jacobian (one vector)

Let , , .

(9.7)

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 :

(9.8)
(9.9)
(9.10)

RoPE’s backward pass is the inverse rotation. Then etc. give

(9.11)

The same for K, V. Multi-head: sum the contributions.

Residual Jacobian

(9.12)

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 , , , , .

(9.13)

Then ordinary matmul rules for .

Embedding backward

is scattered back into the rows of (and if used):

(9.14)