Skip to content

Modern LLM serving: prefix caching, prefill/decode disaggregation and KV-cache compression

Skip →Compute-optimal test-time scaling
LLM stage 2 #9corefrontierpaperrubric 11/122023 · NeurIPS 2024 · ~60 min

Lianmin Zheng, Liangsheng Yin, Zhiqiang Xie, …, Ying Sheng

Read first: Efficient Memory Management for Large Language Model Serving with PagedAttention · GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints

Status

TL;DR. A serving engine runs two very different jobs. Prefill reads the whole prompt in one pass and is limited by compute; decode emits one token per step and is limited by how fast memory can be read. Four ideas from 2023–24 papers shape current engines. (1) Prefix caching: SGLang’s RadixAttention keeps the key-value (KV) cache of finished requests in a radix tree, so a system prompt, few-shot block or chat history is computed once and reused while the prefix remains cached. The complete SGLang system, including frontend and constrained-decoding optimisations, reports up to 6.4× throughput over its evaluated baselines. (2) Chunked prefill: Sarathi-Serve splits long prompts into chunks that ride along with running decodes, so decodes never stall. (3) Prefill/decode (PD) disaggregation: DistServe, and DeepSeek-V3 with 32-GPU prefill and 320-GPU decode units, run the two phases on different GPUs. (4) KV compression: grouped-query attention (GQA), multi-head latent attention (MLA) and 2-bit KV quantisation (KIVI) shrink the cache that decode must read.

Why it matters for you. Agents, RAG readers and RL rollouts re-send long, mostly identical prompts thousands of times. Whether those prompts are recomputed or reused decides time to first token and GPU cost. SGLang and vLLM are the main rollout engines in open RL frameworks.

Sources. Besides SGLang: Sarathi-Serve, DistServe, KIVI, FlashAttention-3 and the DeepSeek-V3 report.

First read. Read the TL;DR, “Two phases”, “Metrics”, “RadixAttention”, the two worked examples and “Disaggregation”. Skip on a first read: SGLang’s frontend language and API speculative execution (§2, §5), the proof of Theorem 3.1 (App. A.3), DistServe’s placement algorithms (§4), FlashAttention-3’s kernel details, and DeepSeek-V3’s expert-placement details.

Plain words first. A GPU can do arithmetic much faster than it can fetch numbers from its main high-bandwidth memory (HBM). An operation is compute-bound if it does many operations per byte fetched, and memory-bound if it mostly waits for bytes. The ratio is the arithmetic intensity.

A FLOP is one floating-point operation; a multiply and an add count as two. BF16 is a 16-bit floating-point format, so one value occupies two bytes. We first model weight reads only, ignoring activation traffic, communication and launch overhead.

For a linear layer with a d×dd \times d weight in bf16 (2 bytes per number) applied to nn tokens at once:

intensity=FLOPsbytes≈2nd22d2=n(n≪d).\text{intensity} = \frac{\text{FLOPs}}{\text{bytes}} \approx \frac{2 n d^2}{2 d^2} = n \quad (n \ll d).

So intensity is roughly the number of tokens processed together. Sarathi-Serve (§3.1, Fig. 5) puts the switch to compute-bound at about 200 tokens in theory on an A100, and 500–600 in practice with tensor parallelism.

  • Prefill processes thousands of prompt tokens together: compute-bound. Its latency sets TTFT.
  • Decode processes one token per sequence. A batch of 32 sequences gives n=32n = 32: memory-bound. Batching helps because one weight read is shared by all sequences in the batch.
  • But KV reads do not amortise. Attention can run as one batched kernel, but different sequences normally need different K/V reads every step. Adding independent sequences therefore does not amortise KV traffic the way it amortises shared weight reads. (Shared-prefix reuse inside a specialised attention kernel is a separate optimisation.) This is why the KV cache, not the weights, becomes the decode bottleneck at long context.
MetricDefinitionWhat hurts it
TTFT (time to first token)arrival → first output token: queueing + prefilllong prompts, queueing behind other prefills
TPOT (time per output token)average gap between output tokens after the first (DistServe)big decode batches, prefills mixed into decode steps
TBT / ITL (time between tokens, inter-token latency)each individual gap; Sarathi reports P99 TBT“generation stalls” when a long prefill joins the batch
Throughputtokens or requests per second, all userssmall batches
Goodputhighest request rate per GPU at which ≥ X% (e.g. 90%) of requests meet both TTFT and TPOT SLOs (service-level objectives)anything above, plus over-provisioning

Total latency is about TTFT + TPOT × (output tokens). Goodput is the metric to optimise: a system with high raw throughput that misses the TPOT SLO for 30% of users is worth little. DistServe’s Figure 1 makes this concrete for a 13B model on one A100: colocated serving sustains about 1.6 requests/s within both SLOs, while a prefill-only GPU sustains 5.6 and a decode-only GPU 10. Ideally, two prefill GPUs plus one decode GPU serve 10 requests/s, i.e. 3.3 per GPU, 2.1× better (an idealised allocation calculation, not a separately measured run).

IR analogy. This is the latency/throughput tension of a search engine’s query-serving tier: you size replicas for a P99 latency target, not for peak queries per second.

Old servers batched whole requests: the batch ran until its longest request finished. Orca’s iteration-level (continuous) batching lets requests join and leave at every decode step, and vLLM’s paging (see PagedAttention) makes the memory for that cheap. The catch (Sarathi §3.2): when a new request’s long prefill is admitted, every running decode in that iteration waits for it. Sarathi calls this a generation stall; naive mixing of a full prefill with decodes raised TBT up to 28.3× (Fig. 9).

Plain words. A token’s keys and values depend only on the tokens before it. Two requests that start with the same tokens therefore have identical KV for that prefix. Older engines threw a request’s KV away when it finished. SGLang keeps it and looks it up next time, like a web cache keyed by token prefix.

Data structure. A radix tree is a trie whose edges carry whole token sequences rather than single tokens. Each node points to the KV pages for its edge; pages are one token long, stored non-contiguously (§3).

Two more details matter in practice. The tree lives on the CPU; with no reuse at all, its upkeep took 0.2 s of a 74.3 s run (under 0.3%, §6.3), so it is on by default. For data parallelism, a router keeps a meta-tree of which worker holds which prefixes and sends each request to the worker with the longest match (App. A.4), much as a search engine routes queries to replicas with warm caches.

Why this matters for your workloads.

  • Multi-turn chat and agents: every turn re-sends the whole history; only the new turn is prefilled.
  • RAG with shared instructions: the instruction block and few-shot examples are shared. Passages are shared only if they appear at the same position after the same text, so put stable content first and the query last.
  • RL rollouts: GRPO samples G answers per prompt, and multi-turn agent rollouts grow one step at a time. Both are prefix trees. One caveat follows from “KV depends on weights”: every policy update invalidates the whole cache.

Structured outputs, briefly. SGLang also speeds up constrained decoding (e.g. JSON matching a regex). The regex becomes a finite-state machine; wherever only one continuation is possible (such as a fixed key name), consecutive transitions are merged so that whole string is added in one forward pass instead of token by token. This gave 1.6× throughput on JSON decoding (§6.3). Caveat (App. B.3): jumping over forced text can distort the probabilities of the choices that follow.

Worked example 1: how big is the KV cache?

Section titled “Worked example 1: how big is the KV cache?”

Formula. Per token, each layer stores one key and one value vector per KV head:

KV bytes=2×L×nkv×dh×b×T×B,\text{KV bytes} = 2 \times L \times n_{kv} \times d_h \times b \times T \times B,

with LL layers, nkvn_{kv} KV heads, head size dhd_h, bb bytes per number, TT tokens per sequence and BB sequences.

A 70B-class GQA model (Llama 3 70B shape: L=80L = 80, 64 query heads, nkv=8n_{kv} = 8, dh=8192/64=128d_h = 8192/64 = 128), bf16, T=32,768T = 32{,}768, B=16B = 16:

StepValue
Per token2 × 80 × 8 × 128 × 2 B = 327,680 B = 320 KiB
Per 32K sequence320 KiB × 32,768 = 10 GiB
Batch of 16160 GiB (≈172 GB), versus ≈140 GB of bf16 weights
Same model with full multi-head attention (64 KV heads)8× more: 1.25 TiB
MLA at DeepSeek-V3 sizes (61 layers, 512 + 64 cached numbers per layer), bf16(512 + 64) × 61 × 2 B ≈ 68.6 KiB/token → ≈34 GiB for the batch (a different model; shown for scale)
KIVI 2-bit, if each group of 32 numbers also stores an fp16 scale and zero-point≈ 3 bits per number → ≈30 GiB

Read-off. At this context and batch the cache is larger than the model, and every decode step reads all of it. Shrinking the cache directly shortens each step and lets more sequences fit. The options, in order of how invasive they are:

  1. Fewer KV heads (GQA) or a low-rank latent (MLA): architectural, decided at pretraining.
  2. Quantise the cache (KIVI, below): works on an existing model.
  3. Offload cold prefixes to CPU memory or disk and fetch them on a hit. SGLang lists extending RadixAttention down the memory hierarchy as future work (§8); the trade is PCIe transfer time against recomputation.

Worked example 2: prefix-cache savings for an agent

Section titled “Worked example 2: prefix-cache savings for an agent”

Assume an empty cache, no evictions, a fixed model and identical tokenisation. Step 1 sends a 6,000-token system prompt. Between each pair of successive steps (nine transitions for 10 steps), append 500 new tool-output tokens; every step resends the full history. Ignore model-generated tokens in the arithmetic, but assume any generated prefixes are retained.

  • Prompt at step kk: 6000+500(k−1)6000 + 500(k-1) tokens. Total over 10 steps: 60,000+500×45=82,50060{,}000 + 500 \times 45 = 82{,}500 tokens.
  • No cache: prefill all 82,500.
  • Radix cache, cold: 6,000 at step 1, then 500 per step: 10,500 tokens. Hit rate =72,000/82,500≈87%= 72{,}000 / 82{,}500 \approx 87\%.
  • System prompt already cached by other tasks: 4,500 tokens; hit rate ≈ 94.5%.
  • Step 10 alone: 10,500-token prompt, 500 new tokens, so the number of token positions whose representations must be computed falls 21×. That is roughly a 21× cut in tokenwise projection and MLP FLOPs, not a latency prediction: the 500 new queries still attend over the cached history (with ideal causal attention, query–key pairs fall only about 10.8×, from 55.1M to 5.1M), smaller matrices may run less efficiently, and queueing and scheduling also contribute to TTFT.
  • Memory: the shared 6,000-token prefix costs 6,000 × 320 KiB ≈ 1.83 GiB on the 70B model once, rather than once per concurrent agent; 16 agents save ≈27.5 GiB.

One careless change, such as a timestamp or request ID in the system prompt, creates a new branch at the first differing token; only the unchanged prefix before that position remains reusable. Reuse falls to zero only if the first token changes and there is no other common prefix.

  • End to end (§6.2): up to 6.4× higher throughput and 3.7× lower latency than vLLM v0.2.5, Guidance and LMQL across MMLU, HellaSwag, ReAct and generative agents, tree- and skeleton-of-thought, LLM judges, JSON decoding, multi-turn chat and a DSPy RAG pipeline (Llama-7B on an A10G; similar trends for Mixtral-8x7B and Llama-70B with tensor parallelism).
  • Hit rates were 50–99%, and cache-aware scheduling reached 96% of the optimal hit rate on average.
  • Where it does not help: multi-turn chat with long outputs got almost no speed-up, because decoding dominates and different sessions share little.
  • Production (Chatbot Arena, one month): 52.4% hit rate for LLaVA-NeXT-34B and 74.1% for Vicuna-33B, cutting first-token latency 1.7× on average for Vicuna-33B.
  • Ablation (Fig. 8c): removing the tree (flat table), cache-aware scheduling (FCFS or random), frontend parallelism or frontend hints each lowers throughput.

Idea. Decode steps leave compute idle (low intensity). Fill that idle compute with a slice of someone’s prefill, sized so the step still meets the TBT target.

Stall-free batching (Algorithm 3). Choose a token budget τ per iteration from a one-time profile and the TBT SLO. Each iteration: add every running decode (1 token each), then the next chunk of any partly done prefill, then admit new requests, each chunk cut to fit what is left of τ. Decodes never wait for a full prefill.

Costs.

  • Each chunk’s attention re-reads the KV of all earlier chunks; DistServe counts N+(N−1)+⋯+1=O(N2)N + (N-1) + \dots + 1 = O(N^2) chunk loads for NN chunks. Sarathi finds attention prefill still compute-bound at small chunks, with at most ≈25% extra prefill time at chunk 512 on Yi-34B and almost none at 2048 (§5.4.1).
  • Matmul tiles: a 257-token chunk can be 32% slower than 256 (§4.3), so budgets should be multiples of the kernel tile size.
  • Results: 2.6× more serving capacity than vLLM for Mistral-7B on one A100, up to 3.7× for Yi-34B on two A100s, up to 5.6× end to end for Falcon-180B with pipeline parallelism. Budgets were 512 (strict SLO) and 2048 (relaxed). In Table 4 (Yi-34B, two A100s, budget 1024), the combination improves both metrics relative to chunking alone, but trades some TTFT for much better TBT relative to hybrid batching alone. On openchat_sharegpt4, hybrid-only gives P50 TTFT/P99 TBT of 0.53/0.68 s, chunking-only 1.04/0.17 s, and Sarathi-Serve 0.76/0.14 s; on arxiv_summarization the combined TTFT (3.90 s) is slightly worse than hybrid-only (3.78 s).

Why colocation hurts. In one engine, prefill and decode (1) interfere: adding one prefill to a decode batch slows both (DistServe Fig. 2), and (2) are forced to share one parallelism plan and one GPU count, even though prefill wants low latency for TTFT and decode wants big batches within TPOT.

DistServe’s fix. Put prefill and decode on different GPUs. Size each pool and pick each pool’s parallelism separately to maximise per-GPU goodput. For intuition, assume Poisson arrivals at rate RR, identical prompts taking DD seconds, one first-come-first-served (FCFS) worker, no batching, and utilisation RD<1RD < 1. This is an M/D/1 queue, so average TTFT =D+RD22(1−RD)= D + \dfrac{R D^2}{2(1 - RD)}: the first term is execution, the second is queueing. This explains why intra-operator (tensor) parallelism, which cuts DD, wins at low load, and inter-operator (pipeline) parallelism, which raises capacity, wins at high load. Because real prompt lengths and service times vary, DistServe itself then chooses configurations with workload-aware profiling and simulation (§3–4).

The price: moving the KV cache. After prefill, the request’s whole KV cache must reach a decode GPU.

  • DistServe’s example (§3.3): one 512-token OPT-66B request has ≈1.13 GB of KV; at 10 requests/s that is 90 Gbps.
  • For the 70B GQA model above, an 8K-token prompt is 8,192 × 320 KiB = 2.5 GiB; at 4 requests/s, ≈86 Gbps.
  • DistServe’s testbed had only 25 Gbps between nodes, so it places each prefill stage and its decode stage on the same node and moves KV over NVLink (600 GB/s between A100s). Transfer was under 0.1% of total latency for OPT-175B, and over 95% of requests waited under 30 ms (§6.3).
  • Decode workers pull KV when they have room, using prefill-GPU memory as a queue, which absorbs bursts.

Results. On the chatbot workload, 2.0–4.6× higher request rate than vLLM; across workloads, up to 7.4× more requests or 12.6× tighter SLOs than vLLM or DeepSpeed-MII, with over 90% of requests within SLO.

When it pays. Long prompts plus strict TPOT; enough traffic to keep two pools busy; fast links between the pools. Sarathi’s authors note the downsides: KV migration needs high-bandwidth links, and prefill GPUs’ memory sits largely unused for KV.

At frontier scale (DeepSeek-V3 §3.4). Optional deployment case study. TP4 (tensor parallelism) splits an attention computation over four GPUs; DP8 (data parallelism) runs eight independent attention replicas; EP32 (expert parallelism) distributes the experts of the mixture-of-experts (MoE) layers over 32 GPUs; SP (sequence parallelism) shards suitable intermediate activations along tokens. These are complementary layouts for different parts of the same model, not four factors to multiply together. DeepSeek serves V3 with separate prefill and decode stages on H800 nodes:

  • Prefill unit: 4 nodes, 32 GPUs. Attention uses 4-way tensor parallelism with sequence parallelism and 8-way data parallelism; the MoE layers use 32-way expert parallelism (EP32). 32 redundant copies of high-load experts (each GPU hosts 8 experts plus 1 redundant), re-chosen from live load statistics, e.g. every 10 minutes. Two micro-batches overlap one’s compute with the other’s all-to-all.
  • Decode unit: 40 nodes, 320 GPUs; attention TP4 with SP and DP80; MoE EP320 with one expert per GPU, 64 GPUs holding redundant and shared experts. All-to-all runs point-to-point over InfiniBand. Per-expert batches are usually within 256 tokens and memory-bound, so the MoE part can be given only a small share of the GPU’s streaming multiprocessors (SMs).
  • Plus speculation: the multi-token-prediction head’s second token is accepted 85–90% of the time, giving 1.8× tokens per second (§5.4.3).

The lesson: once experts are spread over hundreds of GPUs, prefill and decode want such different layouts that separating them is the natural design.

Plain words. Store each cached number in 2 bits plus a shared scale ss and zero-point zz per small group: Q(X)=⌊(X−z)/s⌉Q(X) = \lfloor (X - z)/s \rceil with z=min⁡Xz = \min X, s=(max⁡X−min⁡X)/(2B−1)s = (\max X - \min X)/(2^B - 1). The question is which numbers share a group.

  • Keys: group per channel (the same dimension across 32 tokens). A few channels of the key cache have consistently huge values. Grouping per channel isolates them; grouping per token would let one outlier stretch the scale for every other channel of that token. Per-token keys gave about 5× larger attention-score error (Table 2).
  • Values: group per token. Values have no fixed outlier channels, but attention mixes them token by token; per-channel values gave about 15× larger output error. The paper’s key extra observation is sparse attention (§3.2, Eq. 2): a few tokens dominate the weighted sum. Per-token scales keep unrelated tokens from changing the quantisation grid of an important token. Per-token groups also suit streaming: each new token is its own group.
  • Residual buffers. Per-channel keys need a group of tokens before they can be quantised. With group size G = 32 and residual threshold R = 128, KIVI buffers new keys in full precision until the buffer reaches R tokens, then quantises that entire buffer and empties it (§3.3, Algorithm 1). The key residual therefore cycles from 0 to R − 1 tokens, while values keep a sliding window of the last R tokens in full precision. The paper describes an expected full-precision window of about R/2 for keys versus R for values.

Table 1 (Llama-2-13B, 2-bit simulated): keys per-channel with values per-token keeps CoQA at 63.53 versus 66.37 at 16-bit; any per-channel value quantisation collapses it below 3. Full KIVI-2 keeps GSM8K at 20.77 versus 22.67 for Llama-2-13B and 36.01 versus 38.36 for Mistral-7B. On Llama-2-7B, peak memory (weights included) falls 2.6×, allowing up to 4× larger batches and 2.35–3.47× throughput.

FlashAttention and FlashAttention-2 reached only 35% utilisation on the H100. FlashAttention-3 uses Hopper’s asynchrony: some warps only load tiles (via the TMA copy engine) while others only multiply; the softmax of one block runs while the matmul of another proceeds, which matters because the H100 has 989 TFLOPS of FP16 matmul but only 3.9 TFLOPS for exponentials; and FP8 is made accurate with per-block scales plus multiplying Q and K by a random orthogonal matrix to spread outliers. Result: 1.5–2.0× over FlashAttention-2 in FP16 (up to 740 TFLOPs/s, 75% utilisation), close to 1.2 PFLOPs/s in FP8, with 2.6× lower FP8 error than a per-tensor baseline. For serving, this speeds prefill (and prefill chunks); memory-bound decode gains less.

  • SGLang’s baselines are old. The comparison uses vLLM v0.2.5; the paper notes RadixAttention was being added to later vLLM versions as an experimental feature, so the gap to current engines is likely smaller.
  • Hit rate depends on prompt hygiene and traffic. Low-traffic models in Chatbot Arena still reached 52–74%, but a per-request ID or timestamp early in a prompt cuts reuse to the prefix before it (zero if it is the first token).
  • Exact prefixes only. The same passage at a different position, or after different text, has different KV. Fuzzy or semantic matching is listed as future work and would change outputs.
  • Disaggregation and chunked prefill were never compared head to head in these papers (Sarathi leaves it as future work), and the two can be combined.
  • KIVI’s throughput comes from a Hugging Face implementation on short prompts. The main LongBench experiments cap inputs at 4K–8K tokens (§4.1), but Appendix D also reports LongBench results for 32K-context Mistral and LongChat models, and Figure 4 includes needle-retrieval tests reaching about 27K–30K tokens. These still do not establish reliability on long, multi-step agent reasoning or modern paged-serving workloads.
  • RL rollouts: caching helps within a policy version only; weight syncs flush it.
  • Builds on: PagedAttention shares blocks within a request (parallel samples, beams); RadixAttention keeps blocks across requests and after they finish. GQA and MLA set bytes per token; speculative decoding and multi-token prediction cut decode passes; Making DL go brrrr is the general compute-vs-memory roofline argument.
  • Frontier deployment: DeepSeek-V3 is the model behind the 32-GPU prefill / 320-GPU decode layout above.
  • RL rollouts: RL infra and AReaL use SGLang or vLLM as the rollout engine; GRPO’s G samples per prompt are a one-level prefix tree.
  • Agents and LM programs: ReAct traces and a DSPy RAG pipeline are among SGLang’s benchmarks; both re-send long shared prefixes.
  • IR link, caching: search engines cache query results and posting lists with LRU-style policies, measure byte versus request hit rates, and route queries to replicas with warm caches. RadixAttention is the same playbook applied to KV tensors, with one difference: a cached KV prefix is only valid in exactly that context.
  • IR link, shared-prefix RAG: because KV is position- and context-dependent, reusing a popular passage across queries is the open problem discussed on the PagedAttention page; it mirrors independent versus contextual chunk encoding in contextual retrieval and late chunking. Compressing cached vectors per channel versus per token also echoes how PLAID compresses ColBERT token vectors.
  • Compute arithmetic intensity for a decode batch and a prefill, and say which one a faster kernel or a bigger batch helps.
  • Define TTFT, TPOT/TBT and goodput, and explain why goodput, not throughput, is the right target.
  • Compute KV bytes for any GQA, MHA or MLA model, and the effect of 2-bit quantisation.
  • Trace a request through RadixAttention (match, insert, split, evict) and compute a prefix-cache hit rate for an agent or RAG prompt.
  • Decide between chunked prefill and disaggregation from prompt length, SLOs and link bandwidth.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    A 70B-class GQA model (Llama 3 70B shape: 80 layers, 8 KV heads, head dim 128) serves 16 concurrent requests of 32K tokens each with a bf16 KV cache. Compute the KV bytes per token and in total, compare them with the ≈140 GB of bf16 weights, and redo the total for full multi-head attention (64 KV heads) and for 2-bit KIVI. What does the comparison say about what each decode step reads?

    What a strong answer covers
    • Per token: 2 (K and V) × 80 × 8 × 128 × 2 bytes = 327,680 B = 320 KiB. Per 32K-token sequence: 320 KiB × 32,768 = 10 GiB. Batch of 16: 160 GiB (≈172 GB), more than the weights.
    • With 64 KV heads the cache is 8× larger: 80 GiB per sequence and 1.25 TiB for the batch, which is why 70B-class models share KV heads.
    • KIVI 2-bit: the nominal 2-bit payload is 20 GiB; an fp16 scale and zero-point per 32 values add about 1 bit per element, so ≈30 GiB before residuals. Keys are flushed in R-token blocks while values keep the newest R tokens, so residual storage varies; 40 MiB per sequence is only a conservative full-precision upper bound.
    • Each decode step reads the weights once for the whole batch but every sequence's own KV. Here KV traffic exceeds weight traffic, so a larger batch no longer amortises most bytes, and time per output token grows with context length.
  2. Derive / compute

    An agent sends a 6,000-token system prompt at step 1. Each of the nine transitions to steps 2–10 appends 500 previously unseen tool-output tokens, and each step resends the full history. Ignore model outputs and assume no eviction. Compute submitted tokens, newly prefilled tokens and the token-weighted hit rate for a cold cache and for a resident system prompt. What can and cannot be inferred about TTFT, and what happens when an early timestamp changes?

    What a strong answer covers
    • Prompt at step k is 6,000 + 500(k − 1) tokens. Total = 10 × 6,000 + 500 × (0 + 1 + … + 9) = 60,000 + 22,500 = 82,500 tokens.
    • Cold cache: 6,000 tokens at step 1, then only the 500 new ones at steps 2–10, so 10,500 tokens prefilled. Hit rate = 72,000 / 82,500 ≈ 87%. Warm system prompt: 4,500 prefilled, hit rate ≈ 94.5%.
    • Step 10 alone: a 10,500-token prompt with 500 new tokens, so the count of newly computed token representations falls 21×. Attention work (the new tokens still attend over the whole cached history) and measured TTFT fall by different factors; neither can be inferred from that token-count ratio alone.
    • A token's KV depends on every earlier token, so a changed timestamp creates a new branch at the first differing token; only the unchanged prefix before it stays reusable. Reuse falls to zero only if the very first token changes and nothing else is shared. Put stable content first and volatile content last.
    • Memory: on the 70B GQA model the 6,000-token prefix costs 6,000 × 320 KiB ≈ 1.83 GiB once, instead of once per concurrent agent.
  3. Mechanism

    Use arithmetic intensity to explain why prefill is compute-bound and decode is memory-bandwidth-bound, why batching more decodes helps the linear layers but not attention over the KV cache, and how Sarathi-Serve's stall-free batching uses the slack. Where does chunking stop being free?

    What a strong answer covers
    • A linear layer with a d × d bf16 weight applied to n tokens does 2nd² FLOPs and reads about 2d² bytes, so intensity ≈ n FLOPs per byte. A 2K-token prefill is far above the ridge point (Sarathi: about 200 tokens in theory on A100, 500–600 in practice); a decode batch of 32 is far below it.
    • Batching decodes shares one weight read across sequences, but each sequence reads its own KV, so attention intensity in decode stays near the GQA group size whatever the batch size.
    • Stall-free batching: pick a token budget from the TBT SLO. Running decodes (1 token each) get priority; the remaining budget admits prefill chunks. Every running decode advances each iteration, but its latency can still exceed decode-only latency: Sarathi bounds interference rather than removing all prefill cost. Naive hybrid batching with full prefills raised TBT up to 28.3× (Fig. 9).
    • Costs: each chunk re-reads the KV of earlier chunks (O(N²) chunk loads, DistServe's critique); fixed kernel overheads (at most ≈25% extra prefill time at chunk 512 on Yi-34B, near zero at 2048); tile quantisation (a 257-token chunk can be 32% slower than 256).
  4. Critique

    KIVI groups keys per channel and values per token at 2 bits, uses an R = 128 threshold for key-buffer flushes and a 128-token full-precision value window, and reports near-baseline quality with 2.6× less peak memory. Explain the two grouping choices, then assess whether the quality and throughput evidence justifies deploying KIVI-2 for 32K-token RAG and multi-step agent histories. What failure-focused experiment would you require?

    What a strong answer covers
    • Keys have a few fixed outlier channels. Grouping along a channel confines a large scale to that channel; grouping per token lets one outlier set the scale for the whole token. Per-token keys gave about 5× larger attention-score error (Table 2).
    • Values have no channel outliers but are mixed token by token by the attention weights; per-channel values gave about 15× larger output error. Per-token grouping also streams naturally, since each new token is its own group.
    • Keys accumulate in full precision until the buffer reaches R and are then quantised together, so the key residual cycles between 0 and R − 1 tokens; values keep the newest R tokens. This differs from a fixed full-precision K/V window.
    • Evidence: the main LongBench runs cap inputs at 4K–8K, Appendix D adds 32K-context Mistral and LongChat models, and Figure 4 needle tests reach about 27K–30K tokens; none covers long generated reasoning or agent trajectories. GSM8K (Llama-2-13B 22.67 → 20.77) and multi-query-attention Falcon-7B (needed 4 bits) show task- and model-dependent loss; throughput came from a Hugging Face implementation, not a paged engine.
    • Experiment: multi-document QA and multi-step agent traces at 32K with gold evidence at varied depths, KIVI-2 vs KIVI-4 vs bf16, scoring long reasoning outputs as well as short answers, inside a real paged engine.
  5. What if…

    SGLang's Figure 8c measures removing the tree structure (a simple table-based cache) and replacing cache-aware ordering with FCFS. Explain those results on few-shot and multi-turn workloads. Separately, predict the unmeasured effect of reserving a fixed memory pool for cached prefixes. Design an ablation that separates hit-rate gains from larger effective batches, and explain when cache-first ordering can hurt tail latency.

    What a strong answer covers
    • The no-tree baseline handles only limited, registered sharing rather than arbitrary nested prefixes (few-shot block, then a shared question, then branches), so hit rate and batch size fall. Keep the measured no-tree and scheduling results separate from the proposed fixed-pool experiment, holding request order, GPU memory and admission limits fixed where possible.
    • FCFS interleaves unrelated requests, so LRU eviction removes a prefix before its siblings arrive (thrashing). Longest-shared-prefix-first is a depth-first walk of the request tree, which Theorem 3.1 proves hit-rate optimal offline if the cache holds the longest request; online it reached 96% of optimal on average.
    • A fixed pool would hold cached tokens even when running requests need the memory. SGLang uses one shared pool and evicts least-recently-used leaves with reference count 0, so the cache only fills idle memory and the batch can grow.
    • Harm: greedy prefix-first ordering can starve requests with no match and worsen tail TTFT (the paper leaves fairness to future work); chats with long outputs gain almost nothing because decode dominates.
  6. Design

    You serve a RAG reader on the 70B GQA model (320 KiB of KV per token) with 8K-token prompts, ~300-token answers, a 2 s P90 TTFT SLO and a 50 ms P90 TPOT SLO, at about 4 requests per second. Decide between colocated serving with chunked prefill and prefill/decode disaggregation, accounting for KV transfer, and say what you would measure.

    What a strong answer covers
    • Transfer per request: 8,192 × 320 KiB = 2.5 GiB. At 4 requests/s that is 10 GiB/s ≈ 86 Gbps: far above DistServe's 25 Gbps cross-node testbed, small next to intra-node NVLink (600 GB/s on A100) or an 800 Gbps InfiniBand link. Placement must keep prefill/decode pairs on fast links.
    • Disaggregation removes interference and lets each pool get its own size and parallelism (DistServe's 13B example: 2 prefill GPUs + 1 decode GPU give 2.1× the per-GPU goodput of colocation). It pays most when prompts are long and both SLOs are tight.
    • Chunked prefill keeps one pool, needs no transfer and uses all GPU memory for KV, but chunks add prefill overhead (TTFT) and decodes still share compute with prefill.
    • Prefix caching interacts: a shared RAG instruction prefix shrinks prefill work, which favours colocation; with disaggregation the full KV must still reach the decode worker unless it caches the prefix too.
    • Measure request-level joint TTFT/TPOT SLO attainment as well as each marginal percentile, per-GPU goodput, P99 TBT, transfer latency and prefill-buffer occupancy under bursts. Two separate P90 targets do not by themselves guarantee that 90% of requests meet both.

Done with this page?

Status