Walk through how a token's d_model embedding is split into per-head pieces inside multi-head attention.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
After the Q, K, V projections produce d_model-wide vectors, a reshape + transpose splits each vector into (num_heads, d_head), a tensor view, not a copy.
Picture a long candy bar. You can cut it into 8 equal pieces or call it one bar with 8 labeled sections; the candy is the same either way. Multi-head attention does the second thing. The token vector is one long buffer in memory, and the model just relabels contiguous chunks of it as 'this part is head 1, this part is head 2', and so on. Nothing is copied or duplicated. Each head then does its own small attention computation on its slice, and the model concatenates the slices back together at the end.
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.
Trace the shape transformations from x through QKV projection, reshape, transpose, per-head attention, concat, and W_O. Highlight that the split is a view, name the GQA/MQA variations, and end with why per-head softmax is the real reason multi-head wins.
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.
Believing each head has its own private d_model-wide projection. The projections produce one d_model vector that is then sliced into per-head pieces.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.