Grouped-Query Attention (GQA) & KV Cache Optimization
Standard Multi-Head Attention (MHA) assigns independent Key and Value heads to every Query head, causing massive KV cache VRAM consumption during inference. Grouped-Query Attention groups multiple Query heads to share single Key/Value heads.
MHA vs. MQA vs. GQA
MHA: 1 Q head per 1 KV head (1:1 ratio). MQA: All Q heads share 1 KV head (N:1 ratio, extreme bandwidth saving, minor quality loss). GQA: G Query heads share 1 KV head (e.g. 8:1 ratio, optimal tradeoff).
KV Cache VRAM Reduction
With 8:1 GQA (e.g., 64 Q heads, 8 KV heads in Llama 3 70B), the KV cache footprint during generation drops by 87.5% (8x saving), allowing 8x larger batch sizes or context lengths.
Pre-Training Integration
GQA must be built into pre-training from step 0 so projections learn grouped representations.
Dividing KV head count by grouping factor G directly divides KV memory overhead by G.
- Llama 3 8B and 70B both use GQA with 8 KV heads, enabling fast multi-user serving on single GPU nodes.