AIToday
Large Language ModelsQiita 機械学習Published: Oct 13, 2026, 22:00 JST

Explainer: KV キャッシュ cuts recomputation but eats memory

Explainer: KV キャッシュ cuts recomputation but eats memory

3 Key Points

  1. What happened

    The explainer states that an LLM predicts one next token at a time, and that instead of recomputing past tokens' Key and Value vectors each step, it stores and reuses them as the KV キャッシュ.

  2. Why it matters

    Saving that stored data spares the work of rebuilding it, but the saved data itself mounts up as text gets longer and more requests run at once, which is given as the main reason an LLM becomes heavy.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, in your inbox every morning.

Context & Analysis

The piece is written for readers who keep meeting terms like "KV cache" and "prefill / decode" in LLM news and want to hold the machine in their heads once with small numbers. It builds the picture from the bottom: each token becomes a list of numbers (an embedding), Attention mixes in information from related words, and an FFN processes each word separately, with those two blocks stacked 32 to 100 times. Query, Key and Value are introduced as a library search — Query is the search word, Key is each book's title, Value is the book's contents — and the same single example sentence runs through the whole calculation.

The memory cost gets a concrete shape. The explainer gives the KV cache size as 2 (K and V) × layers × KV heads × head dimension × bytes per element × tokens × simultaneous requests, and works it out for Llama 3.1 8B (32 layers, 8 KV heads, dimension 128, up to 128K tokens) in FP16: 128 KiB per token, 1 GiB at 8K tokens, 16 GiB at 128K tokens, which it notes is about the same as the FP16 model itself, and ten times that with 10 simultaneous requests.

It then maps the fixes that show up in news coverage back to that formula — GQA / MQA (sharing K and V across Query heads), quantizing the cache from FP16 to FP8 / INT4, vLLM's PagedAttention, sliding windows that discard old tokens, and DeepSeek's MLA, which compresses K and V. Prompt caching in the Claude and OpenAI APIs is described as reusing this same cache across requests, which is why an identical prefix at the start is what makes reuse possible.

FAQ
What exactly does the KV キャッシュ save?
It saves the past tokens' Key and Value vectors and the layer computations that produce them. The explainer says attention itself — comparing the new token's Query against all past Keys — cannot be skipped.
How big can the KV キャッシュ get?
For Llama 3.1 8B in FP16 with one simultaneous request, the explainer gives 128 KiB per token, 1 GiB at 8K tokens and 16 GiB at 128K tokens — roughly the same as the FP16 model itself, and ten times that with 10 simultaneous requests.
What is the difference between prefill and decode?
Prefill computes the whole prompt at once and puts every token's Key and Value vectors into the cache. Decode computes only the one new token's Key and Value per step and adds them to the cache.
Qiita 機械学習Read Original Article

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleDesigning an incident response mode for AI agents