How do you pick the head dimension ?
hardAnswer
- Common choice: (so total FLOPs match a single-head version with hidden dim d). too small (< 32) → heads can't represent complex relationships; too large (> 128) → wastes parameters on redundancy.
- Typical: .
- Grouped-query attention (GQA, MQA) share K/V across groups of heads to reduce KV cache without hurting quality much.
Check yourself — multiple choice
- is fixed at 1
- typically; too small underfits, too big wastes params; GQA/MQA share K/V to save KV cache
- can only be 512
- Doesn't matter
≈ 64-128 typical; GQA/MQA share K/V to cut inference memory.
#attention#transformers
Practise Deep Learning
214 interview questions in this topic.
Related questions
- How does self-attention work in a transformer?
- Describe a single transformer encoder block in detail.
- How does a decoder block differ from an encoder block?
- Why is attention scaled by 1/sqrt(d_k)?
- Why multi-head attention instead of a single big head?
- Why is standard self-attention O(n²) in sequence length?