SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2404.14469 · 2024

SnapKV: LLM Knows What You are Looking for Before Generation

arXiv · PDF · Open in the Atlas

Code that ran

We lifted 10 functions out of this paper's own repositories and ran 8 of them in a sandbox. "Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results.

RepositoryRoleRan
fasterdecoding/snapkv canonical 8 of 10
FunctionStatusWhere it lives
repeat_kv Ran fasterdecoding/snapkv/snapkv/monkeypatch/snapkv_utils.py
code served (permissive licence) · get_code("3c76e52815c5401d")
build_chat Ran fasterdecoding/snapkv/experiments/LongBench/pred_snap.py
code served (permissive licence) · get_code("ead90df220ef482e")
count_score Ran fasterdecoding/snapkv/experiments/LongBench/metrics.py
code served (permissive licence) · get_code("b349b79d9cc2934b")
normalize_answer Ran fasterdecoding/snapkv/experiments/LongBench/metrics.py
code served (permissive licence) · get_code("e7e75981cb464788")
normalize_zh_answer Ran fasterdecoding/snapkv/experiments/LongBench/metrics.py
code served (permissive licence) · get_code("8c5c581f9264c810")
parse_args Ran fasterdecoding/snapkv/experiments/LongBench/pred_snap.py
code served (permissive licence) · get_code("db40c0387e20158c")
post_process Ran fasterdecoding/snapkv/experiments/LongBench/pred_snap.py
code served (permissive licence) · get_code("4489113b536ca6eb")
prepare_inputs_for_generation_mistral Ran fasterdecoding/snapkv/snapkv/monkeypatch/mistral_hijack_4_37.py
code served (permissive licence) · get_code("7691e90deddd0f79")
prepare_inputs_for_generation_llama Not yet run fasterdecoding/snapkv/snapkv/monkeypatch/llama_hijack_4_37.py
code served (permissive licence) · get_code("d50769dc29155b3b")
prepare_inputs_for_generation_mixtral Not yet run fasterdecoding/snapkv/snapkv/monkeypatch/mixtral_hijack_4_37.py
code served (permissive licence) · get_code("5aeb661d1528668c")

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

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.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2404.14469")
get_code_for_paper("2404.14469")
have("2404.14469")

Connect an agent — have() is free.