Multi-Head Attention (MHA)
What is Multi-Head Attention (MHA)?
In one sentence: Multi-head attention runs several attention processes side by side, so the model can notice different kinds of relationships at once.
Each "head" is like a different reader with a different focus. One head might track grammar, another might track who did what, and another might track topics. Their results are then combined into one richer understanding.
What does Multi-Head Attention (MHA) look like?
In "Sara gave Tom her book," one head might link "her" to "Sara" while another links "book" to "gave."
Why does Multi-Head Attention (MHA) matter?
Multiple heads let models understand language in many ways at the same time.
Multi-Head Attention (MHA) vs. Grouped-Query Attention (GQA)
MHA gives every query head its own key and value heads; GQA lets a group of query heads share one key/value pair, which shrinks the KV cache a lot at long context.
| Dimension | Multi-Head Attention (MHA) | Grouped-Query Attention (GQA) |
|---|---|---|
| KV heads | 1 KV pair per Query head | 1 KV pair shared per group of Query heads |
| KV cache memory | Large—a bottleneck for long-context serving | Several times smaller (e.g., 8× with 8 query heads per group), usually with little quality loss |
| Adoption | Original Transformer and many earlier LLMs | Common in modern open models such as Llama 3, Qwen and Mistral |
Last updated · Fact-checked by The AI Math
Linking to this page from a lesson or article? <a href="https://getaimath.com/dictionary/multi-head-attention-mha/">Multi-Head Attention (MHA), explained simply</a> (The AI Math Dictionary)