From 300KB to 69KB per Token: How LLM Architectures Solve the KV Cache Problem
TL;DR Highlight
Moving from MHA to GQA to MLA cut KV cache from 300 KiB to 68.6 KiB per token.
Who Should Read
A backend developer worried about GPU memory and API costs in long-context or long-conversation LLM services.
Core Mechanics
- KV cache is real GPU memory
- Each token's key and value vectors are stored on the GPU and reused.
- This avoids recomputing all earlier tokens for every new token.
- GPT-2 costs 300 KiB per token in Raschka's comparison, so a 4,000-token chat uses about 1.2 GB for the cache alone.
- Cache size per token differs by architecture
- GPT-2 (MHA) is 300 KiB, Llama 3 (GQA) is 128 KiB, and DeepSeek V3 (MLA) is 68.6 KiB.
- GQA lets several query heads share keys and values.
- MLA compresses keys and values into a low-dimensional latent space and decompresses them at inference.
- Gemma 3 looks closely only at recent context
- It adds a sliding window to GQA with a 5:1 ratio of local to global layers.
- Local layers attend to only 1,024 tokens.
- The article says ablations (experiments removing components) showed almost no perplexity loss.
- Mamba-style SSMs drop the cache entirely
- A fixed-size hidden state is updated per token, so memory doesn't grow.
- The model must decide what to compress in real time.
- The article says SSMs haven't displaced transformers at the frontier.
- When the cache is evicted, it gets rebuilt
- KV cache is working memory that lasts seconds to minutes, and the GPU reclaims it when needed.
- The article attributes the pause when reopening an old chat to cache rebuilding.
- The article cites prompt caching discounts of 50% for OpenAI and 90% for Anthropic.
- There is no medium-term memory between cache and weights
- RAG, files, vector DBs and system prompts act as bridges over that gap.
- When the cache grows too large, compaction has the model summarize its context, and details get lost.
- Cursor trains compaction with RL and reports better results on a coding benchmark.
Community Reactions
- A commenter corrected the caching discount figure
- They said OpenAI's cache-hit discount is 90%, not 50%.
- They linked OpenAI's official pricing docs as evidence.
- Experience quantizing the KV cache directly
- In llama.cpp, q8 keys and q4 values reportedly roughly halve cache memory again on top of GQA or MLA savings.
- The commenter runs Qwen 70B 4-bit on an M2 Max 96GB and said this made longer contexts fit.
- They explained that keys need more precision because they drive attention scores, while values tolerate lossy compression.
- Pushback that the article blurs distinct layers into one 'memory'
- A commenter said KV cache, prompt caching, saved memory, retrieval and summarization are different mechanisms.
- They argued the cache never becomes a summary; the app replaces old text with a shorter prompt.
- They said standard responses are systems tricks like limits, eviction, paging/offload and compression.
- Research and a production case on KV cache compression
- One comment pointed to Cartridges, which optimizes the KV cache with gradient descent while freezing the network.
- Another said Edgee caches prompt-compression outputs in a globally distributed KV store.
- They noted compression results for similar contexts are reusable across sessions.
How to Apply
- Pin your prompt prefix and check cache hit rate
- Put the system prompt and static documents first and user input last in today's API calls.
- Log the cached-token count from the usage field and compare.
- Per the article, OpenAI caches automatically while Anthropic lets you set breakpoints.
- Test whether key facts survive compaction
- Plant specifics like six rules or an exact dollar amount in a long conversation and have it summarized.
- Compare the summary against the original values.
- Store anything that goes missing in a file or DB instead of trusting the summary.
- Enable KV cache quantization if you self-host
- In llama.cpp, set keys to q8 and values to q4 and measure memory use at long context.
- Check quality loss on your own eval set.
- Compare per-token KV cache size when choosing a model
- Multiply concurrent requests and context length by KiB per token to budget GPU memory.
- GQA and MLA families may fit longer contexts or more concurrent requests in the same memory.
Try It
# Paste into Claude or ChatGPT (simplified version of the paper's method: check whether compaction loses details)
Process {{long conversation or document}} in this order.
1. Summarize it to 20% of the original length.
2. Extract every number, proper noun, rule, and constraint from the original as a list.
3. Compare in a table whether each item survived in the summary. (item / present in summary / altered / missing)
4. List the altered or missing items as 'pinned facts' that must be stored outside the summary.
{{long conversation or document}}Terminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls