RMSNorm: keeping a token's scale under control
Root mean square layer normalisation (RMSNorm) controls vector scale. How does it work, and what does it simplify compared with LayerNorm?
Each residual addition keeps a token’s representation and adds another update. After many layers, the coordinates can arrive at quite different scales.
How can the next network read the pattern without having to cope with every change in its overall size?
Turn the whole vector down together
Imagine multiplying every coordinate by two. The proportions between them stay the same; the vector just gets larger.
We could divide all coordinates by one measure of the vector’s size. A larger input would then receive a larger divisor.
The measure used here is the root mean square: square the coordinates, average them, then take the square root.
Squaring lets positive and negative coordinates both contribute to the size. Dividing by that size rescales the vector together, keeping its pattern of signs and proportions.
That is the normalisation step of RMSNorm. It controls the vector’s overall size.
Change the scale, keep the pattern
Make the input larger below. Its colours become stronger, but compare the vector after normalisation.
The input grows, but its normalised pattern stays almost unchanged.
So far, every coordinate has received the same divisor. What if the model needs to make some coordinates more prominent than others?
Let the model choose the final balance
After normalising, multiply each coordinate by its own learned scale. The model can still emphasise some channels more than others.
Follow the two operations separately. The first rescales the whole vector. The second changes individual coordinates using learned weights.
Set all scales to 1 to see the second operation leave the normalised vector unchanged.
Some models store each scale as 1 plus a learned weight that starts at zero. The layer then begins as the plain normalisation, and training nudges the scales away from 1.
A small constant in the denominator keeps the calculation defined when the input is zero. The compact formula is:
The older LayerNorm does one more thing first: it subtracts the vector’s average, then divides by the spread around it, and adds a learned bias at the end. RMSNorm skips the average and the bias, which makes it cheaper and works about as well.
Read the pattern, keep the stream
Place RMSNorm before a branch, and that branch reads a normalised input to calculate its update.
Follow the green stream past each branch. RMSNorm changes the input read by the branch; the stream receives the branch’s update at the addition circle.
The norm can also sit on the branch output, changing which values are normalised before the residual addition.
Sources
Sources: RMSNorm paper, LayerNorm paper, Gemma implementation for scales stored as 1 plus a weight, Llama reference implementation, OLMo 2 implementation.