RMSNorm › Mathematical Connection Between RMS and Standard Deviation
Language AI HandbookAll chapters RMSNorm › Mathematical Connection Between RMS and Standard DeviationOne section · Sections in this chapter3 / 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
We've claimed that RMSNorm works because activations in neural networks tend to be near-centered. But how near is near enough? To answer this precisely, we need to understand the mathematical relationship between what RMSNorm computes (the RMS) and what LayerNorm computes (the standard deviation). If the two quantities are nearly identical under typical transformer conditions, then the two normalizations are nearly identical in their effect.
This section derives the exact connection between these two quantities. The derivation is worth following carefully because it reveals a beautiful geometric relationship and tells us exactly when the two normalizations diverge. Understanding this relationship gives you the theoretical confidence to choose RMSNorm over LayerNorm: you will know precisely the conditions under which the choice matters and when it does not.
The key insight is that RMS and standard deviation are related through a Pythagorean identity involving the mean. This identity makes the trade-off perfectly precise: the larger the mean of the activations, the more the two normalizations differ. Conversely, when the mean is small relative to the standard deviation, the two normalizations are nearly interchangeable.
The Goal: Relating RMS to Standard Deviation
We want to express in terms of (the standard deviation) and (the mean). If we can do this, we'll know how much the two normalizations differ based on the mean alone.
Start with the definition of variance, which measures how spread out values are around their mean. The variance is defined as the average squared deviation from the mean:
where:
- : the variance of the input vector, measuring spread around the mean
- : the number of elements in the vector
- : the -th element of the input vector
- : the mean of the input elements, equal to
This formula takes each element, measures its distance from the mean, squares that distance, and averages all the squared distances. The square root of variance gives us the standard deviation , which has the same units as the original data.
Step-by-Step Derivation
Our strategy is to expand the variance formula and recognize familiar terms. We'll use the algebraic identity to expand the squared term:
Now we can distribute the sum across the three terms. Each term gets its own summation:
Let's simplify each term:
- First term: is the mean of squared values. This is exactly .
- Second term: The sum equals by the definition of mean. So this term becomes .
- Third term: We're summing the constant exactly times, so this equals .
Substituting these simplifications:
Rearranging to isolate the RMS:
Taking square roots of both sides:
where:
- : the root mean square of the input vector
- : the standard deviation of the input vector (spread around the mean)
- : the mean of the input vector (location of the center)
Why does this formula make sense? Notice that the RMS combines information about both the mean and the spread of the distribution. The standard deviation only captures spread: it measures how far values deviate from their center. The mean captures location: it measures where the center is. The RMS captures both because it measures distance from zero, not from the mean. A vector with large mean but small variance still has large RMS.
The Geometric Interpretation
This formula has a beautiful geometric meaning. Think of and as the two legs of a right triangle. The RMS is the hypotenuse. The Pythagorean theorem tells us that , which is exactly what we derived.
Think of it this way: if you draw a 2D coordinate system where the horizontal axis represents "standard deviation" and the vertical axis represents "mean," then any distribution maps to a point at coordinates . The RMS is the distance from the origin to that point, the length of the line segment from to . LayerNorm normalizes by the horizontal coordinate (divides by ). RMSNorm normalizes by the diagonal distance from the origin (divides by ). When the vertical coordinate (the mean) is small, these two quantities are nearly identical.

This geometric picture immediately reveals when RMSNorm and LayerNorm behave similarly:
- When : The triangle collapses to a line. The hypotenuse equals the remaining leg: . The two normalizations are identical.
- When is small relative to : The triangle is nearly flat. The hypotenuse is only slightly longer than . The normalizations are nearly equivalent.
- When is comparable to or larger than : The triangle is more equilateral or tall. The hypotenuse differs significantly from . The normalizations diverge.
The practical question becomes: in real neural networks, how large is compared to ? The simulation we ran earlier gave us the empirical answer: means are very small relative to standard deviations in well-initialized transformers, placing us firmly in the "nearly flat triangle" regime.
import numpy as np
def layer_norm(x, gamma, eps=1e-6):
"""Standard layer normalization with centering."""
mu = np.mean(x, axis=-1, keepdims=True)
var = np.var(x, axis=-1, keepdims=True)
x_norm = (x - mu) / np.sqrt(var + eps)
return gamma * x_norm
def rms_norm(x, gamma, eps=1e-6):
"""RMSNorm without centering."""
rms = np.sqrt(np.mean(x**2, axis=-1, keepdims=True))
x_norm = x / (rms + eps)
return gamma * x_norm
# Generate random activations (typical neural network values)
d = 256 # Hidden dimension
batch_size = 32
# Simulate activations after a linear layer + activation
activations = np.random.randn(batch_size, d) * 0.5 + 0.1 # Small positive bias
gamma = np.ones(d) # Identity scaling for comparisonInput statistics (per sample): Mean magnitude: 0.1053 Std deviation: 0.4904 RMS value: 0.5022 Comparison of LayerNorm vs RMSNorm outputs: Mean absolute difference: 0.209557 Max absolute difference: 0.444943 Correlation: 0.998802
The outputs are highly correlated but not identical. The differences arise from the mean subtraction in LayerNorm. Let's visualize how the two normalizations compare across different input distributions.
# Test with different mean magnitudes
mean_offsets = [0.0, 0.5, 1.0, 2.0, 5.0]
results = []
for offset in mean_offsets:
x = np.random.randn(1000, d) * 0.5 + offset
ln_out = layer_norm(x, gamma)
rms_out = rms_norm(x, gamma)
# Compute RMS difference
rms_diff = np.sqrt(np.mean((ln_out - rms_out) ** 2))
# Compute statistics
input_mean = np.mean(np.abs(np.mean(x, axis=-1)))
input_std = np.mean(np.std(x, axis=-1))
results.append(
{
"offset": offset,
"input_mean": input_mean,
"input_std": input_std,
"rms_difference": rms_diff,
}
)
The key insight emerges: when inputs are approximately centered (mean near zero), the two normalizations are nearly equivalent. In deep neural networks with proper initialization and residual connections, activations tend to stay roughly centered. This explains why RMSNorm works as well as LayerNorm in practice.