SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.10774 · ICML · 2024

Quest: Query-Aware Sparsity for Efficient Long-Context LLM Inference

Song Han, Guangxuan Xiao, Jiaming Tang, Yilong Zhao, Kan Zhu, Baris Kasikci

arXiv · PDF · Open in the Atlas

Code that ran

8 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 6 failures of our instrument; 4 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2406.10774.json · badge: /api/ran/2406.10774.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
mit-han-lab/Quest canonical (classifier label)
classifier basis: census
8 ran · 4 no recorded run
FunctionStatusWhere it lives
build_chat Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
mit-han-lab/Quest/evaluation/LongBench/pred.py
code served (permissive licence) · get_code("324506640e971548")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

# Create mock tokenizers for different model types
class ChatGLM3Tokenizer:
    def build_chat_input(self, prompt):
        return f"chatglm3_processed: {prompt}"

class ChatGLMTokenizer:
    def build_prompt(self, prompt):
        return f"chatglm_processed: {prompt}"

class DefaultTokenizer:
    pass

# Test with chatglm3 model
tokenizer_chatglm3 = ChatGLM3Tokenizer()
prompt_text = "Hello, how are you?"
model_name_chatglm3 = "chatglm3-6b"

ARGS = {
    "tokenizer": tokenizer_chatglm3,
    "prompt": prompt_text,
    "model_name": model_name_chatglm3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
fastchat, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
count_score Ran
ran, honoured the contract we drafted
mit-han-lab/Quest/evaluation/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("b349b79d9cc2934b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

generate_prompt Ran
ran; our contract draft was wrong, not the code
mit-han-lab/Quest/evaluation/passkey/passkey.py
code served (permissive licence) · get_code("82a59167e1c0360c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import random

# Set seed for reproducibility
random.seed(42)

# The function takes two parameters: n_garbage and depth_ratio
# Both are integers/floats used for string manipulation and random operations

ARGS = {
    "n_garbage": 1000,
    "depth_ratio": 50
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
local_heavy_hitter_mask Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
mit-han-lab/Quest/evaluation/quest_attention.py
code served (permissive licence) · get_code("2190cf0bf20bf72f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 4, dtype family float, shape (2, 3, 8, 8) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Construct minimal valid arguments for local_heavy_hitter_mask
# attn_weights: shape (batch_size, num_heads, seq_length, seq_length)
# token_budget: int representing number of tokens to keep
# chunk_size: int for chunking the sequence

batch_size = 2
num_heads = 3
seq_length = 8
dtype = torch.float32

attn_weights = torch.randn(batch_size, num_heads, seq_length, seq_length, dtype=dtype)
token_budget = 4
chunk_size = 2

ARGS = {
    "attn_weights": attn_weights,
    "token_budget": token_budget,
    "chunk_size": chunk_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 3, 8, 8) — shape (2, 3, 8, 8) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
normalize_answer Ran
ran; our contract draft was wrong, not the code
mit-han-lab/Quest/evaluation/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("e7e75981cb464788")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

normalize_zh_answer Ran
ran; our contract draft was wrong, not the code
mit-han-lab/Quest/evaluation/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("8c5c581f9264c810")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

parse_args Ran
ran; our contract draft was wrong, not the code
mit-han-lab/Quest/evaluation/LongBench/pred.py
code served (permissive licence) · get_code("c2ae4c2b89cd4aae")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Namespace. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import argparse

ARGS = {
    'args': [
        '--model', 'llama2-7b-chat-4k',
        '--task', 'qasper',
        '--token_budget', '4096',
        '--chunk_size', '1024',
        '--quest',
        '--e'
    ]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
post_process Ran
ran, violated the contract we drafted
mit-han-lab/Quest/evaluation/LongBench/pred.py
code served (permissive licence) · get_code("4489113b536ca6eb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The function post_process takes two parameters:
# 1. response: a string that gets processed based on model_name
# 2. model_name: a string used to determine which processing branch to take

# Test case 1: xgen model
response_xgen = "Some response text\nAssistant: This is the assistant response"
model_name_xgen = "xgen-7b"

# Test case 2: internlm model
response_internlm = "Some response<eoa>This should be removed"
model_name_internlm = "internlm-chat"

# Test case 3: other model (no special processing)
response_other = "Just a regular response"
model_name_other = "gpt2"

# We'll use the xgen case as the primary test
ARGS = {
    "response": "Some response text\nAssistant: This is the assistant response",
    "model_name": "xgen-7b"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
add_args Not yet run
unverified (harvested, no recorded run)
mit-han-lab/Quest/evaluation/passkey/passkey.py
code served (permissive licence) · get_code("a16da1e7b565968b")
How it ran

no invocation recorded.

forward Not yet run
unverified (harvested, no recorded run)
mit-han-lab/Quest/evaluation/quest_attention.py
code served (permissive licence) · get_code("1e15c8009d60ec39")
How it ran

no invocation recorded.

load Not yet run
unverified (harvested, no recorded run)
mit-han-lab/Quest/evaluation/pg19/ppl_eval.py
code served (permissive licence) · get_code("72836b3c90faaa5d")
How it ran

no invocation recorded.

test_model Not yet run
unverified (harvested, no recorded run)
mit-han-lab/Quest/evaluation/passkey/passkey.py
code served (permissive licence) · get_code("3bccc0e6004c76a1")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 3 the same month, 5 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
normalize_answer 133 other papers
77 dated earlier, 8 the same month, 47 later, 1 undated · 1 only as an assembly brick
1508.06615 (2015-08)
Character-Aware Neural Language Models
1606.05250 (2016-06)
SQuAD: 100,000+ Questions for Machine Comprehension of Text
1608.07905 (2016-08)
Machine Comprehension Using Match-LSTM and Answer Pointer
and 130 more not named here
normalize_zh_answer 28 other papers
7 dated earlier, 3 the same month, 16 later, 1 same year, order not determinable, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2024.findings-emnlp.230 (2024 (year only))
CLongEval: A Chinese Benchmark for Evaluating Long-Context Large Language Models
and 25 more not named here
count_score 24 other papers
6 dated earlier, 2 the same month, 15 later, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
and 21 more not named here
post_process 14 other papers
4 dated earlier, 10 later
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
2404.14469 (2024-04)
SnapKV: LLM Knows What You are Looking for Before Generation
and 11 more not named here
build_chat 4 other papers
4 later
2410.13846 (2024-10)
LightTransfer: Your Long-Context LLM is Secretly a Hybrid Model with Effortless Adaptation
2025.emnlp-main.443 (2025 (year only))
A Training-Free Length Extrapolation Approach for LLMs: Greedy Attention Logit Interpolation
2509.19633 (2025-09)
Mamba Modulation On the Length Generalization of Mamba
and 1 more not named here

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

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

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, longcontext 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 7.03× self-attention speedup, which reduces inference latency by 2.23× while performing well on tasks with long dependencies with negligible accuracy loss. Code is available at https: //github.com/mit-han-lab/Quest.

For agents

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

get_harvested_code_for_paper("2406.10774")
get_code_for_paper("2406.10774")
have("2406.10774")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2406.10774.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2406.10774.svg)](https://syntology.ai/paper/2406.10774)

Connect an agent — have() is free.