跳到正文
DEV Community· RuChating·· 44 分鐘前AI 評分51

推測解碼的第二份 KV cache 為何影響推理伺服器容量估算

The second KV cache: why speculative decoding's memory bill is not the one you modeled

AI 導讀

文章指出,推測解碼每個進行中的請求都同時保留目標模型與草稿模型的 KV cache,容量規劃只計一份會低估記憶體需求。研究在六組模型配對中以 K4V4 量化草稿 KV cache,使其記憶體減少 66.20%,兩份 cache 合計減少 23.95%,平均接受率則由 57.93% 降至 57.14%。

正文

Speculative decoding is usually sold as free speed. A small draft model proposes several tokens, the larger target model checks them in a single pass, and — if the acceptance rate is decent — you get more tokens per second without changing the output distribution. Most write-ups stop there: acceptance rate, speedup, maybe a note about the draft model being cheap.

There is a line item missing from that story. Speculative decoding keeps two KV caches alive for every in-flight request: one for the target model and one for the draft model. Capacity plans almost always budget for one. A paper posted on arXiv on 16 November and accepted at the AXIOM Foundations of Efficient Deep Learning workshop at NeurIPS 2026 finally puts a number on the second one, and the answer changes how you should size an inference server.

Two caches, one memory budget

The mechanics are simple enough to skip in most explanations, which is exactly why the memory cost gets overlooked. The draft model generates a short run of candidate tokens autoregressively. Its KV cache grows as it does. The target model then verifies that run in parallel and produces the final token sequence. The target model's cache is also live, because the conversation so far still lives there.

So the memory equation for a serving replica is not "model weights plus KV". It is weights plus target KV plus draft KV plus working memory. The draft cache is a second, parallel copy of session state with its own shape, its own layer count, and its own lifetime. If the draft is sized at roughly a quarter or a third of the target's cache, the headline "we added a tiny model" turns into a material increase in resident memory per request. That is the difference between fitting another batch slot on a GPU and evicting one.

The authors of Memory-Efficient Speculative Decoding with Quantized Draft KV Cache attack only that second cache. The target cache and the verification rule stay in BF16, so the compression cannot change the target model's final correction — a careful design choice, and one worth copying. Quantization is applied to the draft cache alone.

The numbers, and the arithmetic behind them

Across six model pairs, their K4V4 scheme — four bits for keys, four for values — reduced draft cache memory by 66.20%. Combined memory across both caches fell by 23.95%. Mean acceptance went from 57.93% to 57.14%, a relative decline of 1.36%.

Those two percentages invite a wrong conclusion. A 66% cut in the draft cache is not a 66% cut in your KV bill; it is a 66% cut in one component of it. Here is illustrative arithmetic, not a measurement from the paper: if the target cache is 80 GB and the draft cache is 20 GB, a 66% draft reduction saves about 13.2 GB — a 13% saving on a 100 GB total. To get the reported 23.95% combined saving, the draft cache has to be a larger share of the pair in the tested configurations. Before you quote the headline number in a capacity review, measure the draft-to-target cache ratio on your own models. That ratio, not the compression percentage, decides whether this technique moves your utilization.

The acceptance result is the other half of the trade. A 1.36% relative drop is small, but acceptance is a multiplier on the useful work of every speculative step. The right metric is not acceptance rate in isolation; it is accepted tokens per gigabyte of KV per second, measured at the concurrency you actually run. If the freed memory lets you keep more sessions resident or raise the batch size, a slightly worse acceptance rate is a good deal. If your draft cache is already a rounding error, it is not.

The finding that matters more than the percentage

The most useful result in the paper is not the memory saving. It is what happens when you change the quantizer layout.

With a naive per-token quantizer, splitting a 12-bit budget between keys and values gives a striking result: K8V4 beats K4V8 by 10.87 percentage points of acceptance. The natural reading is that keys need the precision and values can be squeezed. Then the authors switch keys to grouped per-channel quantization. The gap becomes −0.25 percentage points — the sign flips. A controlled test on Qwen confirms that changing only the key quantizer can erase or reverse which bit split looks better.

That is a design lesson well beyond this one paper. "4-bit KV cache" is not a specification; the quantizer geometry is part of the algorithm. Key and value precision have to be co-designed with the layout used to quantize them. If you are evaluating a quantization scheme from a benchmark, check which layout produced the number before you port it into a serving stack. A result that looks like a property of the model can be a property of the quantization grid.

Their final recipe follows KIVI: per-channel keys and per-token values, applied to the draft cache only. The target side and the verifier stay exact, which means the speculative decoding guarantee — same output distribution as the target model — is preserved by construction.

Where the first cache lives is changing too

Compressing the draft cache is one lever. Relocating the target cache is another, and it showed up in the same week. A 23 November vLLM engineering post describes running the agentic KV pool directly on NVMe with AMD's open-source MoRI UMBP, removing the DRAM tier entirely apart from a 64 GB write buffer and a 16 GiB read staging buffer. With pooled capacity fixed at 1.8 TB, throughput stayed within 1% of an equally sized DRAM pool at 48, 70 and 96 concurrent sessions on MI355X GPUs. Their workload wrote 2.3 to 4.6 TB of KV per hour, which is why a DRAM pool held only 23 to 47 minutes of history while disks rated for a day of writes cost less.

Put the two results together and a pattern appears. The memory hierarchy of an inference server is being redesigned at both ends: the redundant, short-lived copy is compressed in place, while the long-lived copy is moved to cheaper, slower media. Neither change requires a new accelerator. Both require you to know which piece of state you are looking at.

There is a cost on the storage side, of course. Every KV block the GPU computes gets written to SSD, so endurance and write amplification become first-class capacity-planning inputs. NVMe that matches DRAM in throughput today does not make SSDs identical to DRAM; it makes them a different kind of resource, priced per write rather than per gigabyte held.

A checklist before you enable this

  • Identify the draft-to-target cache ratio for your model pair. The headline saving applies to the draft cache, not to your total KV budget.
  • Keep the target cache and verifier at full precision unless you have a separate correctness argument. The paper's guarantee comes from leaving them untouched.
  • Benchmark quantizer layout, not just bit width. Per-token and per-channel key quantization can reverse the ranking of bit allocations.
  • Measure accepted tokens per GB of KV at your production concurrency. Acceptance rate alone can mislead in either direction.
  • Check whether freed memory actually becomes batch capacity. If your replica is network-bound or weight-bound, the memory saving buys nothing.
  • If you also move KV to NVMe, model SSD writes per hour and spread them across enough drives. Throughput parity is not endurance parity.

Speculative decoding made a generation cheaper. The next round of gains is less glamorous: deciding where every copy of session state lives, how many bits it needs, and which quantizer geometry earns those bits. The second KV cache was never free. It was just invisible.

來源:DEV Community · dev.to