Scaled dot-product attention, multi-head structure, and grouped-query attention (GQA).
Steps:
Instead of single attention, we use multiple parallel attention heads:
For Llama-70B: 64 query heads, each with dhead=128.
GQA reduces KV-cache by sharing K/V heads across multiple query heads:
| Type | Q Heads | KV Heads | KV per token |
|---|---|---|---|
| MHA | 64 | 64 | 16 KB/layer |
| GQA (Llama-70B) | 64 | 8 | 2 KB/layer |
| MQA | 64 | 1 | 256 B/layer |
For the illustrated 64-query-head / 8-KV-head geometry, GQA reduces KV-head storage by 8× relative to MHA with 64 KV heads. Quality impact is model- and training-dependent and is not measured here.