How does grouped-query attention differ from multi-head attention and multi-query attention?
Last updated
All keep H query heads and differ in key/value heads: MHA has H, MQA has 1 shared, GQA has G each shared by H/G query heads (G = H is MHA, G = 1 is MQA).
MQA shrinks the KV cache H× but can hurt quality and stability. GQA cuts it by H/G with near-MHA quality (Llama 2 70B, Llama 3, Mistral) and can be uptrained from an MHA checkpoint.
Attention FLOPs barely change. The win is KV cache size and memory bandwidth during decoding, enabling larger batches and longer contexts.