Organizations: 1Beijing Institute of Technology · 2Uppsala University · 3National University of Defense Technology · 4Nanjing University of Science and Technology · 5Tsinghua University · 6Georgia Institute of Technology · 7Hohai University · 8Shenzhen University
Long-sequence inference in large language models is constrained by the high cost of prefilling, where dense attention scales quadratically with context length. Exploiting similarity across attention heads offers a way to reduce redundant computation. Prior approaches in this direction have relied on localized query observations to determine head-level computation reuse or budget allocation. However, inter-head similarity does not imply uniform query requirements, leaving adaptation to varying budget needs and selection preferences across query regions a key challenge. We introduce QASparse, a Query-Adaptive Sparse attention mechanism with hardware-efficient execution. QASparse preserves the efficiency of shared cross-head importance estimation while adapting computational budgets and token selections to query requirements, and it executes these dynamic sparse decisions through dedicated kernels. Its query adaptivity stems from two complementary innovations: Local Budget Regression models local variations in computational demand along query positions to estimate budgets for different query regions and attention heads; Boundary Voting lets queries within each head vote over candidates near the selection cutoff using actual query/key scores, refining the retained set while preserving the initial selection size. To reduce the execution overhead of dynamic budgets, we further design length-specialized selection kernels that efficiently support query-adaptive sparse patterns across context lengths. Together, these designs efficiently combine shared estimation with local decisions while adapting both how much attention is computed and which interactions are retained. Experimental results demonstrate improved benchmark scores and faster prefill attention computation compared with existing sparse attention baselines.
Figures & tables
Figure 1: (a) Cross-head Top- k overlap decreases as k increases. (b) The budget for target attention coverage grows overall with query position but exhibits local variation. (c) Nearby queries can require substantially different budgets for the same 90% coverage.
Figure 2: Overview of Query-Adaptive Selection. (a) Budgets are estimated from regularly sampled queries, and sliding-window regression predicts token requirements. (b) QK scores are used to vote among key blocks near the cutoff of the shared ranking, refining block selection while preserving the voting budget. (c) Sparse attention patterns before and after Boundary Voting.
Figure 3: (a) Long context: The kernel keeps a larger, intact group of sampled Q vectors in SRAM and streams through all visible K blocks within one logical workload. (b) Short context: The kernel splits the same Q workload into smaller groups Q1 and Q2 and pairs each group with the K partitions.
Models
Methods
4k
8k
16k
32k
64k
128k
Avg
Llama
FlashAttention
95.18
93.36
93.26
89.28
85.56
77.96
89.10
FlexPrefill
94.59
93.53
92.58
91.59
85.18
73.67
88.52
ProxyAttn
94.12
92.25
93.35
90.34
87.24
75.15
88.74
QASparse
94.90
93.21
93.75
92.22
87.70
77.82
89.93
GLM
FlashAttention
94.26
92.68
91.42
89.27
85.04
84.45
89.52
FlexPrefill
92.46
91.40
90.64
87.69
86.70
84.34
88.87
Table 1: Performance comparison of different methods on various models and sequence lengths on RULER. The best results are highlighted in bold.
Models
Methods
En.Sum
En.QA
En.MC
En.Dia
Zh.QA
Code.Run
Math.Find
Retr.Passkey
Retr.Number
Retr.KV
Avg
FlashAttention
35.22
34.98
81.82
20.00
42.67
0.00
16.67
96.67
100.00
60.00
48.80
FlexPrefill
32.87
28.01
72.73
30.00
36.40
0.00
22.22
96.67
100.00
48.00
46.69
ProxyAttn
32.09
33.22
72.73
10.00
43.72
0.00
22.22
93.33
100.00
40.00
44.73
Llama
QASparse
35.13
38.58
72.73
10.00
41.42
0.00
22.22
96.67
100.00
56.00
47.28
FlashAttention
29.32
28.57
72.73
30.00
17.10
0.00
27.78
96.67
90.00
0.00
39.22
FlexPrefill
34.92
28.08
72.73
20.00
16.01
0.00
16.67
100.00
83.33
0.00
37.17
Table 2: Performance comparison of different methods on various models and tasks on Infinite Bench. The bold numbers indicate the first highest value in each column.
Figure 4: RULER quality–latency trade-offs. At 4k, QASparse’s specialized short-context kernel supports approximately 3× speedup over ProxyAttn at comparable accuracy. The dashed line denotes Full Attention.
Figure 5: The horizontal 1× line marks the geometric-mean latency of the two kernels at each context length. Speedup is this reference latency divided by the latency of the indicated kernel.
Appendix figures & tables23 assets
Supplementary material from the paper’s appendix.
Appendix
Threshold
High-to-low
Low-to-high
Gap
20%
67.53
19.19
+48.33
30%
77.79
45.69
+32.10
40%
84.92
70.15
+14.77
Appendix
Table 3: RULER scores of Llama-3.1-8B base at 4k, averaged equally over 13 tasks with 20 fixed examples per task.
Method
Rankings
4k
8k
16k
32k
64k
128k
Mean ↑
ProxyAttn
1
95.00
93.67
91.73
90.57
87.76
85.45
90.70
QASparse
1
95.05
93.46
92.97
90.39
87.53
86.03
90.91
ProxyAttn
2
95.31
93.25
92.21
90.21
87.60
85.97
90.76
QASparse
2
95.29
93.77
93.31
91.24
86.05
86.31
90.99
ProxyAttn
4
95.21
93.73
92.44
90.62
87.70
85.61
90.89
QASparse
4
95.36
93.85
93.33
90.22
86.86
86.01
90.94
Appendix
Table 4: RULER scores of GLM-4-9B-Chat-1M across shared-ranking counts.
Method
Rankings
4k
8k
16k
32k
64k
128k
Mean ↑
ProxyAttn
1
94.12
92.25
93.35
90.34
87.24
75.15
88.74
QASparse
1
94.90
93.21
93.75
92.22
87.70
77.82
89.93
ProxyAttn
2
94.68
92.55
93.39
90.17
86.52
77.60
89.15
QASparse
2
94.29
91.91
93.34
90.56
87.11
77.40
89.10
ProxyAttn
4
94.42
93.05
94.03
90.61
86.00
78.04
89.36
QASparse
4
94.82
92.73
94.28
91.73
86.48
77.35
89.56
Appendix
Table 5: RULER scores of Llama-3.1-8B-Instruct across shared-ranking counts.
Method
Rankings
4k
8k
16k
32k
64k
128k
Mean ↑
ProxyAttn
1
93.51
90.84
88.43
87.09
83.80
84.39
88.01
QASparse
1
94.21
92.30
87.96
86.94
83.00
85.30
88.29
ProxyAttn
2
93.13
90.32
86.74
86.72
83.98
84.82
87.62
QASparse
2
93.80
91.03
86.63
86.12
82.76
85.62
87.66
ProxyAttn
4
93.71
90.92
87.23
87.49
84.22
84.63
88.03
QASparse
4
94.09
91.76
87.02
87.25
83.42
84.62
88.03
Appendix
Table 6: RULER scores of MegaBeam-Mistral-7B-512k across shared-ranking counts.
Method
Rankings
4k
8k
16k
32k
64k
128k
Mean ↑
ProxyAttn
1
94.17
91.91
92.42
87.60
86.04
81.17
88.88
QASparse
1
94.35
92.21
92.91
88.95
86.54
82.52
89.58
ProxyAttn
2
94.63
91.58
92.30
87.74
86.82
81.27
89.06
QASparse
2
94.24
92.23
93.14
88.76
87.92
83.08
89.89
ProxyAttn
4
94.29
91.71
92.63
88.80
86.93
82.27
89.44
QASparse
4
94.51
91.54
92.87
89.31
87.84
83.73
89.97
Appendix
Table 7: RULER scores of Qwen2.5-7B-Instruct-1M across shared-ranking counts.
Setting
4k
8k
16k
32k
64k
128k
Mean ↑
4 candidate blocks
92.67
92.29
91.69
88.90
88.73
80.41
89.12
8 candidate blocks
92.74
92.55
91.50
89.13
89.00
79.55
89.08
16 candidate blocks
92.67
93.51
91.76
89.67
88.92
78.71
89.21
32 candidate blocks
91.78
92.74
91.83
89.44
88.40
79.68
88.98
Appendix
Table 8: RULER scores of Llama-3.1-8B-Instruct for different total candidate-block counts.
Length
Short (ms)
Long (ms)
Reference (ms)
Short speedup ( × )
Long speedup ( × )
8k
0.42
0.77
0.569
1.354
0.739
16k
1.16
1.50
1.319
1.137
0.879
32k
4.10
2.56
3.240
0.790
1.266
64k
78.28
5.31
20.388
0.260
3.840
128k
460.30
11.82
73.761
0.160
6.240
256k
1165.54
35.51
203.441
0.175
5.729
Appendix
Table 9: Selection-kernel latency and speedup relative to the geometric-mean latency at each context length.
Setting
4k
8k
16k
32k
64k
128k
Mean ↑
Global Linear Regression
92.74
92.74
91.83
88.51
89.15
76.74
88.62
Non-overlapping Piecewise Linear Regression
92.74
92.74
91.06
89.74
89.04
79.68
89.17
Sliding-window Linear Regression
92.67
93.51
91.76
89.67
88.92
78.71
89.21
Appendix
Table 10: RULER scores of Llama-3.1-8B-Instruct for the three budget-regression schemes.
Method
Enabled
Disabled
FlexPrefill
88.28
88.59
ProxyAttn
88.67
81.27
QASparse
89.21
84.69
Appendix
Table 11: RULER mean scores with and without full attention on the final two query blocks.
Setting
4k
8k
16k
32k
64k
128k
Mean ↑
Force final two query blocks
92.67
93.51
91.76
89.67
88.92
78.71
89.21
No final-block override
91.90
90.21
86.08
83.40
83.65
72.88
84.69
Appendix
Table 12: RULER scores with and without the final-two-query-block full-attention override.
Setting
4k
8k
16k
32k
64k
128k
Mean ↑
Shared ranking for budget label
92.67
93.51
91.76
89.67
88.92
78.71
89.21
True ranking for budget label
91.90
92.63
90.83
89.17
86.85
76.46
87.97
Appendix
Table 13: RULER scores for shared and true orderings in budget-label computation; initial selection uses the shared ranking in both cases.
Setting
4k
8k
16k
32k
64k
128k
Mean ↑
Max voting
92.67
93.51
91.76
89.67
88.92
78.71
89.21
Exponential-sum voting
91.97
92.74
91.83
89.67
89.46
78.91
89.10
Appendix
Table 14: RULER scores for maximum and exponential-sum scoring in Boundary Voting.
Figure 6: RULER quality–latency trade-offs across context lengths.
Method
4k
8k
16k
32k
64k
128k
FlashAttention
0.71
2.48
9.47
36.57
143.77
595.57
QASparse ( γ=0.90 )
0.77
1.97
5.61
16.44
48.61
211.74
Appendix
Table 15: Attention latencies (ms) of Llama-3.1-8B-Instruct.
Context
Proxy Q/K
Proxy Scores
Sorting
Budget Labels
Regression
Voting
Attention
64k
141.62 (0.47%)
17.10 (0.06%)
3.12 (0.01%)
41.56 (0.14%)
0.09 (0.00%)
8.56 (0.03%)
538.37 (1.79%)
128k
275.39 (0.68%)
64.60 (0.16%)
11.76 (0.03%)
141.17 (0.35%)
0.17 (0.00%)
32.30 (0.08%)
1058.40 (2.60%)
Appendix
Table 16: Memory usage in MB (percentage of peak GPU memory).
Method
4k
8k
16k
32k
64k
128k
Avg
ProxyAttn
92.67
92.67
91.76
89.05
87.62
78.27
88.67
Shared ranking + Boundary Voting
92.67
92.67
92.72
89.05
87.92
78.08
88.85
Shared ranking + Regression
91.97
92.47
91.56
89.28
89.04
78.33
88.78
QASparse
92.67
93.51
91.76
89.67
88.92
78.71
89.21
Appendix
Table 17: Component ablations across all 13 RULER subtasks. Avg reports the six-length mean score.
Method
4k
8k
16k
32k
64k
128k
Mean
FlashAttention-2
95.18
93.36
93.26
89.28
85.56
77.96
89.10
FlexPrefill
94.59
93.53
92.58
91.59
85.18
73.67
88.52
ProxyAttn
94.12
92.25
93.35
90.34
87.24
75.15
88.74
QASparse ( γ=0.95 )
94.90
93.21
93.75
92.22
87.70
77.82
89.93
QASparse ( γ=0.90 )
94.16
92.02
93.98
91.46
88.01
76.16
89.30
Appendix
Table 18: RULER scores of Llama-3.1-8B-Instruct.
Method
4k
8k
16k
32k
64k
128k
Mean
FlashAttention-2
94.26
92.68
91.42
89.27
85.04
84.45
89.52
FlexPrefill
92.46
91.40
90.64
87.69
86.70
84.34
88.87
ProxyAttn
95.00
93.67
91.73
90.57
87.76
85.45
90.70
QASparse ( γ=0.95 )
95.05
93.46
92.97
90.39
87.53
86.03
90.91
QASparse ( γ=0.90 )
95.02
93.18
92.82
90.13
87.06
83.06
90.21
Appendix
Table 19: RULER scores of GLM-4-9B-Chat-1M.
Method
Sum.
QA En
Choice
Dial.
QA Zh
Code
Math
Passkey
Num.
KV
Mean
FlashAttention-2
35.22
34.98
81.82
20.00
42.67
0.00
16.67
96.67
100.00
60.00
48.80
FlexPrefill
32.87
28.01
72.73
30.00
36.40
0.00
22.22
96.67
100.00
48.00
46.69
ProxyAttn
32.09
33.22
72.73
10.00
43.72
0.00
22.22
93.33
100.00
40.00
44.73
QASparse ( γ=0.95 )
35.13
38.58
72.73
10.00
41.42
0.00
22.22
96.67
100.00
56.00
47.28
QASparse ( γ=0.90 )
34.02
33.51
72.73
20.00
41.57
0.00
22.22
96.67
100.00
52.00
47.27
Appendix
Table 20: InfiniteBench scores of Llama-3.1-8B-Instruct. Task columns denote longbook summary, English longbook QA, longbook choice, dialogue QA, Chinese longbook QA, code execution, math finding, passkey, number-string retrieval, and KV retrieval, respectively.
Method
Sum.
QA En
Choice
Dial.
QA Zh
Code
Math
Passkey
Num.
KV
Mean
FlashAttention-2
29.32
28.57
72.73
30.00
17.10
0.00
27.78
96.67
90.00
0.00
39.22
FlexPrefill
34.92
28.08
72.73
20.00
16.01
0.00
16.67
100.00
83.33
0.00
37.17
ProxyAttn
31.13
27.49
72.73
20.00
17.62
0.00
27.78
96.67
80.00
0.00
37.34
QASparse ( γ=0.95 )
28.78
28.47
72.73
30.00
17.52
0.00
22.22
96.67
80.00
0.00
37.64
QASparse ( γ=0.90 )
29.23
25.48
72.73
30.00
17.26
0.00
22.22
96.67
73.33
0.00
36.69
Appendix
Table 21: InfiniteBench scores of GLM-4-9B-Chat-1M. Task columns denote longbook summary, English longbook QA, longbook choice, dialogue QA, Chinese longbook QA, code execution, math finding, passkey, number-string retrieval, and KV retrieval, respectively.
Model
Length
FA2
QASparse
Increase
Llama-3.1-8B-Instruct
64k
28.12
28.25
0.46%
Llama-3.1-8B-Instruct
128k
38.66
39.15
1.27%
MegaBeam-Mistral-7B-512k
64k
26.65
26.78
0.49%
MegaBeam-Mistral-7B-512k
128k
37.19
37.68
1.32%
GLM-4-9B-Chat-1M
64k
29.27
29.40
0.44%
GLM-4-9B-Chat-1M
128k
38.05
38.55
1.31%
Appendix
Table 22: Peak GPU memory (GiB) and relative increase over FlashAttention-2.
Context
Proxy Q/K
Proxy Scores
Sorting
Budget Labels
Regression
Voting
Attention
128k
0.85
0.89
0.03
2.98
0.03
0.54
94.68
256k
0.49
0.63
0.02
1.72
0.01
0.47
96.66
512k
0.03
0.51
0.01
1.75
0.01
0.20
97.49
768k
0.05
0.46
0.03
1.09
0.01
0.23
98.14
Appendix
Table 23: Mean per-layer stage-time shares (%) for Llama-3.1-8B-Instruct at γ=0.95 .
Figure 7: Budget estimates on selected RULER 4k examples. Each point is a mean over valid queries in a 128-token query block, and horizontal positions are block centers divided by input length.
LLM inference acceleration develops algorithms and systems that reduce language-model latency, memory use, and serving cost while preserving output quality.
Attention is a major scalability bottleneck in large language models (LLMs), with its computational cost and key-value (KV) memory traffic becoming increasingly prohibitive as context length grows. Sparse attention addresses this bottleneck by restricting each query to a subset of the context, but its effectiveness hinges on identifying relevant regions both cheaply and reliably. Existing training-free methods primarily rely on runtime relevance estimates, with selection dimensionality and granularity typically governed by fixed heuristics rather than the intrinsic interaction structure of pretrained attention heads. We take a different perspective: the query-key operator of each pretrained head defines a characteristic response structure that determines the resolution needed for sparse selection, both across feature directions and across context tokens. Building on this insight, we propose Head-Adaptive Sparse Attention (HASA), a training-free sparse attention framework that jointly adapts selection resolution along these two dimensions. Along the feature dimension, the singular spectrum of each head's query-key operator determines an effective rank, yielding a compact, head-specific response space. Along the sequence dimension, neighboring regions are progressively merged according to the directional coherence of their token responses in this same space, while heterogeneous regions remain separate. Exact attention is then computed using the original full-dimensional KV states of the selected regions. HASA captures 88.1% of dense-attention mass and, compared with UNIQUE, a strong recent sparse-attention baseline, improves accuracy by up to 3.47 and 2.57 points on RULER and LongBench-Pro, respectively, and accelerates self-attention by up to 1.32x, while achieving up to 14.07x speedup over dense attention.
Sparse attention reduces the cost of long-context attention, but existing kernels typically process queries independently, repeatedly loading and dequantizing KV entries shared across queries. We observe substantial overlap in the KV entries selected by neighboring queries, creating opportunities for cross-query reuse. We present QUILT, a workload-aware sparse-attention execution mechanism that jointly processes neighboring queries and reuses shared KV entries to reduce redundant memory traffic and computation. QUILT introduces Shift-and-Compare Set Decomposition (SCSD), which transforms irregular set operations into regular data-parallel primitives suitable for modern accelerators, and pipelines SCSD with attention computation to hide its overhead. Cascaded sharing captures reuse hierarchically at multiple granularities. A tile-aware execution strategy balances sharing granularity with hardware tile utilization and selectively removes low-importance query-specific tails to eliminate underutilized tiles. We evaluate QUILT on LongBench using GLM-5.3 and DeepSeek-3.2 under both tensor and sequence parallelism. Compared with the state-of-the-art sparse-attention kernel, QUILT reduces average kernel latency by up to 55.1% and processed KV data by up to 55.9%, while reducing time-to-first-token (TTFT) latency by up to 36.8% with negligible accuracy degradation.
The quadratic complexity of self-attention during the prefill phase impedes long-context inference in large language models. Existing sparse attention methods face a trade-off among context adaptivity, sampling overhead, and fine-tuning costs. We propose VSPrefill, a mechanism requiring lightweight training that uses the vertical-slash structural pattern in attention distributions. Our compact VSIndexer module predicts context-aware importance scores for vertical columns and slash diagonals from key-value representations augmented with RoPE. This approach constructs sparse masks with linear complexity without modifying the backbone parameters. During inference, an adaptive cumulative-threshold strategy allocates sparsity budgets per layer, while a fused kernel executes attention with on-the-fly index merging. Evaluated on Qwen3-4B-Instruct and LLaMA-3.1-8B-Instruct across the LongBench and RULER benchmarks, VSPrefill preserves 98.35% of the full attention accuracy while delivering a 4.95x average speedup at a context length of 128k. These results establish a new Pareto frontier in the trade-off between accuracy and efficiency.
Chen Guanzhong
School of Computer Science and Technology, Tongji University