Search

Search papers and lessons

Root Mean Square Layer Normalization

Biao Zhang, Rico Sennrich · 2019

RMSNorm drops the mean-centring step from layer normalization and keeps only the rescaling, which made training 7% to 64% faster on the models tested with comparable quality.

On this page

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

TL;DR

Layer normalization makes deep networks train more reliably, but it costs time at every step. Zhang and Sennrich tested the idea that its usefulness comes from rescaling, not from centring. They propose RMSNorm, which divides each layer's inputs by their root mean square and skips the subtraction of the mean. On machine translation, image-caption retrieval, reading comprehension and CIFAR-10, RMSNorm matched layer normalization's quality and ran 7% to 64% faster, depending on the model.

Builds on: RMS Normalization, Layer Normalization, Mean and Variance · Leads to: RMSNorm as a drop-in replacement in later large language models (no lesson node yet)

Why it mattered

Layer normalization is the default normaliser in the Transformer, and RMSNorm has since been used as its replacement in several large language model families. The paper's main claim is that the same training benefit comes from a cheaper statistic. In one of the paper's timing comparisons, on an RNN translation model in Theano, the run took 988 seconds with layer normalization and 652 seconds with RMSNorm. The paper has about 2,300 citations on Semantic Scholar. The reason it spread is simple: a model that needs fewer operations per normalisation layer gets a speed-up without retraining its architecture.

The problem

A normaliser inside a network has to do two jobs. It keeps the scale of each layer's activations under control, so gradients stay in a sensible range. It also fixes the centre of the activations, so the next layer does not see a drifting mean. Layer normalization does both, using a mean and a variance computed over each example's own features.

That costs time. The mean needs a pass over the features, the variance needs a second pass, and the subtraction needs a third. For a small network the cost is negligible. For deep recurrent models, which normalise many times per token, the extra work can offset the faster convergence per step. A normaliser can win per step and still lose per second.

The question is which of the two jobs matters. The paper argues that the rescaling does, so the centring can go.

How it works

Take one layer whose summed inputs form the vector a = (a_1, ..., a_n). Here is the RMSNorm computation step by step, with a tiny vector.

  1. Start from the summed inputs. A layer computes a_i = sum over j of w_ij x_j, the weighted sum that feeds each neuron. Take a = (3, 4), so n = 2.
  2. Square each input. 3^2 = 9 and 4^2 = 16. Check: the two squares are 9 and 16.
  3. Average the squares. (9 + 16) / 2 = 12.5. Check: 12.5 is the mean of the squares.
  4. Take the square root. RMS(a) = sqrt(12.5) = 3.5355. This is the root mean square, a single number for the whole vector.
  5. Divide each input by the RMS, then apply the gain. a_bar_i = a_i / RMS(a) x g_i. With gains g = (1, 1), the output is (0.8485, 1.1314). Check: the RMS of the output is sqrt((0.7200 + 1.2800) / 2) = 1, so the output lies on a sphere of fixed size.
  6. Compare with layer normalization on the same vector. Layer normalization first subtracts the mean, (3 + 4) / 2 = 3.5, which gives deviations (-0.5, 0.5). Their variance is 0.25, so the standard deviation is 0.5, and the output is (-1, 1).
  7. Shift the same input and compare again. Take a = (13, 14). Layer normalization gives (-1, 1) again, because it removes the shift. RMSNorm gives (0.9622, 1.0362), which differs from step 5. So RMSNorm is not invariant to adding a constant to the inputs. That is the price of dropping centring.

The step-by-step idea, as a flow:

flowchart LR
  A[Summed inputs a] --> B[Square each input]
  B --> C[Mean of the squares]
  C --> D[Square root: RMS]
  D --> E[Divide a by RMS]
  E --> F[Multiply by gain g]
  F --> G[Normalised output]

The graph below shows the two normalisers on a family of inputs. Inputs with the same spread but different sizes give the same output under RMSNorm, but the output moves under a shift if the mean is not removed.

0.511.522.533.5400.511.52first input a_1, with a_2 = 1first normalised output
  • RMSNorm, first output
For the input (a_1, 1), RMSNorm's first output rises from 1 at a_1 = 1 toward sqrt(2) as a_1 grows. Layer normalization gives (1, -1) for every a_1 other than 1, because with two inputs it removes the mean and rescales the deviations to unit size.

The math

The paper's notation uses a for the summed inputs and g for the gain. Here it is with the symbols named in words.

Definition: Root mean square normalisation

For a vector of summed inputs a with n entries, the root mean square is RMS(a) = sqrt((1/n) sum over i of a_i^2). RMSNorm outputs a_bar_i = (a_i / RMS(a)) g_i, where g is a learned gain vector, initialised to ones.

Step 4 in symbols

For the vector (3, 4), RMS(a) = sqrt((3^2 + 4^2)/2) = sqrt(12.5) = 3.5355. The statistic is a single scalar per example, so it costs one sum of squares, one division and one square root, and no mean is needed.

Step 5 in symbols

Dividing by RMS(a) puts the vector on a sphere whose radius is sqrt(n), so its root mean square is 1 whatever the size of the input. This is why the output RMS is 1 when the gain is 1, and it does not depend on the layer's width once the factor sqrt(n) is accounted for.

Step 6 in symbols

Layer normalization uses mu = (1/n) sum over i of a_i and sigma = sqrt((1/n) sum over i of (a_i - mu)^2), then sets a_bar_i = ((a_i - mu) / sigma) g_i. When the mean mu is zero, the two methods are the same, because sigma and RMS(a) then coincide.

Step 7 in symbols

The rescaling invariance follows from homogeneity of the RMS: RMS(alpha a) = alpha RMS(a) for any positive scale alpha. So if the inputs are multiplied by alpha, the output does not change. Shifting the inputs by a constant c gives RMS(a + c), which is not equal to RMS(a) + c in general, so the output changes. RMSNorm keeps the rescaling invariance and loses the re-centring invariance.

The partial version

The paper also proposes pRMSNorm, which estimates the RMS from only the first k = ceil(n p) entries of a. The paper uses p = 6.25%. It keeps the rescaling invariance, and it can be faster, but the estimate is biased, because it uses only part of the vector.

Results

The paper tests RMSNorm against layer normalization on several tasks: machine translation (RNN and Transformer models), image-caption retrieval, reading comprehension and CIFAR-10 classification. The pattern is the same on each. Quality is close to layer normalization's, often within a few tenths of a point on the task metric, and the training time per run is lower. The overall range the paper reports is 7% to 64% faster, depending on the model and framework. The exact per-task numbers are in the paper's tables; read those from the source rather than from this summary.

Limits. Two effects are confounded in the speed numbers: the arithmetic saved, and the framework's implementation. The paper notes that pRMSNorm is sometimes slower, because tensor slicing is not well optimised in these frameworks. The tasks are mostly sequence models from 2019, and the quality results are close: differences of a fraction of a BLEU point are within the spread the paper reports. The paper also does not give a theory for why centring is unnecessary; it is an empirical claim supported by the invariance analysis.

Misreadings to avoid. RMSNorm is not a different normalisation of the batch: it works on one example's features, like layer normalization, so it does not depend on the batch size. It is also not the same as dividing by the Euclidean norm, which the paper found did not work.

Reading guide

Check yourself

QuestionIn one sentence, what does RMSNorm divide each input by, and what does it not subtract?Show answer

It divides each summed input by the root mean square of the whole vector, a single number, and it does not subtract the mean of the inputs.

QuestionCompute RMSNorm of the vector (6, 8), with all gains equal to 1.Show answer

The squares are 36 and 64, their mean is (36 + 64)/2 = 50, and the square root is RMS = sqrt(50) = 7.0711. The output is (6/7.0711, 8/7.0711) = (0.8485, 1.1314). Check: this matches the output for (3, 4), because (6, 8) is (3, 4) scaled by 2, and RMSNorm is invariant to that rescaling.

QuestionWhy does the paper's invariance argument mean RMSNorm is cheaper than layer normalization on each step?Show answer

RMSNorm needs one reduction over the inputs, a sum of squares. Layer normalization also needs the mean, which is a separate reduction, and it subtracts the mean from every input before computing the variance. Dropping the mean removes one pass over the features and the subtraction.

QuestionA model uses RMSNorm with inputs shifted by a large constant. Why might its outputs differ from layer normalization's, and what does that cost?Show answer

Layer normalization removes the shift, so its output is unchanged. RMSNorm divides by an RMS that includes the shift, so its output changes. This is the re-centring invariance the paper gives up. Whether that costs anything depends on the task, and the paper's experiments are the test of it: the claim is that the quality stayed close to layer normalization's.

QuestionOn the Theano translation model, layer normalization took 988 seconds and RMSNorm took 652 seconds. What is the percentage saving?Show answer

The saving is (988 - 652) / 988 = 336 / 988 = 0.340, so about 34.0%. So the saving on that run is about 34%.

Sources

Read the full paper

Biao Zhang, Rico Sennrich, 2019. arXiv:1910.07467