productinterview.tools
MenuClose

What Is the KV Cache? LLM Serving Memory Explained

Stored attention keys and values for every token so far, so the model doesn't recompute them for each new token; it often limits how many conversations a GPU can serve.

1 min read
On this page
  1. How it works
  2. The numbers
  3. Why it matters, by role
  4. How interviews test it
  5. Common confusions
  6. Related concepts
  7. Sources

How it works

  • While generating, each new token attends to all earlier tokens.
  • Keeping their keys and values in memory avoids recomputing them every step.
  • The cache grows with conversation length and with the number of conversations served at once.

Full lesson: AI numbers: serving, cost and latency.

The numbers

  • Per token ≈ 2 × layers × KV heads × head size × bytes.
  • For a 70B-class model (80 layers, 8 KV heads of 128, 16-bit): ≈ 330 KB per token; ≈ 1.3 GB for a 4,000-token conversation.

Why it matters, by role

  • AI Infrastructure PMProduct Manager. Decides what a product should do, for whom, and why. Read the full explanation: Sizes capacity and cost per user.
  • AI TPMTechnical Program Manager. Owns plans, dependencies, risks and delivery for large cross-team programmes. Read the full explanation: Drives hardware planning.
  • AI Platform PM: Explains why long contexts cost more.

How interviews test it

Common confusions

  • "It fits" counting only weights, forgetting the cache.
  • The KV cacheKey-value cache. Stored attention keys and values that let a model generate each new token without recomputing the whole context. Read the full explanation is not a response cache; it doesn't reuse answers between users.
  • Prompt (prefix) caching reuses part of it across requests with identical openings.

Sources