Why does scaled dot-product attention divide by √d_k?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
To keep the softmax from saturating. If the components of q and k are roughly independent with zero mean and unit variance, their dot product q·k is a sum of d_k terms and has variance ≈ d_k - so the standard deviation of the logits grows like √d_k. With d_k = 128, unscaled logits routinely reach magnitudes of ±20 or more.
Full worked answer
To keep the softmax from saturating. If the components of q and k are roughly independent with zero mean and unit variance, their dot product q·k is a sum of d_k terms and has variance ≈ d_k - so the standard deviation of the logits grows like √d_k. With d_k = 128, unscaled logits routinely reach magnitudes of ±20 or more.
Softmax of large-magnitude logits collapses to nearly one-hot: one attention weight ≈ 1, the rest ≈ 0. In that regime the softmax's Jacobian is nearly zero (the gradient of softmax involves p·(1−p) terms, which vanish as p → 0 or 1), so almost no gradient flows back through the attention scores. Early in training that means the attention layers barely learn; it can also cause loss spikes and instability. Dividing by √d_k renormalizes the logit variance back to ~1 regardless of head dimension, keeping the softmax in a regime with usable gradients and appropriately soft attention distributions.
Two points that distinguish a strong answer:
- It's a variance argument about initialization/training dynamics, not a mathematical requirement - the model could in principle learn scaled-down projections, but starting saturated makes optimisation much harder.
- The same idea shows up elsewhere: logit soft-capping in some models (bounding attention or final logits with tanh) and QK-norm (applying LayerNorm/RMSNorm to queries and keys before the dot product, used in several modern architectures) attack the same failure mode - attention logits growing without bound during training - more aggressively than the static √d_k scale.
A concrete way to phrase the intuition: √d_k scaling makes the temperature of the attention softmax independent of head size, so architecture choices about head_dim don't silently change how peaked attention is.
What a good answer covers
- To keep the softmax from saturating
- If the components of q and k are roughly independent with zero mean and unit variance, their dot product…
- With d_k = 128, unscaled logits routinely reach magnitudes of ±20 or more
- Softmax of large-magnitude logits collapses to nearly one-hot: one attention weight ≈ 1, the rest ≈ 0
- In that regime the softmax's Jacobian is nearly zero (the gradient of softmax involves p·(1−p) terms,…
Key terms: soft-capping · QK-norm
In the glossary: Attention · LayerNorm · RMSNorm · Temperature
Interviewer follow-ups to expect
What is QK-norm and why did some recent models adopt it?
- It's a variance argument about initialization/training dynamics, not a mathematical requirement - the model could in principle learn scaled-down projections, but starting saturated makes optimisation much harder.
- The same idea shows up elsewhere: logit soft-capping in some models (bounding attention or final logits with tanh) and QK-norm (applying LayerNorm/RMSNorm to queries and keys before the dot product, used in several modern architectures) attack the same failure mode - attention logits growing without bound during training - more aggressively than the static √d_k scale.
What happens to gradients when softmax saturates - walk me through the Jacobian?
Would you expect scaling issues to be worse with larger or smaller head dimensions?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep