See how much context fits in the KV cache.
KV-cache memory grows linearly with resident tokens and concurrent sequences. Change attention geometry, precision and the memory budget to see when context becomes the constraint.
KV-cache memory scales with the tokens that remain resident.
Per token. In standard decoder attention, every layer retains one key and one value per KV head. Head dimension is hidden_size / attention_heads.
Context and concurrency. Total memory then multiplies by the number of tokens in each sequence and by the number of sequences resident at the same time.
GQA and MQA. Fewer KV heads reduce cache memory in the same proportion, independently of precision or context length. The chart compares the selected geometry with full MHA using the same query-head count.
Budget. The memory limit applies only to KV cache. It is not total VRAM: weights, activations, CUDA graphs, buffers and other reserves must be subtracted first. Use the AI Inference VRAM Calculator to model the full deployment budget.
This approximation does not model MLA, hybrid/sliding-window attention, recurrent state, backend-specific paging/fragmentation or compressed caches. Validate those deployments against real serving-engine metrics.
Primary sources: Meta · Llama architecture definitions, Meta · Llama 3.1 model card, and vLLM · KV-cache configuration. Verified 2026-08-21.