Forward Deployed EngineeringAI EngineeringTransformer Training Stability

Pre-norm vs post-norm transformers: why do large models use pre-norm, and how does it affect training stability?

Question 67 of 73 · Updated

On this page

Interview-ready answer#

Pre-norm and post-norm differ in where normalization sits relative to the residual addition. In pre-norm, a sublayer consumes a normalized input and adds its output to the original residual stream. In post-norm, the sublayer output is added to the residual stream first, and the entire sum is normalized.

Large language models often favor pre-norm because it preserves an explicit identity path through the residual stream. Backpropagation through a deep stack therefore does not have to pass through a normalization Jacobian at every residual connection. This generally makes deep networks easier to optimize and less sensitive to initialization and learning-rate warmup than conventional post-norm Transformers.

The trade-off is that the unnormalized residual stream can accumulate large activations, and deeper blocks may contribute relatively small updates. Post-norm can perform well with carefully designed residual scaling, initialization and optimization. Pre-norm improves the optimization geometry; it does not guarantee stable training or better final model quality.

1. Residual block equations#

Let xₗ be the residual stream entering layer l, Fₗ a differentiable sublayer such as attention or an MLP, and N a normalization operator such as LayerNorm.

Pre-norm:

LaTeX

Post-norm:

LaTeX

A standard Transformer block typically applies the chosen pattern twice: once to the attention sublayer and once to the feed-forward sublayer, each with its own normalization parameters.

Loading diagram…

Both variants have a residual connection. The crucial difference is whether normalization also transforms the skip path after the sum.

2. Why gradient propagation changes#

Use column-vector activations and let J denote a Jacobian, with I the identity matrix. Applying the chain rule gives:

ArchitectureLocal input-output Jacobian
Pre-normI + J_F(N(x)) J_N(x)
Post-normJ_N(x + F(x)) (I + J_F(x))

In a deep stack, backpropagation multiplies the transposes of these Jacobians. Pre-norm provides an additive identity term in each local Jacobian. When residual-branch Jacobians are small, the local transformation can remain close to identity. The residual stream also has the telescoping form = + Σₗ Fₗ(N(xₗ)), making its direct additive path explicit.

Post-norm instead multiplies every local skip contribution by a normalization Jacobian. The transformation's scale and direction depend on the activations and learned normalization parameters. Repeated multiplication may attenuate or amplify gradients, and parameter-gradient scales can be unfavorable at initialization.

For example, ordinary LayerNorm subtracts the mean and divides by the feature standard deviation with an epsilon term. Its derivative annihilates a uniform input shift: adding the same constant to all features does not change the normalized output. In a pre-norm sublayer the direct residual path preserves that shift; in a post-norm sublayer the normalized output has no dependence on a uniform shift of the summed activation.

This is a structural illustration, not a claim that every useful post-norm gradient vanishes. Nor does an identity term guarantee nonvanishing pre-norm gradients: the residual branch can cancel or amplify directions, products of local Jacobians can still be ill-conditioned, and downstream normalization and loss geometry matter.

3. Numerical demonstration: compare the Jacobians#

For a deliberately small linear residual branch F(x) = Wx, use affine-free LayerNorm with epsilon = 10⁻⁵. Its Jacobian can be written using centered vector c = x − mean(x), feature dimension d, and s = sqrt(mean(c²) + epsilon):

LaTeX

This lets us test both block Jacobians without training an entire model.

PYTHON
import numpy as np def norm(x, eps=1e-5): c = x - x.mean() return c / np.sqrt(np.mean(c*c) + eps) def norm_jac(x, eps=1e-5): d = x.size c = x - x.mean() s = np.sqrt(np.mean(c*c) + eps) return (np.eye(d) - np.ones((d,d))/d)/s - np.outer(c,c)/(d*s**3) def blocks(x, w): return x + w @ norm(x), norm(x + w @ x) def jacobians(x, w): i = np.eye(x.size) return i + w @ norm_jac(x), norm_jac(x + w @ x) @ (i+w) x = np.array([1., 2., 4.]) w = np.zeros((3, 3)) pre, post = jacobians(x, w) print(np.linalg.svd(pre, compute_uv=False)) print(np.linalg.svd(post, compute_uv=False))

For the zero residual branch, the pre-norm Jacobian is exactly I, with singular values [1, 1, 1]. The post-norm Jacobian has approximate singular values [0.801781, 0.000005154, 0]. Even when the learned branch contributes nothing, post-norm still transforms the residual stream.

Executed verification: Python 3.13.5 and NumPy 2.3.5 passed 1,602 checks. Across 320 seeded random configurations (four feature dimensions, four weight scales and twenty samples per combination), both analytic Jacobian-vector products were checked against centered finite differences. Additional checks verified LayerNorm shift invariance, pre-norm preservation of the uniform-shift direction and the post-norm output's zero-mean derivative. Two zero-branch checks completed the suite.

The implementation assumes a single feature vector, no learned affine normalization parameters and a linear branch. It verifies the local mathematical mechanism, not training convergence or perplexity at scale. RMSNorm also has a scale-dependent Jacobian, but does not subtract the mean; the LayerNorm shift-invariance example must not be transferred directly to RMSNorm.

4. Initialization, depth and learning-rate warmup#

The original Transformer used post-norm residual blocks. Theoretical and empirical work on normalization placement found that conventional post-norm can have large expected parameter gradients near the output layers at initialization. Taking a large optimizer step immediately can therefore destabilize training. Learning-rate warmup helps by gradually increasing the learning rate while optimizer statistics and activations settle.

Pre-norm has more favorable gradient behavior under common initialization assumptions and often permits less aggressive warmup. This does not imply that warmup should always be removed: optimizer settings, mixed precision, batch size, residual initialization, architecture and training scale still influence the stable learning-rate range.

Pre-norm does not normalize the whole residual stream at every addition. If branch updates accumulate as depth increases, the residual norm can grow, making individual updates small relative to the existing stream. Correlated updates can worsen activation growth. Residual-branch initialization or scaling, appropriate normalization epsilon and learned gains, optimizer choice and gradient clipping remain important.

Many pre-norm language models use a final normalization before the output projection. This conditions the final residual representation supplied to the prediction head. It does not insert a normalization into every intermediate identity path, although its own Jacobian still affects gradients from the loss.

5. Practical architectural trade-offs#

AspectPre-normPost-norm
Gradient pathExplicit additive identity path across blocksSkip path transformed by normalization
Conventional deep-stack optimizationOften easier and less warmup-sensitiveMay require more careful initialization and optimization
Residual streamCan grow with depth; monitor update-to-stream ratioNormalized after each residual sum, subject to learned affine parameters
Model qualityStrong practical default for deep autoregressive LLMsCompetitive with suitable stabilization; not inherently worse
Output normalizationOften a separate final normAlready normalized at residual-block outputs

GPT-style and Llama-family designs illustrate the practical preference for normalization before sublayers; Llama uses RMSNorm rather than ordinary LayerNorm. The normalization operator and its placement are distinct architectural choices. Residual-scaled post-norm designs such as DeepNorm demonstrate that very deep post-norm Transformers can be trained successfully with a different initialization and residual scaling strategy.

If a customer is adapting an existing pretrained model, I would preserve its exact architecture, including norm placement, epsilon and final norm. Moving normalization across residual additions changes the computed function; it is not a checkpoint-compatible optimization switch.

If training a new architecture, I would compare matched runs with controlled parameter budgets and training data. Monitor per-layer activation RMS, residual-branch-to-stream RMS ratio, gradient norms, optimizer update-to-weight ratios, loss spikes, non-finite values and independent validation loss. Evaluate stability and final task performance rather than selecting the architecture solely because one early training curve looks smoother.

Related questions

Explore other topics:AI AgentsAI System DesignLarge Language Models