Why does normalizing Q and K before the dot product help training at scale?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
QK-norm applies L2 normalization (or a learned scale) to the query and key vectors of every token before computing the attention score q · k. Why does this stabilize large-scale training? What problem in vanilla attention is it fixing, and what is the cost?
At scale, Q and K magnitudes drift up, softmax saturates, gradients die. L2-normalizing Q and K per token bounds the dot product to a stable range no matter how big the weights grow.
Picture turning up the volume on a microphone over months. At first the speakers sound balanced. After a year, the loud channel completely drowns out everything else, you only hear one voice, the rest are silent. That is what happens inside a long training run: the numbers the model uses to compare words slowly get bigger and bigger, until one word's vote completely buries everyone else's. The model stops learning from the silent voices and training stalls. QK-norm is a volume limiter that clamps every voice to a fixed loudness before they hit the mixer. The model can still pick winners, but never loud enough to silence the rest of the room.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Name the failure mode (softmax saturation), explain why sqrt(d_k) does not fix training-time drift, state the L2-norm + learnable scalar recipe, cite ViT-22B as the originating model.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Claiming sqrt(d_k) already prevents this. It fixes initialization-time variance only; it does not track Q and K growth during training, which is the source of the drift.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.