Search

Search papers and lessons

RMS Normalization

Level 4 · 9 min read

RMS normalization rescales a vector by its root mean square, a single number, without subtracting the mean, which makes it cheaper than layer normalization and as stable in practice.

On this page

  • Colour = topic mix
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Calculus
  • ReadReady to readNot yet

TL;DR

RMS normalization (RMSNorm) rescales a feature vector so that its root mean square, the typical size of its entries, becomes 1. It divides each entry by that one number, then applies a learned gain. Unlike layer normalization, it does not subtract the mean first, so it does one fewer pass over the data. Large language models use it in almost every layer for that reason.

Builds on: Layer Normalization, Vector Norm · Leads to: Transformer blocks in modern language models

Where it's used

Large language models. Recent open language models such as the LLaMA family place an RMSNorm in front of each attention and feedforward block of every Transformer layer. A model with 32 or more such layers normalizes its hidden vector dozens of times for every token, so a cheaper normalization saves time across the whole network.

Pre-norm residual streams. In a pre-norm block, the input is normalized before attention, and the result is added back to the unnormalized input through a Residual Connection. RMSNorm sets the scale of what enters each sub-layer, so the sub-layer sees inputs of stable size whatever the depth.

Stabilising attention scores. Some recent image and multimodal models apply RMSNorm to the query and key vectors inside attention. There it keeps the dot products from growing without bound as training goes on, which is the failure mode that attention layers are prone to.

How it works

Take one tiny feature vector h = [3, 4], with two entries. Use a learned gain of 1 for both entries, so the gain does not change the picture.

  1. Start with the vector. h = [3, 4]. Check: two entries, so d = 2.

  2. Square each entry. The squares are [9, 16]. Check: squares are never negative, so every term adds to the size.

  3. Average the squares. (9 + 16) / 2 = 12.5. This is the mean square. Check: the average divides by the number of entries, not by the sum of the entries.

  4. Take the square root. The root mean square is √12.5 ≈ 3.5355. Call it RMS. Check: the RMS is in the same units as the entries, so it measures their typical size.

  5. Divide each entry by the RMS. [3 / 3.5355, 4 / 3.5355] ≈ [0.8485, 1.1314]. Check: the signs are unchanged, and the ratio between the two entries stays 3 to 4.

  6. Apply the gain. The gain of 1 changes nothing, so the output is [0.8485, 1.1314]. Check: the mean of the squared outputs is (0.72 + 1.28) / 2 = 1, so the RMS is 1.

Compare with layer normalization on the same vector. Its mean is 3.5, so the centred vector is [-0.5, 0.5], its variance is 0.25, and dividing by the standard deviation 0.5 gives [-1, 1]. Layer normalization moves the centre to zero. RMS normalization leaves the centre where it is and only fixes the size.

flowchart LR
  A["Input vector h"] --> B["Square each entry"]
  B --> C["Average the squares"]
  C --> D["Take the square root (RMS)"]
  D --> E["Divide each entry by RMS"]
  E --> F["Multiply by learned gain"]

The math

Definition: RMS normalization

For a vector h in R^d, with a learned gain vector γ in R^d and a small constant ε > 0 for stability, RMSNorm produces

RMSNorm(h)j=γj hjRMS(h),RMS(h)=1d∑k=1dhk2+ε\mathrm{RMSNorm}(\mathbf{h})_j = \frac{\gamma_j\, h_j}{\mathrm{RMS}(\mathbf{h})}, \qquad \mathrm{RMS}(\mathbf{h}) = \sqrt{\frac{1}{d}\sum_{k=1}^{d} h_k^2 + \varepsilon}

Here h_j is the j-th entry of the input, and γ_j is the learned gain for that entry. The Zhang and Sennrich version has no learned offset, unlike layer normalization.

Step 2 in symbols

The mean square is ms = (1/d) Σ h_k². For h = [3, 4], d = 2, so ms = (9 + 16) / 2 = 12.5.

Step 3 in symbols

The root mean square is RMS = √(ms + ε). With ε set to 0 for this example, RMS = √12.5 ≈ 3.5355.

Step 4 in symbols

Each output entry is y_j = γ_j h_j / RMS. With γ = 1, y = [3 / 3.5355, 4 / 3.5355] ≈ [0.8485, 1.1314].

Why the output has mean square 1

When ε = 0 and γ = 1, the mean square of the output is

1d∑kyk2=1d∑khk2RMS2=msms=1\frac{1}{d}\sum_k y_k^2 = \frac{1}{d}\sum_k \frac{h_k^2}{\mathrm{RMS}^2} = \frac{\mathrm{ms}}{\mathrm{ms}} = 1

This is the check in step 6 of the walkthrough, written out in symbols.

Scale invariance

Multiplying the input by any positive constant c leaves the output unchanged, because c appears in both the numerator and the RMS. So RMSNorm(c·h) = RMSNorm(h) when ε is negligible. Layer normalization has the same property, and this is one reason both work well as the size of activations drifts during training.

Worked examples

Example
1. Tiny: an entry of zero

Input h = [0, 2], gain 1.

  1. Mean square: (0² + 2²) / 2 = 4 / 2 = 2.
  2. RMS: √2 ≈ 1.4142.
  3. Output: [0 / 1.4142, 2 / 1.4142] = [0, 1.4142].
  4. Check: the mean square of the output is (0 + 2) / 2 = 1.

Interpretation: the zero stays zero, and the nonzero entry is scaled so the vector's typical size is 1. Nothing was subtracted from it.

Example
2. Standard: the vector from the layer normalization lesson

Input h = [1, 2, 3, 6], gain 1 for each entry. This is the vector used in the Layer Normalization lesson, so the two results can be compared.

  1. Squares: [1, 4, 9, 36]. Sum 50.
  2. Mean square: 50 / 4 = 12.5.
  3. RMS: √12.5 ≈ 3.5355.
  4. Output: [1 / 3.5355, 2 / 3.5355, 3 / 3.5355, 6 / 3.5355] ≈ [0.2828, 0.5657, 0.8485, 1.6971].
  5. Compare with layer norm on the same vector, [-1.069, -0.535, 0, 1.604]. The RMS output is all positive, and its entries keep the offset of the original vector, because nothing was centred.
  6. Interpretation: the largest entry stays the largest, and the whole vector is shrunk by the same factor.
Example
3. Realistic: one token's hidden vector in a pre-norm block

A pre-norm transformer normalizes the hidden vector of each token before attention. Real models use a few thousand entries, and this example uses four so the arithmetic can be checked by hand. Input h = [2, -2, 4, 0], gain γ = [1, 1, 0.5, 1], and ε = 0.

  1. Squares: [4, 4, 16, 0]. Sum 24.
  2. Mean square: 24 / 4 = 6.
  3. RMS: √6 ≈ 2.4495.
  4. Divide each entry: [2 / 2.4495, -2 / 2.4495, 4 / 2.4495, 0] ≈ [0.8165, -0.8165, 1.6330, 0].
  5. Multiply by the gain: [0.8165 × 1, -0.8165 × 1, 1.6330 × 0.5, 0 × 1] = [0.8165, -0.8165, 0.8165, 0].
  6. Interpretation: the gain has halved the third entry after the normalization, so the learned gain, not the normalization, decides how strongly each feature enters the sub-layer. The zero stays zero.

Try it: the same gain γ = [1, 1, 0.5, 1], and input h = [1, 1, 1, 1]. What is the output? Answer: the mean square is 1 and the RMS is 1, so the normalized entries are all 1. Multiplying by the gain gives [1, 1, 0.5, 1].

Common mistakes and tradeoffs

It is tempting to think RMS normalization is layer normalization with a bug, so it must be worse. In fact it drops one reduction and one subtraction, and the original authors found it matched layer normalization on the tasks they tested, while running faster. Whether it matches in a given model is an empirical question.

It is tempting to think the output has mean zero, the way layer normalization does. In fact only the root mean square is fixed, at 1. If the input has a large offset, the output keeps most of that offset. The mean of the output is whatever the input's mean was, scaled down.

It is tempting to ignore ε. If a vector is nearly all zeros, the RMS is nearly zero, and dividing by it makes the entries explode. The small constant ε keeps the division safe.

It is tempting to think RMSNorm removes the problem of outliers. In fact one very large entry raises the RMS for the whole vector, and the other entries are squashed toward zero. This is the same weakness as layer normalization, covered in its tradeoffs, and the fix there, such as clipping, applies here too.

When to use it: large models with many normalization layers, where speed matters, and where the centre of the features does not carry useful information. When not to use it: small networks where the offset matters, or cases where the earlier layer norm lesson's centring is part of what the model relies on. Alternatives include Batch Normalization, which needs batch statistics and does not suit single-token generation, and layer normalization itself.

History

In 2016 Jimmy Lei Ba, Jamie Ryan Kiros and Geoffrey Hinton introduced layer normalization, which normalizes across the features of one example. It became the default in Transformer models after 2017.

In 2019 Biao Zhang and Rico Sennrich proposed RMS normalization as a simpler alternative. Their argument was that the re-centering in layer normalization contributes little to training, so it can be dropped to save computation. Their experiments supported that claim on the tasks they tried.

RMSNorm spread through large language models in the early 2020s, and open model families such as LLaMA adopted it as a standard component. Its cost advantage grew with model size, because the normalization runs in every layer for every token.

Recap

  • RMS normalization divides a vector by its root mean square, so the typical size of its entries becomes 1.
  • Unlike layer normalization, it does not subtract the mean, so it does one fewer pass over the data.
  • The learned gain then sets the scale of each entry.
  • The output is unchanged when the input is multiplied by a positive constant, which keeps activations stable as training changes their size.
  • Transformer models place it before attention and feedforward blocks, inside residual blocks.

Next, read the Transformer lesson to see where RMSNorm sits in a full block.

Check yourself

QuestionWhat does RMS normalization skip compared with layer normalization, and what does it not have?Show answer

It skips the mean subtraction (the centring step), so the output is not centred to mean zero. Compared with layer normalization it also has no learned offset, only the learned gain.

QuestionCompute RMSNorm of h = [3, 0, 4] with gain 1 and ε = 0.Show answer

The squares are 9, 0 and 16, summing to 25. The mean square is 25 / 3 ≈ 8.3333, and the RMS is √8.3333 ≈ 2.8868. The output is [3 / 2.8868, 0, 4 / 2.8868] ≈ [1.0392, 0, 1.3856].

QuestionWhy does multiplying the input by 10 leave the RMSNorm output unchanged?Show answer

Every entry is multiplied by 10, so the RMS is also multiplied by 10. The factor cancels in the division h_j / RMS(h). The only exception is when ε matters, which happens when the input is very small, because ε is added inside the square root and is not scaled.

QuestionA model's hidden vectors have one feature that is always far larger than the rest. Will RMSNorm fix the scale for the other features?Show answer

Not well. The one large feature dominates the mean square, so the RMS is large and the other features are divided by a large number, leaving them small. RMSNorm does not remove that outlier, so the fix has to come from elsewhere, for example by clipping or by changing the features that feed the layer.

Sources