KatInterview

Dropping the Mean: RMSNorm Versus LayerNorm in Transformers

Machine LearningModel answer
MediumModel answerMachine Learningtransformersnormalizationlayernorm

Last updated

Contrast LayerNorm and RMSNorm formulas, what removing centering changes, and why many large language models adopt the simpler normalization.

Many recent large language models replace LayerNorm with RMSNorm inside their transformer blocks. Explain the difference between the two.

Your answer should:

  1. Write out both operations for the hidden vector of a single token, using the usual definitions: LayerNorm with a learned scale and bias, RMSNorm with a learned scale only.
  2. Describe what is lost, and what is kept, when the mean-subtraction step is removed.
  3. Argue why RMSNorm can be an appealing choice in practice, and where that argument is weaker than it first sounds.

Assumptions

  • Normalization runs across the hidden (feature) dimension of one token, not across the batch or the sequence.
  • Details such as whether a bias is present, where epsilon goes, and the precision used for reductions differ between codebases. State the choices you make.

Points worth clarifying up front

  • Which axis is being normalized?
  • Is there a learned bias?
  • Is normalization applied before the sublayer (pre-norm) or after it (post-norm)?
  • In what precision are the reductions computed?

Hints

Hint 1

Write both formulas side by side for a vector x of dimension d. Which statistics does each need: mean, variance, or only a mean of squares?

Hint 2

Think about which transformations of the input each layer is invariant to. Rescaling x by a constant affects both similarly; adding a constant to every feature affects them differently.

Hint 3

Consider cost versus benefit: how much of a transformer block's time is spent in normalization, and is it compute-bound or memory-bound? Also consider reduction precision in bf16/fp16.