Scaled Dot-Product Attention is the core attention operator of the Transformer: Attention(Q,K,V)=softmax(dkQKT)V. Dividing by dk normalizes the dot-product variance: if Q and K have per-dimension variance 1, the variance of a dk-dim dot product grows linearly with dk; without scaling, softmax inputs saturate as dimensionality grows (e.g. dk=128, 128≈11.3) and gradients vanish.
💡Use Cases
every head softly matches all tokens in the sequence — the foundation for MHA/GQA/MLA, FlashAttention and RoPE; interviews typically start with "why divide by dk" and then probe complexity, masks and head splitting.
⚡Key Problems Solved
unlike unscaled dot products, scaling keeps softmax entropy and gradients stable at any dimensionality so deep networks train reliably; but time and memory stay O(n2), which becomes the main bottleneck for long sequences and motivates IO-aware implementations like FlashAttention.
🎯5 High-Frequency Exam Points
1
Why divide by dk? What breaks without it (variance analysis, softmax saturation)?
2
Time and space complexity of scaled dot-product attention? Why is O(n2) the long-context bottleneck?
3
Shapes of the Q/K/V projections? How are heads split and concatenated?
4
Difference and implementation of padding mask vs causal mask?
5
Single vs multi-head: why h heads rather than one wide d-dim head?