Complete the RMSNorm formula
RMSNorm(x) = gamma * x / sqrt(mean(x^2) + eps). One learnable scale `gamma` per feature, and a small `eps` (typically 1e-5 or 1e-6) under the square root for numerical stability.
Imagine each token in the model has a list of 4096 numbers. Some lists are bigger overall, some smaller. RMSNorm just measures the typical size of those numbers (the root mean square) and divides everything by that, so every list ends up at roughly the same overall scale. Then it lets the model learn one knob per position to fine-tune the final scale. That is the whole operation. The two missing pieces of the puzzle are the knob name (gamma) and the tiny safety constant under the square root (epsilon) that stops the division from blowing up when the input is all zeros.
Detailed answer & concept explanation~4 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
2 min: write the formula, identify gamma and eps as the two blanks, contrast with LayerNorm (no mean subtraction, no bias), note the compute saving, and name eps inside the radical.
| Aspect | LayerNorm | RMSNorm |
|---|---|---|
| Normalizing quantity | `(x - mean(x)) / sqrt(var(x) + eps)` | `x / sqrt(mean(x^2) + eps)` |
| Mean subtraction | Yes | No |
| Learnable params per feature | 2 (gamma, beta) | 1 (gamma) |
| Reductions over feature axis | 2 (mean, then variance) | 1 (mean of x^2) |
| Typical eps | `1e-5` | `1e-5` or `1e-6` |
| Compute cost | Baseline | Roughly 30-50% faster |
Real products, models, and research that use this idea.
- Llama 3.1 8B and 70B both use RMSNorm with eps `1e-5` in every block (two per block, plus a final RMSNorm before the unembedding head).
- Mistral Large and Mixtral 8x22B use RMSNorm with eps `1e-5`.
- PyTorch added `torch.nn.RMSNorm` as a first-class module in PyTorch 2.4 (2024), matching the Llama-style inside-eps formula.
- T5 (Raffel et al., 2020) was one of the first major models to use RMSNorm in production, predating its dominance in decoder LLMs.
- Llama's reference implementation in the `llama` repo defines RMSNorm as `x * rsqrt(x.pow(2).mean(-1, keepdim=True) + eps) * weight`, which exactly matches the formula.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is gamma per-feature (shape `(d_model,)`) rather than a single scalar?
QWhat happens if you set eps too large, like `1e-2`?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Adding a learnable bias term. RMSNorm deliberately omits the bias that LayerNorm has; only one learnable parameter per feature.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.