Core
Residuals, pre-norm vs post-norm
Residual paths preserve a shared state through depth, while normalization placement changes optimization and the scale of each update.
Updated
1
Concept
A Transformer does not pass each layer’s output into the next as a total replacement. It maintains a residual stream and asks each sublayer to add an update. For a transformation , the core pattern is
The identity term gives information a direct route through the stack. A layer can learn a small useful correction instead of rebuilding the representation. During backpropagation, gradients also have an additive route that does not multiply through every sublayer’s Jacobian. This does not eliminate exploding or vanishing gradients, but it makes deep optimization substantially more manageable.
Attention and the FFN each write into this stream. After attention, the state contains its previous features plus a communication update. After the FFN, it contains that result plus a nonlinear position-wise update. The residual stream is therefore not one component’s output. It is a shared workspace accumulating many overlapping features.
Normalization controls the scale and distribution seen by transformations. LayerNorm computes statistics across a token’s feature dimension, then applies learned scale and shift. Many modern decoder models use RMSNorm, which normalizes root-mean-square magnitude without subtracting the mean. The placement question remains similar: normalize before a sublayer or after its residual addition?
The original Transformer used post-norm:
The combined state is normalized after every update. A common modern alternative is pre-norm:
Here each sublayer receives normalized input, but the main residual path remains an identity addition. Deep pre-norm stacks often optimize more reliably because the gradient has a cleaner route through successive additions. This is an empirical architectural tendency, not a proof that pre-norm is always more accurate.
Post-norm and pre-norm also produce different representational dynamics. Post-norm repeatedly rescales the combined stream. Pre-norm allows residual magnitude to grow through accumulated updates, so architectures may use a final normalization and sometimes explicit residual scaling. Initialization, depth, learning-rate schedule, precision, and optimizer all interact with the choice.
Dropout, when used, normally applies to the sublayer branch before addition, not to the identity path. That preserves a reliable route while regularizing updates. At inference dropout is disabled. Other methods such as stochastic depth can remove entire residual branches during training, again relying on the identity path to keep the network valid.
The phrase “residual stream” helps interpretation. Many features are superposed in the same vector space, and components read from and write to that space. An attention head’s output may be cancelled by another update, carried unchanged across layers, or transformed later. Looking only at one sublayer output misses the state already present in and the later operations that consume the sum.
A simple debugging habit is to record norms: the norm of , the norm of , and the norm after addition. An update that dwarfs the stream can destabilize training; an update that is always negligible may indicate a dead branch. These are diagnostics, not universal thresholds, because expected scale depends on architecture.
The enduring picture is collaborative editing. The residual stream preserves the current document. Each normalized sublayer reads it and proposes a structured change. Normalization placement determines whether calibration happens before the specialist works or after the edit is merged, changing how safely very deep stacks can be trained.
2
Explain it like I am five
A long restoration project keeps the original photograph on a central light table. Each specialist receives either a calibrated copy or the latest composite, proposes a bounded correction, and adds it back rather than repainting from scratch. Pre-norm calibrates what enters each specialist while leaving the central table continuous. Post-norm adds the correction first and calibrates the combined image afterward.
3
Teach it back
Write the conceptual equations for pre-norm and post-norm, then explain how the residual path helps gradients.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
Pre-norm uses x' = x + F(LN(x)); post-norm uses x' = LN(x + F(x)). The additive identity path lets information and gradients travel through a deep stack without every layer having to reconstruct the full representation. Pre-norm usually offers a more direct unnormalized identity route and often trains deep Transformers more easily, while post-norm changes the state scale after every addition and may require more careful optimization.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun (2015). Deep Residual Learning for Image Recognition.
- Ruibin Xiong et al. (2020). On Layer Normalization in the Transformer Architecture.