ModelRefs / Multi-Head Attention (MHA) — AI Glossary

Multi-Head Attention (MHA) — AI Glossary

The core attention mechanism in transformers using multiple parallel attention heads to capture diverse relational patterns. Also called MHA or self-attention.

Overview

MHA (Vaswani et al. 2017) projects Q, K, V into h subspaces, computes scaled dot-product attention in each head, and concatenates results. Each head can specialize in different syntactic/semantic relations. MHA is O(n²d) per layer, motivating GQA, MQA, and sparse attention variants for long contexts.

Reference details

Topicarchitecture
Also known asMHA, self-attention
Last reviewed2026-06-24

Example: Where the heads and the quadratic term come from

A model with hidden size 4,096 and 32 heads gives each head 4,096 / 32 = 128 dimensions. Each head computes attention independently over the sequence, and the results are concatenated back to 4,096 — so heads cost no extra width, they partition it. The cost that does grow is the pairwise comparison: at a sequence length of 8,192 each head scores 8,192² ≈ 67 million query-key pairs, and that term is quadratic in length while everything else is linear. Doubling the context roughly quadruples that work, which is the pressure behind every attention variant.

Commonly confused with

Multi-head attention is the original formulation. GQA and MQA are not different attention mechanisms but different sharing schemes for the key and value projections — they cut KV-cache memory at inference, not the quadratic score computation. Sliding-window and sparse attention are what actually attack the quadratic term, by not computing all pairs.

When to use it

Reach for it when:

  • Reasoning about why long context costs what it does
  • Interpreting a model card's head count and hidden size as a memory and bandwidth statement
  • Understanding what GQA, MQA and windowed variants each trade away

Reach for something else when:

  • Assuming more heads means better quality — head count partitions a fixed width
  • Estimating inference memory from attention alone; the KV cache usually dominates
  • Treating attention weights as an explanation of the model's reasoning

Primary source

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Multi-Head Attention (MHA) — AI Glossary.

Frequently asked questions

What is Multi-Head Attention (MHA)?

The core attention mechanism in transformers using multiple parallel attention heads to capture diverse relational patterns.

Is Multi-Head Attention (MHA) the same as MHA?

Yes — MHA, self-attention are common aliases for Multi-Head Attention (MHA).

What concepts are related to Multi-Head Attention (MHA)?

Closely related concepts include attention, grouped query attention, cross attention.