LLM & Transformer Fundamentals·Question 30 of 109Intermediate

What are MQA and GQA, and why do they exist?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

They exist because of KV cache memory. In standard multi-head attention (MHA), every one of h heads has its own K and V projections, so the cache stores h keys and h values per token per layer. Cache size - not FLOPs - is the binding constraint on serving throughput: it determines how many concurrent sequences fit on a GPU (batch size), and decode speed is bounded by streaming the cache from HBM every step. Cutting KV heads attacks both.

Full worked answer with diagram

They exist because of KV cache memory. In standard multi-head attention (MHA), every one of h heads has its own K and V projections, so the cache stores h keys and h values per token per layer. Cache size - not FLOPs - is the binding constraint on serving throughput: it determines how many concurrent sequences fit on a GPU (batch size), and decode speed is bounded by streaming the cache from HBM every step. Cutting KV heads attacks both.

MQA (multi-query attention), from Shazeer's "Fast Transformer Decoding: One Write-Head is All You Need": keep h query heads but share a single K/V head across all of them. Cache shrinks by h× (e.g. 32×), decode bandwidth drops proportionally. Cost: measurable quality regression on some tasks, and training can be less stable - one K/V representation has to serve every query head's needs.

GQA (grouped-query attention), Ainslie et al.: the interpolation. Partition the h query heads into g groups, each group sharing one K/V head - e.g. Llama-style 70B models use 64 query heads with 8 KV heads (groups of 8). Cache shrinks 8×, and quality is empirically near-indistinguishable from MHA. The GQA paper also showed you can uptrain an existing MHA checkpoint into GQA by mean-pooling its K/V heads and continuing training briefly - you don't need to pretrain from scratch. GQA has been the default in most open models since 2023 (Llama 2/3 large variants, Mistral, Qwen...), with MLA as the main alternative in the DeepSeek and Kimi lineages.

Concrete impact: a 70B-class model at fp16 with 80 layers and head_dim 128 stores ~2.6 MB/token with 64 KV heads versus ~320 KB/token with 8 - the difference between fitting ~4 and ~30+ long sequences in the same memory.

The natural follow-on is MLA (multi-head latent attention, DeepSeek): compress K/V into a shared low-rank latent vector per token and reconstruct per-head K/V from it - cutting cache further while increasing effective head diversity versus GQA. Worth mentioning to show you know where this design line went.

Worth sketching. Query heads on one side, KV heads on the other: the sharing ratio is the entire design space.

flowchart TD
    Q1["MHA: 32 query heads"] --> KV1["32 KV heads<br/>largest cache, best quality"]
    Q2["MQA: 32 query heads"] --> KV2["1 shared KV head<br/>32x smaller, measurable quality cost"]
    Q3["GQA: 32 query heads in 8 groups"] --> KV3["8 KV heads<br/>8x smaller, quality near MHA"]
    KV3 --> MLA["MLA: cache one latent per token,<br/>rebuild per-head K and V from it"]

What a good answer covers

  • They exist because of KV cache memory
  • In standard multi-head attention (MHA), every one of h heads has its own K and V projections, so the…
  • Cache size - not FLOPs - is the binding constraint on serving throughput
  • MQA (multi-query attention), from Shazeer's "Fast Transformer Decoding
  • Cache shrinks by h× (e.g

Key terms: MQA (multi-query attention) · single · GQA (grouped-query attention) · uptrain · MLA

Interviewer follow-ups to expect

  1. Why is decode throughput bounded by memory bandwidth, and how does GQA change the arithmetic?

  2. How does the GQA uptraining recipe work?

  3. What does MLA do differently?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep