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.

status: publishedimportance: importantdifficulty 3/5math: undergraduateread: 14mlive demo
Editorial transformer illustration of activation vectors being centered, scaled, and stabilized by normalization.

Concept Structure

Layer Normalization & RMSNorm

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
1next concepts
2related links

Learning map

Layer Normalization & RMSNorm
BeforeScaled Dot-Product Attention & Transformer LayersNow4/4 sections readyTryManipulate one control and predict the visible change.NextLong Context Engineering: RoPE Scaling, KV Compression & Memory Optimization

Object flow

4/4 sections readyAsk about thisResearch room
ConceptLayer Normalization & RMSNormAttention & Transformers
2 sources attachedLocal snapshot ready
concept:attention-transformers/layer-normalization

Conceptual Bridge

What should feel connected as you move through this page.

Carry inScaled Dot-Product Attention & Transformer Layers

Bring the mental model from Scaled Dot-Product Attention & Transformer Layers; this page will reuse it instead of restarting from zero.

Work hereLayer Normalization & RMSNorm

Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.

Carry outLong Context Engineering: RoPE Scaling, KV Compression & Memory Optimization

The next edge should feel earned: use the demo prediction here before following Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization.

Test the linkManipulate one control and predict the visible change.Then continue to Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

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

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

For a vector of activations xRdx\in\mathbb R^d (for one token / one example), LayerNorm is:

μ(x)=1di=1dxi,σϵ(x)=1di=1d(xiμ(x))2+ϵ,LN(x)=γxμ(x)σϵ(x)+β.\begin{aligned} \mu(x) &= \frac{1}{d}\sum_{i=1}^d x_i,\\ \sigma_\epsilon(x) &= \sqrt{\frac{1}{d}\sum_{i=1}^d (x_i-\mu(x))^2 + \epsilon},\\ \mathrm{LN}(x) &= \gamma \odot \frac{x-\mu(x)}{\sigma_\epsilon(x)} + \beta. \end{aligned}

RMSNorm removes mean-centering and uses:

RMSϵ(x)=1di=1dxi2+ϵ,RMSNorm(x)=γxRMSϵ(x).\begin{aligned} \mathrm{RMS}_\epsilon(x) &= \sqrt{\frac{1}{d}\sum_{i=1}^d x_i^2 + \epsilon},\\ \mathrm{RMSNorm}(x) &= \gamma \odot \frac{x}{\mathrm{RMS}_\epsilon(x)}. \end{aligned}

Two practical insights:

  • Normalization makes the layer output less sensitive to the overall scale of xx.
  • In pre-norm transformers, you normalize before attention/MLP, which tends to improve gradient flow in very deep stacks.
03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
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

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the demo to see:

  • how centering (LayerNorm) vs non-centering (RMSNorm) changes the direction of a vector,
  • how learned γ,β\gamma,\beta 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.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

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.

Prediction open01 / Intuition
Editorial transformer illustration of activation vectors being centered, scaled, and stabilized by normalization.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

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.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

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.

paper · 2016Layer NormalizationBa, Kiros, and Hinton

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 source
paper · 2019Root Mean Square Layer NormalizationZhang and Sennrich

Direct 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 source

Claim Review

Normalize one token/example vector across features: LayerNorm centers and scales, while RMSNorm keeps RMS-based scaling without mean-centering.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources2 references

ba-2016-layer-normalization, zhang-2019-rmsnorm

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedLayerNorm normalizes one token/example vector across its features by subtracting that vector's mean and dividing by its standard deviation, then applying learned gain/bias. RMSNorm uses the same per-vector rescaling frame but omits mean-centering and divides by the root mean square.Claim metadata: source checked

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-07

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.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Layer Normalization & RMSNorm.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptLayer Normalization & RMSNormAttention & Transformers

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.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptAttention & Transformers

Layer Normalization & RMSNorm

Anchored question

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
Local action draft

This draft stays locally in this browser for concept:attention-transformers/layer-normalization.

No local draft saved.
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
Grounded AI handoff

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.

Open source object
concept/concept-notebook/attention-transformers/layer-normalization concept:attention-transformers/layer-normalization