firehose> #llmops

KV Cache and Paged Attention: Why LLM Serving Is Memory-Bound

TL;DR

When an LLM deployment falls over at 100 concurrent users, the video argues the model is almost never the culprit — GPU memory management during inference is. Inference splits into a compute-bound prefill phase (process the whole prompt, produce the first token) and a memory-bound decode phase (emit one token at a time, re-reading the whole context from VRAM each step). The KV cache is what makes decode tractable — it stores the key/value matrices of every prior token so the 1000th token doesn't recompute the first 999 — and it is explicitly a memory-for-compute trade. That trade then creates the real bottleneck: naive serving pre-allocates one contiguous VRAM block per request sized to the maximum possible output length, so a request that could use 300 tokens holds 2048, and the video states research shows 60–80% of KV cache memory is wasted to internal fragmentation, external fragmentation, and duplicated system prompts. Paged attention (from vLLM) fixes this by lifting a fifty-year-old OS idea wholesale: break the KV cache into fixed 16-token pages, let them live anywhere in VRAM non-contiguously, and keep a lightweight block table mapping logical → physical pages. Once memory is paged and blocks are hashed by token sequence, prefix caching falls out for free — requests sharing a system prompt point at the same physical pages. The operator payload is three vLLM flags (--gpu-memory-utilization, --enable-prefix-caching, --enable-chunked-prefill) plus speculative decoding as a latency-only bonus, all framed as "more throughput out of a GPU you already have."

Concepts introduced

Held, not dropped (touched by the capture, no concept page yet — spin out on demand):

Key claims

Why this builds on Prompt Caching

The vault already holds Prompt Caching, written from Anthropic's Claude Cookbooks — an API-consumer's view: mark a stable prefix as cacheable, order stable-first/volatile-last, pay less and wait less. Its aliases already include "prefix caching" and "KV cache reuse", which is the tell: the existing page names the technique by its effect and takes the mechanism on faith.

This capture supplies the mechanism from underneath, and it is not a decoration — it explains the existing page's rules rather than restating them:

So: builds_on Prompt Caching, novel with respect to everything else — the vault had no representation of the serving layer (prefill/decode, VRAM budgeting, fragmentation, speculative decoding) at all. Two independent sources (Anthropic's cookbooks, IBM's vLLM explainer) now converge on prefix reuse being the single biggest inference-economics lever, arriving from opposite directions — one from the API surface, one from the allocator. That convergence is worth recording: it is the same claim reached without shared assumptions.

One genuine tension worth naming, though not a contradicts against any page: Prompt Caching presents cache reuse as an unqualified structural saving ("recomputing an identical prefix on every call is pure waste"). This capture makes the price visible — the KV cache is a memory-for-compute trade, and cached prefixes occupy physical VRAM pages that could otherwise hold concurrent requests. At the API boundary the trade is invisible because someone else is paying it. Anyone running their own serving stack pays it directly, and the --gpu-memory-utilization knob is exactly where that bill arrives.

Illustrated walkthrough

A caveat on faithfulness: the transcript is auto-generated captions and garbles several terms. "Page detention" is paged attention; "A140 gigabyte card" is an A100 40 GB; "the LLM project" is the vLLM project; "Ingram" is n-gram; "KVQ" is K, V, Q; "LLM imprints" is LLM inference. Reconstructions below are marked where they were needed.


Linked from