{"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/quest-query-aware-sparsity-for-efficient-long","title":"Quest: Query-Aware Sparsity for Efficient Long-Context LLM Inference","arxiv_id":"2406.10774","date":"2024-06-16","proceeding":null,"authors":["Jiaming Tang","Yilong Zhao","Kan Zhu","Guangxuan Xiao","Baris Kasikci","Song Han"],"abstract":"As the demand for long-context large language models (LLMs) increases, models with context windows of up to 128K or 1M tokens are becoming increasingly prevalent. However, long-context LLM inference is challenging since the inference speed decreases significantly as the sequence length grows. This slowdown is primarily caused by loading a large KV cache during self-attention. Previous works have shown that a small portion of critical tokens will dominate the attention outcomes. However, we observe the criticality of a token highly depends on the query. To this end, we propose Quest, a query-aware KV cache selection algorithm. Quest keeps track of the minimal and maximal Key values in KV cache pages and estimates the criticality of a given page using Query vectors. By only loading the Top-K critical KV cache pages for attention, Quest significantly speeds up self-attention without sacrificing accuracy. We show that Quest can achieve up to 2.23x self-attention speedup, which reduces inference latency by 7.03x while performing well on tasks with long dependencies with negligible accuracy loss. Code is available at http://github.com/mit-han-lab/Quest .","url_abs":"https://arxiv.org/abs/2406.10774v2","url_pdf":"https://arxiv.org/pdf/2406.10774v2.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":"quest-query-aware-sparsity-for-efficient-long","repo_url":"https://github.com/mit-han-lab/quest","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[],"methods":[{"method_slug":"speed","method_name":"SPEED"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2406.10774","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.10774"}},"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":"deterministic:regex_extraction","url":"https://github.com/mit-han-lab/Quest","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mit-han-lab/quest","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_honours":1,"ran":3,"ran_draft_wrong":2,"ran_violates":1,"unverified":5},"by_repo_kind":{"official":{"samples":12,"ran":7,"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":0,"samples":[{"code_sha256_prefix":"b349b79d9cc2934b","entry":"count_score","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/metrics.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/metrics.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b349b79d9cc2934b"}},{"code_sha256_prefix":"82a59167e1c0360c","entry":"generate_prompt","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/passkey/passkey.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/passkey/passkey.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"82a59167e1c0360c"}},{"code_sha256_prefix":"2190cf0bf20bf72f","entry":"local_heavy_hitter_mask","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/quest_attention.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/quest_attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2190cf0bf20bf72f"}},{"code_sha256_prefix":"e7e75981cb464788","entry":"normalize_answer","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/metrics.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/metrics.py","link_basis":"harvester_set","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":"e7e75981cb464788"}},{"code_sha256_prefix":"8c5c581f9264c810","entry":"normalize_zh_answer","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/metrics.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/metrics.py","link_basis":"harvester_set","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":"8c5c581f9264c810"}},{"code_sha256_prefix":"c2ae4c2b89cd4aae","entry":"parse_args","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/pred.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/pred.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c2ae4c2b89cd4aae"}},{"code_sha256_prefix":"4489113b536ca6eb","entry":"post_process","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/pred.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/pred.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4489113b536ca6eb"}},{"code_sha256_prefix":"a16da1e7b565968b","entry":"add_args","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/passkey/passkey.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/passkey/passkey.py","link_basis":"first_harvest_node","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":"a16da1e7b565968b"}},{"code_sha256_prefix":"324506640e971548","entry":"build_chat","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/LongBench/pred.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/LongBench/pred.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":"324506640e971548"}},{"code_sha256_prefix":"1e15c8009d60ec39","entry":"forward","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/quest_attention.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/quest_attention.py","link_basis":"first_harvest_node","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":"1e15c8009d60ec39"}},{"code_sha256_prefix":"72836b3c90faaa5d","entry":"load","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/pg19/ppl_eval.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/pg19/ppl_eval.py","link_basis":"first_harvest_node","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":"72836b3c90faaa5d"}},{"code_sha256_prefix":"3bccc0e6004c76a1","entry":"test_model","repo":"mit-han-lab/Quest","repo_kind":"official","path":"evaluation/passkey/passkey.py","file_url":"https://github.com/mit-han-lab/Quest/blob/HEAD/evaluation/passkey/passkey.py","link_basis":"first_harvest_node","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":"3bccc0e6004c76a1"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}