GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
SIGCOMM 2024

CacheGen: KV Cache Compression and Streaming for Fast Large Language Model Serving

A long document's cached KV can be gigabytes, and fetching it can take longer than recomputing. CacheGen encodes KV like video: 3.5-4.3x smaller than quantized KV, 3.2-3.7x faster first tokens.

Breakdown by FDE Interviews · 12 min read · Updated

About the original · 2024
AUTHORS
Liu, Li, Cheng, Ray, et al.
FROM
University of Chicago, Microsoft, Stanford University
PUBLISHED
Oct 2023 · SIGCOMM 2024
CITED BY
353Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 20% of this breakdown.

01

The paper in one minute

Caching a long context's KV cache saves prefill the next time the context is used: a chat history, a contract, a codebase file. The catch the paper points at is that the cache rarely stays in the same GPU's memory. It gets offloaded, stored on another server, or needed by a different GPU, and it is big. The paper's example: an 80,000-token annual report on a 34B model produces 19 GB of KV, about the size of the model. Between regular cloud servers, at single-digit Gbps, fetching that can take longer than computing it from the text.

CacheGen shrinks the cache for transmission rather than for GPU memory. Since the cache only has to be rebuilt into tensors on arrival, it can be encoded as a bitstream, much like video. Three observations drive the encoder. Within a channel, nearby tokens have similar values, so it stores one anchor token per group of 10 at 8 bits and the rest as differences. Errors in early layers hurt more than errors in deep layers, so deeper layers get coarser quantization. Values grouped by channel and layer have lower entropy than values grouped by token, so arithmetic coding uses a probability table per channel and layer, profiled once per model.

The second half is streaming. Each context is split into 1,500-token chunks, each encoded offline at several levels. When a request arrives, chunks are sent one at a time; for each, CacheGen measures the throughput of the previous chunk and picks the least lossy option that still meets the time-to-first-token (TTFT) target, including sending the raw text and recomputing that chunk. Decoding runs on the GPU and overlaps the next chunk's transfer.

On Mistral-7B, Llama-34B and Llama-70B over 662 long contexts, CacheGen's KV was 3.5-4.3x smaller than uniformly quantized KV at similar quality. At 3 Gbps, TTFT was 3.2-3.7x lower than the quantization baseline and 3.1-4.7x lower than sending text. Under fluctuating bandwidth with a 1 s target, misses dropped from 81% to 8%.

THE IDEA, VISUALLY
ENCODE ONCE, OFFLINE (SECTION 5.2) split into chunks 1,500 tokens each, encoded independently anchor + deltas per 10 tokens: first at 8 bits, rest as deltas layer-wise quantization bins 0.5 / 1 / 1.5 for early / middle / late layers arithmetic coding one symbol table per channel and layer store several levels each chunk kept at multiple sizes, plus its text STREAM PER REQUEST (SECTION 5.3) for each chunk, using the throughput of the previous one: if recomputing from text fits the time left, send text else send the least compressed level that still fits decoding runs on the GPU and overlaps the next chunk's transfer; encoding a context takes ~200 ms; short contexts (<1K tokens) fall back to sending text Why it works: within a channel, nearby tokens have similar values; early layers are more sensitive to error than late ones; grouping by channel and layer lowers entropy more than by token. KV SIZE, MISTRAL-7B ON LONGCHAT (TABLE 1) accuracy 8-bit quantization 622 MB 1.00 CacheGen 176 MB 0.98 H2O (drops tokens) 282 MB 0.97 CacheGen on H2O 71 MB 0.97 LLMLingua (drops text) 492 MB 0.94 CacheGen on LLMLingua 183 MB 0.94 TIME TO FIRST TOKEN AT 3 GBPS (SECTION 7.2) 3.2-3.7x lower than uniform KV quantization 3.1-4.7x lower than sending text and prefilling 1.67-1.81x lower than near-lossless 8-bit quantization Mistral-7B, Llama-34B, Llama-70B; 4 datasets, 662 contexts 1 S TARGET, BANDWIDTH 0.1-10 GBPS (FIGURE 13) requests over the target 81% quantization 8% CacheGen with adaptation at the same quality, 20 bandwidth traces, LongChat code: github.com/UChi-JCL/CacheGen
CacheGen treats a stored KV cache like a video file: encode it once into compact bitstreams at several quality levels, then stream it chunk by chunk, dropping quality or sending text when the network slows.
Research notes: the problem, approach and results
3.5-4.3x

smaller KV cache than uniform quantization at similar quality, three models and four datasets

3.2-3.7x

lower time to first token than the quantization baseline at 3 Gbps, including transfer and decoding

81% → 8%

requests missing a 1 s time-to-first-token target under 0.1-10 Gbps bandwidth, quantization vs CacheGen

THE PROBLEM

Reusing a long context's KV cache skips prefill, but the cache is large (19 GB for an 80,000-token report on a 34B model, per the paper) and usually sits on another machine. Over the single-digit Gbps links between ordinary cloud servers, fetching it can take as long as recomputing it, and bandwidth changes mid-transfer.

THE IDEA

Encode the KV cache offline into bitstreams instead of keeping tensor shape: deltas against an anchor token every 10 tokens, coarser quantization in deeper layers, and arithmetic coding with a probability table per channel and layer. Store each 1,500-token chunk at several levels and pick a level (or plain text to recompute) per chunk while streaming, to meet a time-to-first-token target.

THE RESULT

Across Mistral-7B, Llama-34B and Llama-70B on four long-context datasets, KV size fell 3.5-4.3x against uniform quantization at similar quality, and time to first token fell 3.2-3.7x against quantization and 3.1-4.7x against sending text, at 3 Gbps. With varying bandwidth and a 1 s target, misses fell from 81% to 8%.

02

Why it matters to an FDE

Once a customer's contexts outgrow GPU memory (long chat histories, document assistants, many tenants), cached KV lives in host memory, on SSD or on a storage service. At that point network bandwidth, not GPU compute, decides whether the cache helps.

Do the transfer arithmetic before promising a cache win. KV size per token is fixed by the model's shape; divide by the link speed and compare with prefill time. On a 10 Gbps link a multi-gigabyte cache may be slower than prefill.

Transmission-time compression is a different lever from GPU-memory compression. KV quantization for memory must keep tensors usable by the attention kernel; a codec for the wire can use entropy coding and deltas and decode on arrival. The two stack.

Treat cache fetch like a video stream with a deadline. Bandwidth inside a cloud region varies. Choosing quality per chunk against a TTFT target, with text as a fallback, keeps latency predictable instead of hoping the link holds.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 149 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The three KV properties, the encoder, the adaptation rule and three misreadings

    Free account
  2. 04How it works

    The offline encoder, the per-chunk adapter, the integration and the default settings

    Premium
  3. 05The numbers that matter

    Setup, size and TTFT results, adaptation, overheads and the storage cost note

    Premium
  4. 06Try it yourself

    Recheck the paper's arithmetic, build the encoder step by step, and stream against an SLO

    Premium
  5. 07Where it breaks

    Fixed tables, KV-shape assumptions, fast links, limited quality metrics and slips

    Premium
  6. 08Using it on a deployment

    Deciding whether to cache, fetch or recompute, and how to set levels and SLOs

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →