Learn AI Math

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.

DimensionMulti-Head Attention (MHA)Grouped-Query Attention (GQA)
KV heads1 KV pair per Query head1 KV pair shared per group of Query heads
KV cache memoryLarge—a bottleneck for long-context servingSeveral times smaller (e.g., 8× with 8 query heads per group), usually with little quality loss
AdoptionOriginal Transformer and many earlier LLMsCommon 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?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.