Equations · Zhang and Sennrich, “Root Mean Square Layer Normalization” (2019); used in LLaMA and most recent LLMs
The RMSNorm formula, explained
A cheaper LayerNorm: divide by the root mean square of the features and apply a learned gain. It skips subtracting the mean and has no shift.
Term by term
The root of the mean of the squares: a measure of the vector's typical size.
The -th entry, squared.
A small constant for numerical safety. The paper's formula has none; implementations such as LLaMA's add it inside the root.
A learned per-feature gain, applied elementwise.
A small worked example
: mean of squares , , so the output is about times the gain. LayerNorm would give : it also re-centres.
In code
import numpy as np
def rms_norm(x, g, eps=1e-6):
rms = np.sqrt(np.mean(x**2, -1, keepdims=True) + eps)
return x / rms * gEvery symbol in it
Square rootSummationFractionSubscript (index or label)Superscript (power or label)EpsilonHadamard (elementwise) productBold lowercase (vector)
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)