Papers › SnapKV: LLM Knows What You are Looking for Before Generation

SnapKV: LLM Knows What You are Looking for Before Generation

22 Apr 2024arXiv:2404.14469archive 2025-07-28

Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh, Acyr Locatelli, Hanchen Ye, Tianle Cai, Patrick Lewis, Deming Chen

Large Language Models (LLMs) have made remarkable progress in processing extensive contexts, with the Key-Value (KV) cache playing a vital role in enhancing their performance. However, the growth of the KV cache in response to increasing input length poses challenges to memory and time efficiency. To address this problem, this paper introduces SnapKV, an innovative and fine-tuning-free approach that efficiently minimizes KV cache size while still delivering comparable performance in real-world applications. We discover that each attention head in the model consistently focuses on specific prompt attention features during generation. Meanwhile, this robust pattern can be obtained from an 'observation' window located at the end of the prompts. Drawing on this insight, SnapKV automatically compresses KV caches by selecting clustered important KV positions for each attention head. Our approach significantly reduces the growing computational overhead and memory footprint when processing long input sequences. Specifically, SnapKV achieves a consistent decoding speed with a 3.6x increase in generation speed and an 8.2x enhancement in memory efficiency compared to the baseline when processing inputs of 16K tokens. At the same time, it maintains comparable performance to the baseline models across 16 long sequence datasets. Moreover, SnapKV can process up to 380K context tokens on a single A100-80GB GPU using HuggingFace implementation with minor changes, exhibiting only a negligible accuracy drop in the Needle-in-a-Haystack test. Further comprehensive studies suggest SnapKV's potential for practical applications.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology: its repositories, every harvested function with whether it ran, its licence and the call to fetch it.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2404.14469")

Code

Syntology Ran 8 of 10 code samples harvested from 1 repository linked to this paper; 2 have no recorded run. Of those that ran: 1 ran · honoured contract; 1 ran · violated contract; 2 ran · our draft was wrong; 1 ran · fixture could not drive it; 3 ran with no contract checked.

By repository: official repository: 10 samples from 1 repository, 8 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

fasterdecoding/snapkv officialmentioned in papermentioned on GitHubpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

10 samples harvested; 8 ran; 1 honoured the contract we drafted; 2 have no recorded run. Read from Syntology's graph 2026-09-25; that is when this build read the record, not when the samples ran.

1ran · honoured contract
1ran · violated contract
2ran · our draft was wrong
1ran · fixture could not drive it
3ran
2unverified

Licence: 0 of the 10 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from fasterdecoding/snapkv. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv fasterdecoding/snapkv/snapkv/monkeypatch/snapkv_utils.py official repository ran · fixture could not drive it fingerprinted Apache-2.0 (permissive) · 3c76e52815c5401d · report
build_chat fasterdecoding/snapkv/experiments/LongBench/pred_snap.py official repository ran Apache-2.0 (permissive) · ead90df220ef482e · report
count_score fasterdecoding/snapkv/experiments/LongBench/metrics.py official repository ran · honoured contract Apache-2.0 (permissive) · b349b79d9cc2934b · report
normalize_answer fasterdecoding/snapkv/experiments/LongBench/metrics.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · e7e75981cb464788 · report
normalize_zh_answer fasterdecoding/snapkv/experiments/LongBench/metrics.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 8c5c581f9264c810 · report
parse_args fasterdecoding/snapkv/experiments/LongBench/pred_snap.py official repository ran Apache-2.0 (permissive) · db40c0387e20158c · report
post_process fasterdecoding/snapkv/experiments/LongBench/pred_snap.py official repository ran · violated contract fingerprinted Apache-2.0 (permissive) · 4489113b536ca6eb · report
prepare_inputs_for_generation_mistral fasterdecoding/snapkv/snapkv/monkeypatch/mistral_hijack_4_37.py official repository ran Apache-2.0 (permissive) · 7691e90deddd0f79 · report
prepare_inputs_for_generation_llama fasterdecoding/snapkv/snapkv/monkeypatch/llama_hijack_4_37.py official repository unverified Apache-2.0 (permissive) · d50769dc29155b3b · report
prepare_inputs_for_generation_mixtral fasterdecoding/snapkv/snapkv/monkeypatch/mixtral_hijack_4_37.py official repository unverified Apache-2.0 (permissive) · 5aeb661d1528668c · report

Tasks

16k

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

SPEED

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections