What is the quality-versus-memory trade-off among MHA, GQA, and MQA?
Last updated
The variants differ only in the number of key/value (KV) heads: MHA has one per query head (best quality, largest KV cache), MQA shares one across all heads (smallest cache, some quality loss and less stable training).
GQA uses G groups of shared KV heads, shrinking the cache by H/G (Llama 2 70B: 64 query heads, 8 KV heads). It gets near-MHA quality at near-MQA speed and is the modern default.
Smaller caches matter because decoding is memory-bandwidth bound: fewer KV heads means faster tokens/s and room for bigger batches or longer contexts.