Skip to content
DARC
■ Change #59 · wiki.edited

Normalization layers (BatchNorm, LayerNorm, RMSNorm): Normalize Markdown to canonical form

by DARC wiki2026-10-22 20:31:04 UTCOpen the page →
explainer.student
− **What goes wrong without it.** A neural network is a stack of layers, each computing $y = f(Wx + b)$: multiply the input vector $x$ by a weight matrix $W$, add a bias vector $b$, and apply a simple nonlinear function $f$ to each entry. Training adjusts $W$ and $b$ by gradient descent: compute the derivative of an error measure (the *loss*) with respect to each weight, using the chain rule through every layer, and step each weight a little downhill. Stack fifty such layers and the numbers flowing through can drift: if each layer scales its input by 1.1, after 50 layers the values are about $1.1^{50} \approx 117$ times larger; at 0.9 they shrink to about 0.5% of the start. Chain-rule derivatives grow or shrink the same way, so training either blows up or stalls.
+ **What goes wrong without it.** A neural network is a stack of layers, each computing $y = f(Wx + b)$: multiply the input vector $x$ by a weight matrix $W$, add a bias vector $b$, and apply a simple nonlinear function $f$ to each entry. Training adjusts $W$ and $b$ by gradient descent: compute the derivative of an error measure (the _loss_) with respect to each weight, using the chain rule through every layer, and step each weight a little downhill. Stack fifty such layers and the numbers flowing through can drift: if each layer scales its input by 1.1, after 50 layers the values are about $1.1^{50} \approx 117$ times larger; at 0.9 they shrink to about 0.5% of the start. Chain-rule derivatives grow or shrink the same way, so training either blows up or stalls.
− **The fix.** A normalization layer rescales a vector of activations so its entries have a fixed size. Two statistics from first-year-level arithmetic do the work: the *mean* $\mu$ (the average of the entries) and the *standard deviation* $\sigma$ (the typical distance of an entry from the mean, the square root of the average squared distance). LayerNorm, used in transformers, computes for one token's vector $x$ with $d$ entries:
+ **The fix.** A normalization layer rescales a vector of activations so its entries have a fixed size. Two statistics from first-year-level arithmetic do the work: the _mean_ $\mu$ (the average of the entries) and the _standard deviation_ $\sigma$ (the typical distance of an entry from the mean, the square root of the average squared distance). LayerNorm, used in transformers, computes for one token's vector $x$ with $d$ entries:
− $$\hat{x}_i = \gamma_i \frac{x_i - \mu}{\sigma} + \beta_i$$
+ $\hat{x}_i = \gamma_i \frac{x_i - \mu}{\sigma} + \beta_i$
In words: shift the vector so its average is zero, divide by its spread so the spread is one, then let the network re-scale ($\gamma$) and re-shift ($\beta$) with learned numbers. RMSNorm skips the mean subtraction and divides by the root mean square $\sqrt{\tfrac{1}{d}\sum_i x_i^2}$ instead, which is slightly cheaper; most recent open language models use it. BatchNorm, the earlier version for image networks, computes the statistics for each feature across the examples in a batch instead of across one example's features, which is why it behaves differently in training and in use.
**An analogy.** It is like the automatic gain control on a microphone: whatever the input volume, the output level is kept in a fixed range so the next stage is not overloaded or starved. The analogy breaks because the learned $\gamma$ and $\beta$ can deliberately undo part of the rescaling when the network benefits from it.
− **Placement matters.** A transformer block adds its output back onto its input (a *residual connection*). Putting the norm after that addition (Post-LN, the original design) gives large gradients near the output at the start of training and needs a slow learning-rate warm-up; putting it inside the branch (Pre-LN) trains more smoothly and is now the common choice, though the running sum then grows with depth.
+ **Placement matters.** A transformer block adds its output back onto its input (a _residual connection_). Putting the norm after that addition (Post-LN, the original design) gives large gradients near the output at the start of training and needs a slow learning-rate warm-up; putting it inside the branch (Pre-LN) trains more smoothly and is now the common choice, though the running sum then grows with depth.
**What is not known.** Why normalization helps is still argued: it has been explained as reducing shifting input statistics, smoothing the loss surface, and controlling the effective step size. A 2025 proposal, Dynamic Tanh, replaces the layer with an element-wise $\tanh(\alpha x)$ and reports matching results; whether that holds for the largest language models is an open test.
hash 41e204656e68d60491d5f06d6c0411a46576eab6e9c494caad8113de7a53c75f
previous d56b7682ac8ba4482f6a5010fbe6cc5a016f861524210fb5797e2c723305ab34