[01-layer-normalization-forward]'s LayerNorm does two separate things: it CENTERS a position's feature vector (subtracts the mean) and it RESCALES it (divides by the standard deviation), before applying a learned gamma/beta. Zhang & Sennrich (2019) asked a pointed empirical question: how much of LayerNorm's benefit actually comes from the re-scaling, versus the re-centering? Their finding, since adopted by LLaMA, PaLM, Mistral, and most other modern large language models, was that the RESCALING is doing almost all of the useful work, and the mean-centering step can simply be dropped, with training stability and final model quality both essentially unaffected.
The result, RMSNorm, is a strictly SIMPLER, cheaper normalization: no mean to compute, no beta shift to learn, just a single division by the vector's own root-mean-square. Fewer operations per call, fewer parameters to learn, and (because it computes only ONE statistic instead of two) a meaningfully cheaper operation to run billions of times over during training and inference, a real, measurable cost saving at the scale modern LLMs run at.
Implement rmsnorm_forward(x, gamma, eps). Compute the root-mean-square of x along its LAST axis (sqrt(mean(x^2) + eps)), divide x by that value, then apply the learned per-feature multiplicative scale gamma (there is no beta, unlike [01-layer-normalization-forward]).
mean(x^2)), never the first (mean(x)).eps is added INSIDE the square root, exactly like [01-layer-normalization-forward], to avoid dividing by zero.beta parameter: the only learned parameter is the multiplicative gamma.[01-layer-normalization-forward].rms = np.sqrt(np.mean(x**2, axis=-1, keepdims=True) + eps). This is the ONLY statistic RMSNorm needs, no separate mean computation at all.
return gamma * (x / rms). Compare directly against [01-layer-normalization-forward]'s gamma * ((x - mean) / sqrt(var + eps)) + beta: RMSNorm is that formula with the - mean term and the + beta term both removed.
Click "Run Tests" to test your implementation