RMSNorm › Worked Example: Step-by-Step Numerical Trace
Language AI HandbookAll chapters RMSNorm › Worked Example: Step-by-Step Numerical TraceOne section · Sections in this chapter4 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before moving to code, let's trace through a complete numerical example of both LayerNorm and RMSNorm on a small vector. This gives you a concrete feel for the computations and reinforces the mathematical relationship we derived.
Suppose we have a small input vector with elements:
We'll normalize this vector with both methods and compare the results step by step.
Step 1: Compute the Statistics
First we compute the mean and the root mean square :
For the RMS, we first square each element: . The mean of these squares is:
So .
Let's verify the Pythagorean relationship. The variance is:
So . Now let's check: . The identity holds exactly.
Step 2: Apply LayerNorm
LayerNorm subtracts the mean, then divides by the standard deviation. Using (negligible here):
Dividing by :
With and , the LayerNorm output is . The output has mean exactly 0 and standard deviation exactly 1 (up to floating point precision).
Step 3: Apply RMSNorm
RMSNorm simply divides by the RMS, with no mean subtraction. Using :
With , the RMSNorm output is .
Step 4: Compare the Results
The two outputs differ because the mean is non-trivial relative to the standard deviation . Their ratio is , which is substantial. Using the geometric picture, this corresponds to a triangle with a large vertical leg relative to the horizontal leg, so the hypotenuse (RMS) differs noticeably from the horizontal leg ().
In a real transformer, the mean of activations is typically much smaller relative to the standard deviation. If we had and , then , which is indistinguishable from for practical purposes. This is the regime that justifies RMSNorm's approximation in practice.
Step 5: Verify the RMS Property
We can verify that the RMSNorm output has RMS equal to 1 (when ):
The output RMS equals 1.0 exactly (up to rounding), confirming that RMSNorm correctly normalizes the magnitude of the input vector to 1.