Before you use the demo in the newer notebook, say what you expect to change.
Foundation reference
Layer Normalization & RMSNorm
LayerNorm and RMSNorm normalize each activation vector with its own statistics rather than statistics over the batch, so they do exactly the same computation at training and test time (Ba, Kiros & Hinton, 2016).
Study guide
Where to start
Multiplying the input by a positive constant a leaves LayerNorm's output almost unchanged when ε is small next to a² times the variance of x; why is the cancellation only approximate when ε > 0, and what happens when a is negative?
How to study this pagePredict · Check · Generalize · Continue
Compare what the notebook demo shows with the key equation here and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
The newer notebook covers the same concept and has an interactive demo.
Why It Matters for Modern Models
- LayerNorm and RMSNorm normalize each activation vector with its own statistics rather than statistics over the batch, so they do exactly the same computation at training and test time (Ba, Kiros & Hinton, 2016).
- The original Transformer applied LayerNorm after each residual addition (post-norm); GPT-3 and LLaMA instead normalize the input of each sublayer (pre-norm), and LLaMA uses RMSNorm (Brown et al., 2020; Touvron et al., 2023).
- Where the normalization sits changes how training behaves: Xiong et al. (2020) showed that post-norm Transformers have large gradients near the output at initialization and need a learning-rate warmup, while pre-norm Transformers can train without one.
- RMSNorm skips the mean; Zhang & Sennrich (2019) found comparable quality to LayerNorm with running time reduced by 7% to 64% across their models, and the actual saving depends on the implementation.
Questions to Think About
- What do the learned γ and β restore after normalization, and why can they not recover the mean and scale that each input vector had before it was normalized?
- How does moving the normalization from after the residual addition (post-norm) to the start of each sublayer (pre-norm) change the path that gradients take through a deep stack of layers?
Interactive Demo
The interactive demo for this concept is in the newer notebook.
Core Math
If you prefer intuition first, try the demo in the newer notebook, then come back for the math.
For one activation vector , with integer , let and set for this page. Write for coordinate of , and let denote elementwise multiplication.
LayerNorm centers the features and then applies an elementwise affine map:
RMSNorm omits mean centering and uses the stabilized root mean square:
The demo in the linked notebook uses one scalar and one scalar for all features; the equations above allow a separate value for each feature. RMSNorm has no term under this page's convention.
LayerNorm centres and rescales each vector (Ba, Kiros & Hinton, 2016); RMSNorm only rescales it (Zhang & Sennrich, 2019). This page and the linked notebook demo place inside each square root as an explicit numerical convention; library defaults, normalized axes, and affine variants may differ.