at decode time every token caches all history K/V, and memory grows linearly with sequence length: cache size
=2⋅2⋅L⋅H⋅d⋅s⋅b (2 bytes per fp16 element × K and V × layers × heads × head dim × seq len × batch); LLaMA-3 70B at
s=8192,
b=32 needs about 687GB with MHA — dwarfing its 140GB of weights — and about 86GB with GQA (8 groups), saving ~87%; MQA saves the most but degrades quality slightly, so it is mostly used in small models.