{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/kvzip-query-agnostic-kv-cache-compression","title":"KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction","arxiv_id":"2505.23416","date":"2025-05-29","proceeding":null,"authors":["Jang-Hyun Kim","Jinuk Kim","Sangwoo Kwon","Jae W. Lee","Sangdoo Yun","Hyun Oh Song"],"abstract":"Transformer-based large language models (LLMs) cache context as key-value (KV) pairs during inference. As context length grows, KV cache sizes expand, leading to substantial memory overhead and increased attention latency. This paper introduces KVzip, a query-agnostic KV cache eviction method enabling effective reuse of compressed KV caches across diverse queries. KVzip quantifies the importance of a KV pair using the underlying LLM to reconstruct original contexts from cached KV pairs, subsequently evicting pairs with lower importance. Extensive empirical evaluations demonstrate that KVzip reduces KV cache size by 3-4$\\times$ and FlashAttention decoding latency by approximately 2$\\times$, with negligible performance loss in question-answering, retrieval, reasoning, and code comprehension tasks. Evaluations include various models such as LLaMA3.1-8B, Qwen2.5-14B, and Gemma3-12B, with context lengths reaching up to 170K tokens. KVzip significantly outperforms existing query-aware KV eviction methods, which suffer from performance degradation even at a 90% cache budget ratio under multi-query scenarios.","url_abs":"https://arxiv.org/abs/2505.23416v1","url_pdf":"https://arxiv.org/pdf/2505.23416v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"kvzip-query-agnostic-kv-cache-compression","repo_url":"https://github.com/snu-mllab/kvzip","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"question-answering","task_name":"Question Answering"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2505.23416","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2505.23416"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/snu-mllab/kvzip","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_fixture":3,"ran_draft_wrong":2,"unverified":7},"by_repo_kind":{"official":{"samples":7,"ran":0,"repositories":1},"community":{"samples":4,"ran":4,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":1,"samples":[{"code_sha256_prefix":"3c76e52815c5401d","entry":"repeat_kv","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"3c76e52815c5401d"}},{"code_sha256_prefix":"3ddd62fbad41e698","entry":"build_chat","repo":"zefan-cai/kvcache-factory","repo_kind":"community","path":"run_longbench.py","file_url":"https://github.com/zefan-cai/kvcache-factory/blob/HEAD/run_longbench.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3ddd62fbad41e698"}},{"code_sha256_prefix":"a06d17c88eb31b3d","entry":"build_chat_llama3","repo":"zefan-cai/kvcache-factory","repo_kind":"community","path":"run_longbench.py","file_url":"https://github.com/zefan-cai/kvcache-factory/blob/HEAD/run_longbench.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a06d17c88eb31b3d"}},{"code_sha256_prefix":"3597e5670a759378","entry":"key_pruner_query_driven","repo":"zefan-cai/kvcache-factory","repo_kind":"community","path":"pyramidkv/pyramidkv_utils.py","file_url":"https://github.com/zefan-cai/kvcache-factory/blob/HEAD/pyramidkv/pyramidkv_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3597e5670a759378"}},{"code_sha256_prefix":"6211e835b472f7ad","entry":"maybe_repeat_kv_before_cache","repo":"zefan-cai/kvcache-factory","repo_kind":"community","path":"pyramidkv/pyramidkv_utils.py","file_url":"https://github.com/zefan-cai/kvcache-factory/blob/HEAD/pyramidkv/pyramidkv_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6211e835b472f7ad"}},{"code_sha256_prefix":"612ed3463f489b86","entry":"chunk_fn","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/wrapper.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/wrapper.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"612ed3463f489b86"}},{"code_sha256_prefix":"956f62d22920f5cf","entry":"get_cuda_bare_metal_version","repo":"snu-mllab/kvzip","repo_kind":"official","path":"csrc/build.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/csrc/build.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"956f62d22920f5cf"}},{"code_sha256_prefix":"d0b3eff8cf9ed489","entry":"get_model_id","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/load.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/load.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d0b3eff8cf9ed489"}},{"code_sha256_prefix":"9c573adab3602fd1","entry":"load_head_score","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/wrapper.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/wrapper.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9c573adab3602fd1"}},{"code_sha256_prefix":"9c76a69893a315be","entry":"load_model","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/load.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/load.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9c76a69893a315be"}},{"code_sha256_prefix":"f23bd99d186e42f1","entry":"load_quant_model","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/load.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/load.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f23bd99d186e42f1"}},{"code_sha256_prefix":"f0111855fc4c12e0","entry":"template","repo":"snu-mllab/kvzip","repo_kind":"official","path":"model/template.py","file_url":"https://github.com/snu-mllab/kvzip/blob/HEAD/model/template.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f0111855fc4c12e0"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}