Foundation Lab

Layer Normalization & RMSNorm

LayerNorm and RMSNorm use statistics from one activation vector rather than from other batch members; transformer families may use either convention

Concept 54 of 100Core TrainingPhase 2
#54LayerNormCore Training
key equation
μ(x)=1d∑i=1dxi,σϵ(x)=1d∑i=1d(xi−μ(x))2+ϵ,LNϵ(x)=γ⊙x−μ(x)σϵ(x)+β,RMSϵ(x)=1d∑i=1dxi2+ϵ,RMSNormϵ(x)=γ⊙xRMSϵ(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\bigl(x_i-\mu(x)\bigr)^2+\epsilon},\\ \mathrm{LN}_\epsilon(x)&=\gamma\odot\frac{x-\mu(x)}{\sigma_\epsilon(x)}+\beta,\\ \mathrm{RMS}_\epsilon(x)&=\sqrt{\frac{1}{d}\sum_{i=1}^d x_i^2+\epsilon},\\ \mathrm{RMSNorm}_\epsilon(x)&=\gamma\odot\frac{x}{\mathrm{RMS}_\epsilon(x)}\end{aligned}
Reading map and next steps

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 54 of 100LayerNormCore Training / Phase 2: Architecture fundamentals
Current question

With positive ε, positive rescaling is only approximately canceled when activation variance dominates ε; negative rescaling also reverses the normalized direction before the affine map

μ(x)=1d∑i=1dxi,σϵ(x)=1d∑i=1d(xi−μ(x))2+ϵ,LNϵ(x)=γ⊙x−μ(x)σϵ(x)+β,RMSϵ(x)=1d∑i=1dxi2+ϵ,RMSNormϵ(x)=γ⊙xRMSϵ(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\bigl(x_i-\mu(x)\bigr)^2+\epsilon},\\ \mathrm{LN}_\epsilon(x)&=\gamma\odot\frac{x-\mu(x)}{\sigma_\epsilon(x)}+\beta,\\ \mathrm{RMS}_\epsilon(x)&=\sqrt{\frac{1}{d}\sum_{i=1}^d x_i^2+\epsilon},\\ \mathrm{RMSNorm}_\epsilon(x)&=\gamma\odot\frac{x}{\mathrm{RMS}_\epsilon(x)}\end{aligned}
PredictionCommit before the demo.

Ask what should change when the equation is manipulated, then use the linked notebook demo to test that expectation.

EvidenceCompare the linked witness and source.

Use the linked notebook demo, this key equation, and canonical papers as separate witnesses for the same object.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue in the newer notebook.

This atlas page has no local demo; the domain notebook carries the interactive witness and the fuller Intuition -> Math -> Code -> Demo sequence.

Why It Matters for Modern Models

  • LayerNorm and RMSNorm use statistics from one activation vector rather than from other batch members; transformer families may use either convention
  • Pre-norm and post-norm place the same operator on different residual paths, so their gradient paths differ; stability effects depend on architecture and depth
  • RMSNorm omits the mean calculation, reducing this page's toy scalar-operation count; end-to-end speed and model quality depend on the implementation and model

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • With positive ε, positive rescaling is only approximately canceled when activation variance dominates ε; negative rescaling also reverses the normalized direction before the affine map
  • Learned γ and β restore per-feature scale and shift after LayerNorm; they do not recreate the discarded per-vector statistics
  • Pre-norm and post-norm are not interchangeable labels: moving normalization changes the residual and gradient paths

Visualization Status

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation here and the linked notebook demo. Come back here for the full walkthrough.

Key Equation
μ(x)=1d∑i=1dxi,σϵ(x)=1d∑i=1d(xi−μ(x))2+ϵ,LNϵ(x)=γ⊙x−μ(x)σϵ(x)+β,RMSϵ(x)=1d∑i=1dxi2+ϵ,RMSNormϵ(x)=γ⊙xRMSϵ(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\bigl(x_i-\mu(x)\bigr)^2+\epsilon},\\ \mathrm{LN}_\epsilon(x)&=\gamma\odot\frac{x-\mu(x)}{\sigma_\epsilon(x)}+\beta,\\ \mathrm{RMS}_\epsilon(x)&=\sqrt{\frac{1}{d}\sum_{i=1}^d x_i^2+\epsilon},\\ \mathrm{RMSNorm}_\epsilon(x)&=\gamma\odot\frac{x}{\mathrm{RMS}_\epsilon(x)}\end{aligned}

For one activation vector x∈Rdx\in\mathbb R^d, with integer d≥1d\ge 1, let γ,β∈Rd\gamma,\beta\in\mathbb R^d and set ϵ=10−5\epsilon=10^{-5} for this page. Write xix_i for coordinate ii of xx, and let ⊙\odot denote elementwise multiplication.

LayerNorm centers the dd features and then applies an elementwise affine map:

μ(x)=1d∑i=1dxi,σϵ(x)=1d∑i=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\bigl(x_i-\mu(x)\bigr)^2+\epsilon},\\ \mathrm{LN}_\epsilon(x) &= \gamma\odot\frac{x-\mu(x)}{\sigma_\epsilon(x)}+\beta. \end{aligned}

RMSNorm omits mean centering and uses the stabilized root mean square:

RMSϵ(x)=1d∑i=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}_\epsilon(x) &= \gamma\odot\frac{x}{\mathrm{RMS}_\epsilon(x)}. \end{aligned}

The linked notebook demo's scalar γ\gamma and β\beta controls are broadcast across all dd features; the equations above state the general elementwise parameters. RMSNorm has no β\beta term under this page's convention.

The cited papers ground the centering-plus-affine LayerNorm object and RMS-only rescaling. This legacy entry and the linked notebook demo place ϵ=10−5\epsilon=10^{-5} inside each square root as an explicit numerical convention; library defaults, normalized axes, and affine variants may differ.

Canonical Papers

Layer Normalization

Ba, Kiros, Hinton2016arXiv
Read paper →

Root Mean Square Layer Normalization

Zhang & Sennrich2019NeurIPS
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.