↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

What KV-cache eviction is

Quantization stores every cached position in fewer bits (the KV quant tab). Eviction keeps fewer positions: each layer's cache holds a fixed budget of rows per key/value head, and when it is full the rows judged least useful are dropped for good. Attention then runs over the kept rows only. The bet is that most of a query's attention falls on a few positions, so the ones left out would have contributed little.

This page runs two eviction policies on the KV cache tab's example, Qwen2.5-0.5B-Instruct answering "What is the guest Wi-Fi password?" about a prompt that states it is maple-river-42. Both hold 32 positions per key/value head per layer. H2O keeps the newest positions plus the heavy hitters of accumulated attention; SnapKV keeps the prompt positions that the end of the prompt attends to. Each runs teacher-forced on the full cache's answer, so every step compares, and free-running, to see how far its own answer drifts.

H2O: heavy hitters and the newest tokens

H2O scores each cached position by the attention it has received so far, summed over every query up to the current step and over the 7 query heads that share its key/value head:

It keeps the 16 newest positions and the 16 older ones with the highest scores, and evicts the rest. The prefill already cuts the 52-token prompt to 32; every decode step then adds one row and evicts one. The Accumulated attention chart shows the scores of the selected layer and head, with the newest 16 marked; once a position is evicted it can never come back, however much a later query would have wanted it.

SnapKV: votes from the end of the prompt

SnapKV decides once, after the prefill. The last 8 prompt tokens, the end of the question, form an observation window; their attention votes for the earlier positions, summed over the window and the head group and smoothed with an average pool of width 5 so that neighbouring tokens are kept together:

Each key/value head keeps its top 24 positions plus the window, and the answer's rows are then added without evicting. The Votes from the window chart shows the votes; the idea is that what the end of the question attends to is what the answer will need.

What every layer keeps

The What every layer keeps map has a row for each layer and key/value head and a column for each position, kept cells shaded by the method's score and evicted cells pale. Most heads keep the first tokens of the prompt in every layer: they draw attention whether or not they matter, the attention sinks that StreamingLLM found (the Sinks tab), and an eviction policy that dropped them would lose that attention entirely.

The kept keys keep their original RoPE rotation, so each query still sees them at their true distance. The Attention dropped chart shows, per layer, how much of the full cache's attention at this step fell on positions the method had evicted: what this step loses.

What the answers show

The full cache answers "The password for the guest Wi-Fi is "maple-river-42"." With 32 positions H2O answers "The password for the Maple-Tree-Wi-Fi is "maple-tree".", leaving the full answer at token 4, where the full cache gave " guest" 98 %. SnapKV answers "The password for the guest Wi-Fi is "maple-river"." and loses only the final "-42", at token 13.

The Other budgets table repeats both runs with 8 to 48 positions and counts the tokens before each answer changes. H2O keeps 1, 4, 4, 4, 11 and 15 of the 18 tokens at budgets 8, 16, 24, 32, 40 and 48; SnapKV keeps 2, 4, 4, 13 and 13, and the whole answer at 48. An exact string like a password is a hard case for eviction: each piece has to survive until the step that copies it, and a score built from the attention received so far has no reason to keep a piece before it is read.

Where it came from

H2O (2023) observed that a small portion of tokens contributes most of the attention, and Scissorhands (2023) that tokens important at one step stay important; both keep such tokens plus recent ones. StreamingLLM (2023) showed that a recent window alone fails unless the first tokens, the sinks, are kept. FastGen (2023) profiled each head and chose a different policy per head. SnapKV (2024) moved the decision to the end of the prompt, for long inputs followed by a question.

Papers

  1. H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models Zhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen et al. · NeurIPS 2023 Heavy hitters by accumulated attention plus the newest tokens, the first policy on this page.
  2. SnapKV: LLM Knows What You are Looking for Before Generation Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh et al. · arXiv 2024 Votes from an observation window at the end of the prompt, pooled, chosen once per head: the second policy.
  3. Efficient Streaming Language Models with Attention Sinks Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, Mike Lewis · ICLR 2024 Attention sinks: the first tokens draw attention in every layer, and a cache that drops them fails.
  4. Scissorhands: Exploiting the Persistence of Importance Hypothesis for LLM KV Cache Compression at Test Time Zichang Liu, Aditya Desai, Fangshuo Liao, Weitao Wang et al. · arXiv 2023 The persistence of importance: tokens that mattered at one step keep mattering, the assumption behind accumulated-attention scores.
  5. Model Tells You What to Discard: Adaptive KV Cache Compression for LLMs Suyu Ge, Yunan Zhang, Liyuan Liu, Minjia Zhang, Jiawei Han, Jianfeng Gao · ICLR 2024 FastGen: a different eviction policy per head, from a profile of what each head attends to.
  6. Qwen2.5 Technical Report An Yang et al. (Qwen Team) · arXiv 2024 The Qwen2.5 models, including the 0.5B instruct model whose cache this page evicts.

See also