Pre-Norm vs Post-Norm › Worked Example: Tracing One Gradient Step
Language AI HandbookAll chapters Pre-Norm vs Post-Norm › Worked Example: Tracing One Gradient StepOne section · Sections in this chapter6 / 18 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Abstract gradient flow arguments are most convincing when you can trace them through concrete numbers. Let's work through a simplified example with a two-layer network, small enough to compute by hand but structured exactly like a real transformer.
Suppose our model dimension is , and we have a single-token sequence. The input to layer 2 is the output of layer 1, call it . The loss gradient arriving at the output of layer 2 is .
In the pre-norm case, the output of layer 2 is:
The gradient with respect to the input to layer 2 has two additive parts. The residual path contributes directly: the gradient passes through unchanged. The sublayer path contributes whatever the sublayer's Jacobian carries. Suppose the sublayer Jacobian for this input is the matrix (a small, well-behaved transformation). The LayerNorm Jacobian is , but notice it only appears in the sublayer branch. The total gradient at layer 2's input is:
The residual contribution dominates, and the LayerNorm Jacobian only affects the smaller sublayer branch.
In the post-norm case, the output of layer 2 is:
Now the LayerNorm Jacobian sits between the incoming gradient and everything else. The gradient at layer 2's input becomes:
The key difference is that now multiplies the full gradient before it splits into the residual and sublayer contributions. In a well-behaved layer, has eigenvalues close to 1 and this is fine. But in practice, LayerNorm Jacobians can have eigenvalues significantly less than 1 in certain directions, especially early in training when activations are poorly distributed. Stack 24 such layers, and those sub-unit eigenvalues multiply together, creating the gradient attenuation we visualized earlier.
The key takeaway from this numerical walk-through: pre-norm's term ensures the incoming gradient always reaches the input intact. Even if the sublayer branch contributes nothing useful, the residual branch delivers the full gradient signal. Post-norm has no such guarantee.