Zenaique

Define QK-norm and the training failure it prevents

Flashcard·Medium·4.0 · 0·~30s·Asked atCoreweaveTencent
Attempt it
TL;DR

QK-norm normalizes Q and K per head, after projection and before the dot product, bounding logit scale by construction so softmax cannot saturate as Q and K weight norms drift across long training.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a tug-of-war where the rope length is what gets multiplied to score the pull. Without QK-norm, the team captains can sneak in longer ropes during the match, and pretty soon any pull from one side counts as a million points. QK-norm cuts every rope to a fixed length before each round. The teams can still angle the rope, point it sharply, or pull harder, but raw length cannot blow up the score. Softmax stays sane, attention stays diverse, and the training run does not catch fire halfway through.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

QK-norm became one of the standard stability tools in the open-weights transformer toolkit between 2023 and 2026. The technique is small (one normalization layer per attention call) but the failure mode it prevents (attention logit explosion driven by Q and K weight drift) is one of the most commonly cited stability incidents in long pretraining runs at frontier scale.

Knowing QK-norm cold means knowing three things: where it sits in the attention block, what specifically it prevents, and how it compares with the adjacent technique of logit soft-capping. This is interview-grade material for any 2026 LLM engineering role.

The placement inside attention

QK-norm operates on the query and key tensors inside the attention computation. The standard order of operations in a multi-head attention block:

  1. Read residual stream x of shape (batch, seq, d_model).
  2. Apply input LayerNorm or RMSNorm (this is the pre-norm step, separate from QK-norm).
  3. Project to Q, K, V: Q = x @ W_Q, shape (batch, seq, n_heads, d_head). Same for K and V.
  4. QK-norm: apply RMSNorm to Q and K per head. This step is what we are defining.
  5. Apply RoPE rotation to Q and K (if RoPE is used).
  6. Dot product: scores = (Q @ K.transpose) / sqrt(d_head).
  7. Softmax to get attention weights.
  8. Weighted sum with V; output projection.

The norm is per-head, meaning each of the n_heads heads has its own RMSNorm operating along the d_head axis. The learnable gain is typically a (n_heads, d_head) or (n_heads,) tensor; some implementations omit the gain entirely for maximum bounding.

The placement matters. Norming the input to the projection (step 2 in the pre-norm step) controls input variance but not post-projection variance. Norming after projection but after RoPE is also viable. Norming inside the dot product or after softmax is not QK-norm; those are different techniques (logit soft-capping is a post-softmax intervention).

The failure mode it prevents
Why QK-norm fixes it structurally
Shipping models and the soft-capping comparison
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • ViT-22B (Google, 2023) introduced QK-norm to enable stable scaling of vision transformers to 22B parameters; the technique was identified as essential for stability at that scale.
  • Gemma 2 (Google, 2024) shipped QK-norm with RMSNorm together with logit soft-capping (`cap = 30` for attention, `cap = 50` for output) as a belt-and-suspenders stability stack.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QDoes QK-norm work with RoPE?
A

Yes; apply QK-norm to Q and K post-projection, then apply RoPE rotation, then compute the dot product. The norm fixes magnitudes; the rotation changes direction. ViT-22B uses learned position; Gemma 2 and OLMo 2 combine QK-norm with RoPE successfully.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Believing the `1/sqrt(d_k)` scaling already bounds logits. It corrects init-time variance only and cannot constrain weight growth across hundreds of thousands of steps.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Identify where QK-norm sits: after Q and K projections, before the dot product, per head

  • State which norm types are used (RMSNorm and LayerNorm both valid; RMSNorm is the frontier choice)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium