Zenaique

Diagnose attention logit explosion in a large run and defend QK-norm as the fix

Short answer·Hard·4.0 · 0·~3 min·Asked atFractal AnalyticsMercorWipro
Attempt it

Halfway through a long pretraining run on a 30B model, monitoring shows max attention logits trending from ~20 to over 100, attention entropy in several heads dropping toward zero, and intermittent loss spikes that recoveries only partially undo. Diagnose what is happening mechanically, explain why the 1/sqrt(head_dim) scaling did not prevent it, and argue for QK-norm versus logit soft capping as interventions.

Free · 2 AI evals / day
TL;DR

Q and K weight norms drift upward across long training, inflating QK logits, saturating softmax, and collapsing attention entropy. The `1/sqrt(d_k)` factor only corrects init-time variance, not learned weight growth.

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

Imagine a microphone with a volume knob and a hard clip. At the start of recording, the gain is tuned so voices sit nicely in the dynamic range. Over hours, the gain knob slowly drifts up on its own. Voices that started at conversational level are now shouting and the recorder clips. Two ways to fix it: install a volume governor at the input that holds the gain constant (QK-norm) or put a brick-wall limiter on the output that clamps anything above a threshold (soft-capping). The governor prevents the problem; the limiter masks it. You usually want the governor, but if the show is already live, you reach for the limiter.

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.

Attention logit explosion is one of the most cited stability failures in long pretraining runs at frontier scale. The pattern is consistent enough across reported incidents that the 2025-2026 open-weights community has converged on QK-norm as the structural fix, and the question's symptoms (entropy collapse, intermittent loss spikes, logits trending past 100) are diagnostic for exactly this pathology.

The value of the question is not in naming QK-norm. It is in walking the full chain from learned weight drift, through the softmax saturation mechanism, to the choice between structural fix and symptomatic patch, with an honest tradeoff between mid-flight feasibility and from-scratch architectural cleanliness.

The cascade: weight drift to entropy collapse

Start with the attention computation: s_ij = (q_i . k_j) / sqrt(d_k), then a_ij = softmax(s_ij), then output o_i = sum_j a_ij * v_j.

At initialization, Q and K projection weights have entries with standard deviation around 1/sqrt(d_model), so post-projection Q and K vectors have approximately unit-variance entries. The dot product q . k has variance d_k, and the 1/sqrt(d_k) factor brings logits back to O(1). Softmax distributes attention smoothly. Entropy per head is healthy (typically log(seq_len) minus a small amount).

Across hundreds of thousands of steps with Adam updating Q and K projections, weight norms drift. There is no explicit constraint preventing this; Adam normalizes step direction by gradient magnitude but does not bound parameter magnitudes. Weight decay slows growth but does not prevent it entirely, especially when the loss landscape rewards larger Q and K norms (which it does in the early-to-mid training regime, where sharper attention helps).

By 200k-500k steps, Q and K weight Frobenius norms can be 3-10x their initial values. Post-projection q and k vectors have norms 3-10x larger than at init. Dot products q . k grow by 9-100x. Logits s_ij = (q . k) / sqrt(d_k) follow.

Once logits reach magnitude 30-50, softmax begins saturating. By 80-100, several heads have one-hot attention. Entropy collapses. Loss spikes intermittently. In bf16, exp of large logits risks overflow.

This is the failure mode the monitoring is showing. The fix needs to break the link between Q/K weight drift and logit magnitude.

Why the canonical `1/sqrt(d_k)` is structurally insufficient
QK-norm: the structural fix
Soft-capping: the symptom clamp
The mid-flight versus from-scratch tradeoff
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.

  • Gemma 2 (Google, 2024) shipped both QK-norm and logit soft-capping (`cap = 30` for self-attention, `cap = 50` for final logits) as belt-and-suspenders stability measures.
  • Gemma 3 (Google, 2025) kept QK-norm and refined soft-capping; the combination is the production recipe for the Gemma line.
Sign in to see more production examples.

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

QCould you replace QK-norm with simple weight decay on `W_Q` and `W_K`?
A

Partially. Weight decay slows the drift but does not bound the post-projection vector norms structurally. The relationship between decay strength and effective logit scale is indirect and depends on optimizer state; QK-norm gives a structural guarantee.

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 `1/sqrt(d_k)` permanently bounds logits. It is a constant scalar that handles init-time variance only; it does nothing when learned weight magnitudes drift.

Sign in to see all red flags and common mistakes.

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

  • Trace the mechanism: weight drift inflates QK, softmax saturates, entropy collapses, gradients spike

  • Explain why 1/sqrt(d_k) is an init-time correction, not a runtime bound

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