# Multi-Head Attention (MHA)

- **Canonical URL:** https://getaimath.com/dictionary/multi-head-attention-mha/
- **Topics:** [Transformer Architecture](https://getaimath.com/dictionary/category/transformer-architecture/)
- **Last updated:** 2026-11-25

## 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.

![Transformers & Attention: The Smart Highlighter — Simple cartoon diagram showing how a Transformer reads a whole sentence at once and shines a bright highlighter beam from the word "IT" back to "trophy" so it knows what "IT" means.](https://getaimath.com/diagrams/transformer-architecture.png)
*Napkin Diagram (Transformer Architecture): Older AI read word-by-word and often lost track of earlier words; a Transformer highlights which words connect to which.*

## What is an example of Multi-Head Attention (MHA)?

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)](https://getaimath.com/dictionary/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 |

## Related Concepts

- [Attention Mechanism](https://getaimath.com/dictionary/attention-mechanism/): An attention mechanism is a way for a model to focus on the most useful parts of its input when producing each piece of output.
- [Query (Q)](https://getaimath.com/dictionary/query-q/): In attention, the query is a list of numbers that represents what a word is looking for in other words.
- [Self-Attention](https://getaimath.com/dictionary/self-attention/): Self-attention lets every word in a sentence look at every other word and decide which ones matter most for understanding it.
- [Key (K)](https://getaimath.com/dictionary/key-k/): In attention, a key is a list of numbers that describes what a word offers, so queries can find it.
- [Transformer](https://getaimath.com/dictionary/transformer/): A Transformer is a type of neural network design that reads all the words in a passage at once and works out how they relate, using attention.
- [Value (V)](https://getaimath.com/dictionary/value-v/): In attention, a value is the actual information a word passes along when another word pays attention to it.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/multi-head-attention-mha/)
