Bring the mental model from Scaled Dot-Product Attention & Transformer Layers; this page will reuse it instead of restarting from zero.
Attention & Transformers
Layer Normalization & RMSNorm
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.

Concept Structure
Layer Normalization & RMSNorm
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Layer Normalization & RMSNormConceptual Bridge
What should feel connected as you move through this page.
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.
The next edge should feel earned: use the demo prediction here before following Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Deep networks are sensitive to scale.
If activations grow over layers, gradients can explode. If activations shrink, gradients vanish. Normalization methods keep the signal in a "reasonable range" so training is stable.
Transformers almost always use LayerNorm (or RMSNorm) instead of BatchNorm because:
- sequence models often have small or variable batch sizes,
- we want behavior that does not depend on other examples in the batch,
- decoding/inference should behave the same as training.
RMSNorm is a simplification introduced by Zhang and Sennrich: it drops the mean-centering step and normalizes by the root mean square.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
For a vector of activations (for one token / one example), LayerNorm is:
RMSNorm removes mean-centering and uses:
Two practical insights:
- Normalization makes the layer output less sensitive to the overall scale of .
- In pre-norm transformers, you normalize before attention/MLP, which tends to improve gradient flow in very deep stacks.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
rs = np.random.RandomState(0)
x = rs.randn(8) * 2.0 + 3.0 # nonzero mean on purpose
eps = 1e-5
def layernorm(x):
mu = x.mean()
var = ((x - mu) ** 2).mean()
return (x - mu) / np.sqrt(var + eps)
def rmsnorm(x):
rms = np.sqrt((x ** 2).mean() + eps)
return x / rms
ln = layernorm(x)
rn = rmsnorm(x)
cos = float((ln @ rn) / (np.linalg.norm(ln) * np.linalg.norm(rn)))
print("mean(x), std(x):", round(float(x.mean()), 3), round(float(x.std()), 3))
print("cos(LN, RMS):", round(cos, 3))
print("LN mean/std:", round(float(ln.mean()), 3), round(float(ln.std()), 3))
print("RMS mean/rms:", round(float(rn.mean()), 3), round(float(np.sqrt((rn ** 2).mean())), 3))
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the demo to see:
- how centering (LayerNorm) vs non-centering (RMSNorm) changes the direction of a vector,
- how learned let the network keep normalization while still representing useful scales,
- why normalization is a core stability trick in transformer training.
Live Concept Demo
Explore Layer Normalization & RMSNorm
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Layer Normalization & RMSNorm should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Layer Normalization & RMSNorm should make visible.
Visual Inquiry
Make the image answer a mathematical question
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.
Which visible object should carry the first intuition?
Pick the cue that should make Layer Normalization & RMSNorm easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Direct PDF. Grounds LayerNorm statistics over hidden units in a layer for one training case/current time step, with adaptive gain/bias applied after normalization.
Open sourceDirect PDF. Grounds RMSNorm as RMS-based rescaling that removes the mean statistic; reviews LayerNorm's mean/std form and gives RMSNorm's rescaling-invariance frame.
Open sourceClaim Review
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.
Claims without a substantive review badge still need exact source-support review.
ba-2016-layer-normalization, zhang-2019-rmsnorm
Use equation, code, and demo objects to check whether the source support is operational.
Ba et al. compute LayerNorm statistics over all hidden units in one layer for a single training case and apply learned gain/bias after normalization. Zhang and Sennrich review LN's mean/std form, define RMSNorm as a_i/RMS(a) with gain, and state it removes the mean statistic. Local math, code, and demo instantiate finite-vector centering vs RMS-only scaling.
Sources: Layer Normalization, Root Mean Square Layer NormalizationChecks only normalization mechanics and finite-vector witnesses. The token/example wording maps papers' per-case/per-layer statistics to the page's transformer frame; this does not verify norm placement, LLaMA/adoption claims, affine variants, or training-stability guarantees.A bounded review summary is present; still check caveats and exact source scope.Checked Ba Sec.3/RNN equations and Zhang/Sennrich Secs.3-4. Ba supports per-case/layer statistics over one activation vector with shared mu,sigma and learned gain/bias. Zhang/Sennrich review LN as mean/std scaling, define RMSNorm as a_i/RMS(a)*g_i, and state it removes the mean statistic. Local math/code/demo match finite-vector centering vs RMS-only scaling; transformer usage is not reviewed.
Reviewer: codex+oracle; reviewed 2026-05-07Source support candidates
paper 2016Layer NormalizationDirect PDF. Grounds LayerNorm statistics over hidden units in a layer for one training case/current time step, with adaptive gain/bias applied after normalization.
paper 2019Root Mean Square Layer NormalizationDirect PDF. Grounds RMSNorm as RMS-based rescaling that removes the mean statistic; reviews LayerNorm's mean/std form and gives RMSNorm's rescaling-invariance frame.
Practice Loop
Try the idea before it explains itself
Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.
Before touching the demo, predict one visible change that should happen in Layer Normalization & RMSNorm.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Layer Normalization & RMSNorm
What is the smallest example that makes Layer Normalization & RMSNorm click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:attention-transformers/layer-normalization.
- Source ids to inspect: ba-2016-layer-normalization, zhang-2019-rmsnorm
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Layer Normalization & RMSNorm Object key: concept:attention-transformers/layer-normalization Context: Attention & Transformers Anchor id: concept/concept-notebook/attention-transformers/layer-normalization Open question: What is the smallest example that makes Layer Normalization & RMSNorm click without losing the math? Evidence to inspect: - Source ids to inspect: ba-2016-layer-normalization, zhang-2019-rmsnorm - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/attention-transformers/layer-normalization
concept:attention-transformers/layer-normalization