What Is KV Cache in LLMs? Prefill, VRAM & Offloading
The KV cache stores previously computed attention Key and Value tensors in GPU VRAM so LLMs do not recompute the entire prompt on every token. Learn prefill vs. decode, API prompt caching, FP8/NVFP4 quantization, and tiered offloading.

THE STORY IN THREE POINTS
- Core definition: the Key-Value (KV) cache stores previously computed transformer attention Key and Value vectors in GPU VRAM so decoding the Nth token reads cached states instead of recomputing all prior tokens—trading memory capacity for speed without changing model intelligence.
- Why long contexts cause OOMs: model weights load once at startup, whereas KV cache scales linearly with both sequence length and concurrent users—causing 6GB checkpoints to run out of VRAM under 32K contexts or multi-tenant bursts.
- Four serving breakthroughs: PagedAttention (eliminating contiguous fragmentation), RadixAttention prefix trees, FP8/NVFP4 KV quantization (halving footprint per step), and CPU/NVMe offloading (NVIDIA Dynamo, LMCache, DeepSeek DualPath).
What is KV cache? Runtime scratchpad trading VRAM for attention speed
The KV cache (Key-Value cache) is the temporary GPU memory buffer a transformer language model maintains during inference to store previously computed self-attention Key and Value tensors for every token across every decoder layer, preventing the engine from re-reading and recomputing the entire conversation history every time it emits one new token.
Without a KV cache, generating the 10,000th token in a coding session would force the GPU to recalculate projections across all 9,999 preceding tokens on that single step—turning 30-turn agent threads into quadratic multi-million-token compute loops. As MindStudio and ExplainX emphasize, the KV cache holds internal numerical vectors (not readable plaintext), is separate from downloaded model weights, and does not raise output intelligence—full caching produces outputs mathematically identical to uncached recomputation.
Prefill vs. decode: why KV cache drives VRAM limits and token speed
Every inference request traverses two hardware phases that stress opposite GPU bottlenecks. During prefill, the GPU processes your entire input prompt in parallel, computing and writing Key and Value tensors for every prompt token into VRAM—a compute-bound step limited by tensor-core FLOPS. During decode, the model emits one token per step, computing only the newest Query vector while reading every cached Key and Value from VRAM—making generation strictly memory-bandwidth and capacity bound.
Because each generated token appends another Key-Value slice to the cache, memory grows linearly with both active sequence length and concurrent sessions (ExplainX). That explains why a model whose weights occupy only 6 GB can still crash with CUDA out-of-memory errors when handling 32K contexts or eight parallel agents: weights load once, while KV cache expands dynamically per user.
In-request KV cache vs. API prompt caching: what differs?
Developers frequently conflate in-request KV caching inside a serving engine with API prompt caching billed by OpenAI, Anthropic, Google, and DeepSeek. As Respan’s KV-cache analysis clarifies, both mechanisms operate on the exact same Key and Value attention tensors; the critical difference is cache lifetime.
Standard KV cache lives inside GPU VRAM strictly for the lifetime of one request and gets reclaimed once generation completes. Prefix or prompt caching keeps those computed KV blocks resident across separate turns (for 5-minute, 1-hour, or longer TTL windows) so subsequent requests sharing an unchanged prompt prefix skip prefill altogether. In Respan’s H100 benchmark running Qwen3-8B under vLLM 0.33, reusing cached prefixes cut 100K-token prompt read latency from 7.55 seconds down to 0.14 seconds—provided immutable instructions stay fixed at the top, as detailed in our Prompt Caching setup guide.
Four techniques modern engines use to tame KV cache footprint
Once agent context ceilings hit 256K to 1M tokens, raw FP16/BF16 KV blocks outgrew single GPUs—driving modern runtimes such as vLLM, SGLang, TensorRT-LLM, and DeepInfer to layer four complementary optimizations documented in NVIDIA’s KV Cache Glossary. First, PagedAttention allocates KV memory in small fixed-size non-contiguous pages rather than giant monolithic buffers, eliminating VRAM fragmentation and enabling high concurrent batching.
Second, Prefix Tree Sharing (RadixAttention)—explored in our SGLang vs. vLLM comparison—stores shared system prompts and repository definitions once in a radix tree so ten concurrent agents read a single copy. Third, KV cache quantization compresses tensors from 16-bit BF16 to FP8 (cutting memory by 50%) and NVIDIA’s NVFP4 format (halving footprint another 50% compared to FP8, doubling batch capacity). Fourth, tiered offloading via NVIDIA Dynamo, LMCache, and DeepSeek DualPath streams cold KV blocks to CPU RAM or NVMe SSDs instead of evicting idle agent state.
Practical impact on concurrency, --max-model-len, and local speed
Understanding KV cache mechanics demystifies three everyday performance symptoms across local and datacenter runners. First, concurrency scales dramatically with prefix reuse: MindStudio notes that running eight concurrent agents on a single GPU without prefix caching can stall near 1 turn per minute each, whereas enabling shared KV prefix caching raises throughput roughly sevenfold toward 7 turns per minute on identical hardware.
Second, overly generous context flags directly trigger startup OOMs: setting --max-model-len or OLLAMA_CONTEXT_LENGTH to 256K when prompts average 16K reserves unnecessary KV blocks—diagnosed step by step in our vLLM OOM fix guide and Ollama 4K context guide. Third, single-user decode speed tracks HBM or GDDR7 memory bandwidth rather than peak compute FLOPS, because every emitted token streams the full active KV cache from memory.
What happens when KV cache fills up—and lossy compression limits
Model architecture directly determines how quickly VRAM saturates before quantization even starts. Legacy Multi-Head Attention checkpoints consume hundreds of kilobytes per token, whereas Multi-head Latent Attention (MLA) and Causal Encoder-Decoder layouts—such as DeepSeek V4.1-Flash compressing global KV storage to 890 bytes per token—dramatically extend how many parallel 100K-token coding threads fit on one GPU node.
When burst concurrency still fills every allocated KV block on a server, requests either wait in scheduler queues, offload cold prefix state to host RAM, or suffer RECOMPUTE preemption in engines like vLLM V1—throwing away previously computed attention states and causing sudden tail-latency spikes across queued users.
Keep one accuracy boundary in mind when tuning memory: standard lossless KV caching and conservative FP8 quantization preserve baseline generation quality across typical coding tasks, whereas aggressive lossy token eviction or extreme sub-4-bit KV compression can degrade needle-in-a-haystack recall across multi-hundred-thousand-token prompts—making benchmark verification mandatory before tightening production cache ratios.
Sources: KV Cache Explained for LLM Agents|MindStudio ↗ What Is KV Cache in LLM Inference? (2026 Guide)|ExplainX ↗ KV Cache vs. Prompt Caching & 100K Latency Benchmarks|Respan ↗ KV Cache Technical Glossary (FP8, NVFP4 & Offloading)|NVIDIA ↗
THE BROADER CONTEXT · FRONTIER LABS DOSSIER
Explore full product specifications, pricing analysis, and continuous coverage in the Frontier Labs Desk Hub and Others Dossier. Independent benchmarks available on the AI Intelligence Index and Coding Agents Leaderboard.


