WorksComputer Science
RefineKV: Query-Adaptive KV Cache Compression via Attention-Error Bounds
Abstract
Repeatedly accessing the full key–value (KV) cache is a major bottleneck in long-context language model decoding. We find that small query-specific subsets can accurately approximate full attention, yet their union covers nearly the entire cache, motivating query-adaptive access for the KV cache. A natural approach is to split the KV cache into clusters, using compact representatives for clusters that incur negligible error while expanding the rest to their original KV entries. We derive a selection criterion from an upper bound on attention-output error, which reveals two complementary factors governing the error: importance measures the impact of a cluster, while distortion measures how faithfully the cluster can be represented. Based on this criterion, we propose RefineKV, a decoding-time query-adaptive KV compression method. Experiments on two models and three benchmarks demonstrate that RefineKV retains near-full-attention quality while achieving up to 7.6x speedup in the attention phase and 1.66x faster decoding, establishing a new quality-latency Pareto frontier.
Introduction
Context has emerged as a fundamental resource for modern language model inference in both reasoning LLMs ([8]) and interactive agent systems ([31]). During autoregressive decoding with full attention, each token computes attention weights between its query vector and the key vectors of preceding context tokens, then uses these weights to aggregate their value vectors ([27]). To avoid redundant computation, the key and value vectors for context tokens are stored as the Key-Value (KV) cache ([15]). However, repeatedly accessing this massive KV cache at every generation step incurs severe overhead, making attention a substantial decoding bottleneck in long-context regimes ([25]).
KV cache compression aims to reduce the amount of data accessed by every decoding query while minimizing the deviation of compressed output from full attention output, typically through eviction ([15, 30, 20] (Zhang et al. 2023)), merging ([29] (Zhang et al. 2024)) or quantization ([17]). To examine the potential for reducing KV access, we ask a key question: how much of the KV cache is necessary for each query to approximate attention output with high fidelity? Our findings reveal that a relatively small query-specific subset is already sufficient. However, these subsets vary substantially across queries, and their union covers nearly the entire KV cache. This gap reveals that different queries attend to sparse but different parts of the KV cache, which suggests that, rather than compressing the KV cache into a fixed subset for all future queries, the accessed subset should adapt to the current query ([25, 10, 18, 19, 4]).
Query-adaptive access raises a central challenge: given a query, how can we decide which part should be accessed without reading the full KV cache? We move access decisions to a coarser granularity, using a compact summary to assess a group of KV entries without inspecting its individual members. Specifically, we partition the cache into clusters and precompute a compact summary for each cluster to guide query-dependent access. Selected clusters are expanded to expose their original KV entries, while the remaining clusters are approximated by compact representatives. Within this paradigm, the next question is: how can we identify clusters whose representative approximation introduces negligible attention-output error?
We address this question with a cluster-wise risk score. Starting from a decomposition of the attention-output error, we derive an upper bound on the overall approximation error and use its cluster-wise terms as risk scores. The cluster-wise score captures the joint effect of global importance, measured by a cluster’s approximate attention mass, and local distortion, characterized by the spread of its attention logits under the current query. Under this criterion, high-importance clusters require tighter local approximation to remain within the same risk tolerance, while lower-importance clusters can tolerate greater distortion. Empirically, the resulting score correlates strongly with the actual attention-output error caused by cluster approximation.
Based on this risk score, we propose REFINEKV, a query-adaptive KV compression method for efficient decoding. After prefill, REFINEKV partitions the KV cache into contiguous clusters and precomputes their representatives and auxiliary metadata for computing risk score, while retaining the original KV entries for selective expansion. At each decoding step, cluster risk scores are computed from the current query and the cached summaries. Clusters whose risk score exceeds a predefined threshold are expanded to their original KV entries, while the remaining clusters are each compressed into a single representative. An attention operation over this mixed representation produces the approximate output. Experiments on two models and three benchmarks demonstrate that REFINEKV retains near-full-attention quality while achieving up to 7.6× speedup in the attention phase and 1.66× faster decoding, establishing a new quality–latency Pareto frontier.
Motivation: From Eviction to Query-Adaptive Access
Autoregressive Transformers generate each token by conditioning on all previous tokens. Within an attention head, a query vector representing the current decoding position interacts with the key vectors of the context tokens at position to determine how their value vectors are aggregated. For a context of tokens and query , the full-attention output :
During decoding, the keys and values of previous tokens are reused across generation steps. The Key-Value cache (KV cache) stores these representations as , avoiding repeated computation. However, the cache grows linearly with context length , and full attention reads the entire cache for every query, which still incurs substantial decoding latency in long-context regimes. To mitigate this, KV cache compression methods [13, 30] (Zhang et al. 2023) aim to reduce KV data accessed by each query while minimizing the deviation of the compressed output from full attention output in Equation 1.
A fundamental question is: For any query, how much of the KV cache needs to be accessed to accurately approximate full attention? To examine this, we select the highest-weight KV entries for each query until their cumulative attention mass reaches . Figure 1 (left) shows how the percentage of KVs selected (bars) and the attention output error (line) vary with the amount of attention mass retained. The blue bars show the average fraction of KV items retained for each query. At an attention mass of , retaining merely 17.6% of the KV cache per query is sufficient to keep the approximation error down to 10%. This suggests that only a relatively small subset is crucial for accurately approximating the output for a particular query.

Figure 1. Left: Each query needs only a small KV subset, but together these subsets cover nearly the entire cache. For each query, we select the highest-weight KV entries needed to retain of its total attention weight. The figure compares sizes of these per-query subsets and their union across queries, alongside the resulting attention output error. At roughly 10% output error, each query needs only a small subset of the cache, yet their union covers most KV entries. Right: Query-adaptive methods surpass query-independent methods. Oracle query-adaptive top- attention achieves a markedly better perplexity–access trade-off than representative eviction baselines. Our method recovers a substantial portion of this advantage without oracle access.
However, compressing the cache into a fixed subset requires that the same subset remains sufficient to accurately approximate the full-attention output across different queries. This raises a second question: Are these crucial subsets shared across queries, such that a fixed subset of KV pairs could serve all future queries? The orange bars show the size of union of these query-specific subsets. Although an individual query requires only 17.6% of the cache at , their union spans 96.4% of the KV cache. One potential confounding factor is attention locality: each query tends to attend strongly to its immediately preceding tokens. Thus, the union may appear large even under a purely local attention pattern. To control for this effect, we remove the most recent 64 tokens for each query before computing the union. The gap remains substantial, as shown by the green bars. This gap shows that different queries rely on different KV pairs, therefore a fixed subset of cache simply cannot work for all queries. Detailed experimental setups are provided in Appendix § 12.§ 1.
These observations suggest a rethinking in the compression paradigm: rather than committing to a fixed subset of KV entries for all future queries, the accessed subset should adapt to the current query. We next examine whether such query-adaptive access indeed translates into a better end-to-end quality–efficiency trade-off. Figure 1 (right) illustrates a perplexity evaluation on WikiText-2. We consider three query-independent methods, H2O (Zhang et al., 2023), RoCo (Ren & Zhu, [23]), and TOVA (Oren et al., [20]), and contrast them with query-adaptive approaches: oracle top- selection, and our practical query-adaptive approach introduced in the following section. The query-independent methods exhibit a substantially less favorable quality–budget trade-off. This provides end-to-end evidence supporting query-adaptive access as a more effective compression paradigm.
Deciding What to Access: From Attention Error to Risk Score
Query-adaptive access leaves a central question: which KV entries should be accessed for the current query? Answering this question involves two requirements: efficiency and accuracy. Efficiency requires making access decisions without scanning every token-level KV entry, which would otherwise defeat the purpose of compression. Accuracy requires selecting tokens that incur minimal output deviation from full attention.
Cluster-based Access
For efficiency, as KV entries cannot be visited individually, we need to move access decisions to a coarser granularity, using a compact summary to assess a group of KV entries, to decide whether they should be accessed. A natural realization of this idea is to partition KV entries into clusters, and use only cluster-level summaries to decide which clusters require token-level access. Selected clusters are expanded to compute full attention, while unselected ones are either pruned entirely (Tang et al., [25]; Lu et al., [18]) or coarsely approximated by their representative tokens (Hooper et al., [10]; Ni et al., [19]).
In this work, we adopt the representative-based approximation route: clusters whose coarse-grained representation introduces negligible error in the attention output are represented by their compact representatives, whereas those that cannot be faithfully approximated are expanded to full attention. Intuitively, this paradigm allocates a “high-resolution” view to clusters that require precise access. Then we focus on the accuracy requirement, which is: how can we identify clusters whose approximation incurs negligible error in the attention output?
Upper Bounding Attention Error
To answer this question, we seek an efficiently computable, query-dependent risk score that can reflect the output error caused by approximating a particular cluster. Specifically, we start from decomposing the single-head attention-output error. Let be a partition of the KV cache. For each cluster , we use its mean key and value as a shared representative for every KV entry in . For a query , under full attention, let denote the total attention weight assigned to cluster , and let denote the attention-weighted average of its token values. Under approximation, the cluster receives total attention weight and contributes its mean value . Formally,
The error between exact attention output and approximate attention output can be decomposed as:
This decomposition separates the output error into two sources: The first term captures the redistribution of attention mass across clusters, whereas the second term captures the error caused by approximating with . After regrouping the first term (Lemma A.1), both terms are related to the dispersion the logits within a cluster: when all are close to , the cluster is well-approximated and both terms get close to zero.
Neither error term is directly computable from compact cluster summaries. We therefore bound these two terms using the maximum logit deviation: . However, computing exactly would require scanning all keys in the cluster. We therefore use an efficiently computable upper bound , constructed from compact cluster summaries (Details in Appendix A.7). Letting and , we have:
In (4), we write the resulting upper bound in a clusterwise form and use each clusterwise term as its risk score . The detailed derivation is provided in Appendix A. In the following section, we provide an analysis of this risk score: what it actually measures and whether it faithfully reflects the output error.
Importance and Distortion
The risk score derived from (4) captures two query-dependent factors that influence the approximation error: global importance, measured by approximated cluster attention mass , and local distortion, measured by and upper-bounded by .
Global Importance . Approximation error depends on how much the cluster contributes to the overall attention computation. If a cluster receives only a negligible fraction of the attention mass relative to the rest of the context, even a relatively coarse approximation may have little effect on the final attention output.
Local Distortion . For a given query, a cluster is easy to approximate when its tokens behave similarly under the query. In particular, if all are close to , replacing them by the representative introduces little error. Importantly, this distortion is query-dependent: a cluster may be dispersed in the original key space while remaining tightly concentrated along the direction relevant to the current query.
Crucially, the score captures the joint effect of both factors. A highly important cluster can only tolerate a small local approximation error, whereas a low-importance cluster can tolerate substantially larger internal variation. Figure 2 (Left) illustrates a sample from real data: Each point represents a cluster positioned by Local Distortion and Global Importance . The background color indicates the Risk score, and the tilted decision boundary adaptively balances against .
Figure 2. Left: Cluster selection is jointly determined by importance and distortion. Each point represents a cluster positioned by its global importance and local distortion . Background color encodes the risk score , with the dashed line denoting the decision boundary at . The tilted boundary captures their trade-off: important clusters tolerate only small local distortion, whereas low-importance clusters can tolerate larger distortion. Point colors indicate the error incurred on approximating cluster. Three cases show the within-cluster attention-score patterns. Right: Risk score strongly correlated with approximation error. These figures illustrate the correlation between Risk Score and cluster approximation error , where and denote original output and approximate output for cluster .
Beyond this theoretical intuition, the next question is whether risk score faithfully reflects the true output error caused by approximation. Figure 2 (Right) plots the risk score against the cluster approximation error , where and denote original output and approximate output for cluster . The results demonstrate a clear, robust correlation across different model architectures, confirming that our theoretical bound serves as an effective surrogate for actual approximation error. Appendix B.3 reports the partial correlation of score with the cluster error given .
RefineKV: Efficient Risk-Guided KV Access
The preceding analysis provides a principled Risk Score for deciding which clusters require token-level access. Turning this criterion into an efficient decoding method requires both making access decisions without scanning the full KV cache and ensuring that these decisions reduce actual KV reads. We address these requirements with REFINEKV, a query-adaptive KV access method that preserves the full cache while selectively accessing its original entries.
Pipeline Overview. We illustrate our pipeline in Figure 3. In prefill phase, we first compute the entire KV cache and then partition it into contiguous clusters and precompute cluster representative mean key and value as well as auxiliary metadata. At each decoding step , the incoming query interacts only with these cluster-level summaries to estimate the approximation risk score . Clusters with risk above a predefined threshold are expanded for token-level attention, while the remaining clusters are represented by their cached means. A single attention operation over this mixed representation produces the approximate output.
Figure 3. REFINEKV Pipeline. Prefill phase: The KV cache is partitioned into contiguous clusters, and a representative key-value pair together with auxiliary metadata is computed for each cluster. Decode phase: Each query uses the cached summaries to calculate risk score . Clusters with are expanded, while clusters with retain only their representatives. The resulting mixed KV sequence is used to compute the output . The color depth of each block indicates attention score.
Efficient Estimation of Risk Score. Evaluating the risk score in Eq. (4) requires four quantities: , , , and . Among these, is computed directly from the cluster size and centroid via Eq. (2), while and are precomputed cluster-level statistics. Finally, is derived from compact cluster summaries, with details deferred to Appendix A.7.
Determining the Expansion Set. Once the risk scores are available, we compare them with a threshold to determine which clusters should be expanded for token-level attention. For a single
query head, the rule is straightforward: expand clusters with and approximate the remaining clusters by their representatives. Modern large language models adopt Grouped-Query Attention (GQA) [1], where multiple query heads share a single key-value head. Because selection is executed at the KV-cache level, all query heads sharing a KV group must operate on a unified set of expanded clusters. We designate GQA-any as our default strategy: a cluster is expanded if the risk score evaluated by any query head within the group exceeds the threshold. We also consider an alternative aggregation heuristic, GQA-mean, which expands a cluster only when the average risk across the group exceeds ; we systematically ablate both approaches in § 5.3.
Efficient kernel implementation. Realizing the algorithmic sparsity of REFINEKV requires reducing actual KV-cache traffic. We first compute and cache the representative and bound statistics of each prompt block. At each decoding step, a lightweight block-selection kernel evaluates the expansion criterion of REFINEKV using the current query and these cached summaries, producing a mask that identifies the blocks requiring exact attention. The sparse-attention kernel consumes this mask directly on the GPU: it loads token-level K/V only from the selected blocks, while approximating the remaining blocks with their representatives. Appendix § 11.§ 2 provides the implementation details.
Experiments
Experiment Setup
Models. We conduct experiments on two open-sourced long context models: Llama-3.1-8B-Instruct [7] and Qwen2.5-7B-Instruct [22]. Both models support up to 128K context, which is the default setting we use. We add experiments for Qwen2.5-14B-Instruct in Appendix § 12.§ 5, and context length ablation in Appendix § 12.§ 7.
Benchmarks. We evaluate long-context generation on three representative benchmarks: Long-Bench [2], RULER [11], and HELMET [32], which cover complementary application scenarios. LongBench measures real-world long-document understanding across question answering, summarization, retrieval, and code completion. RULER uses controlled synthetic tasks to evaluate retrieval, association, and aggregation as the context length increases. HELMET covers diverse application-oriented workloads, testing whether the quality–efficiency trade-off generalizes across different patterns of long-context usage.
Baselines. We compare REFINEKV with Full Attention and five representative efficient-attention baselines. SnapKV [15] compresses the prompt KV cache by using attention statistics from a recent observation window. StreamingLLM [30] preserves attention-sink tokens together with a sliding window. PyramidKV [3] adaptively distributes the KV budget across layers. Quest [25] partitions the KV cache into pages and uses query-dependent key bounds to select pages that may receive high attention. Double-P [19] clusters prompt KVs and applies two-stage probability-mass pruning.
Metric. We use measured latency, rather than the retained KV budget, as our primary efficiency metric because methods with similar token budgets can have substantially different runtimes. Since prefill is performed only once and contributes a relatively small fraction of the total cost (Analysis in Appendix § 12.2.4), we focus on decode time per output token (TPOT), which reflects end-to-end decode performance rather than isolated attention phase latency. For quality, we follow the official metric of each task and report the unweighted macro-average across tasks.
Ours. We partition the KV sequence into contiguous clusters of 32 tokens and report the quality–latency trade-off using two thresholds, . For GQA aggregation, we use GQA-any introduced in § 4. All main results use no query anchors: at every decoding step, clusters are selected by alone. Query anchors, are an optional technique that further improves quality; we describe and evaluate them in Appendix § 11.§ 1.
Detailed model configurations, benchmark setups, baseline implementations, evaluation metrics, and hardware settings are provided in Appendix § 12.§ 2.
Main Results
Figure 4 shows that REFINEKV consistently provides a favorable quality–latency trade-off across both models and all three benchmarks. With the conservative threshold , REFINEKV nearly matches the quality of Full Attention in all six model–benchmark settings while reducing TPOT, achieving up to a decode speedup over Full Attention. Compared with both eviction-based and query-adaptive baselines, REFINEKV introduces new Pareto-optimal operating points, extending the empirical frontier toward lower latency without sacrificing quality. Increasing the threshold to enables more aggressive sparsification and further improves the maximum speedup to , although its effect on quality varies across tasks. Table 1 reports quality–latency results by task group, while Appendix § 12.§ 3.1 provides the per-task results.
Figure 4. Quality-latency trade-off of REFINEKV and existing KV-cache compression baselines. Experiments are evaluated across two models (Llama-3.1 and Qwen-2.5) on three long-context benchmarks (LongBench, RULER, and HELMET), with results averaged across all tasks. We present a conservative threshold , which matches full attention performance across all settings while achieving up to decode speedup as measured by Time Per Output Token (TPOT). Our method extends the quality–latency Pareto frontier.
| Method | LongBench | RULER | HELMET | |||||||||
| Doc QA | Summ. | Few-shot | Synth. | Code | NIAH | A&T | QA | RAG | LC-QA | ICL | Rec./Rank. | |
| Llama | ||||||||||||
| Full | 43.6/1.0 | 29.2/1.0 | 69.2/1.0 | 53.0/1.0 | 59.6/1.0 | 88.6/1.0 | 45.0/1.0 | 55.0/1.0 | 60.4/1.0 | 48.6/1.0 | 77.0/1.0 | 76.4/1.0 |
| Snap 10% | 41.2/1.7 | 23.4/1.7 | 65.9/1.7 | 53.4/1.7 | 58.5/1.7 | 79.5/1.7 | 40.7/1.7 | 55.0/1.7 | 61.0/1.7 | 48.4/1.6 | 77.0/1.6 | 60.7/1.5 |
| Snap 25% | 42.8/1.5 | 26.3/1.5 | 67.5/1.5 | 53.2/1.5 | 59.8/1.5 | 84.2/1.5 | 41.3/1.5 | 55.0/1.5 | 60.6/1.5 | 49.4/1.5 | 78.0/1.5 | 71.8/1.4 |
| Str. 10% | 32.7/1.7 | 22.2/1.7 | 63.3/1.7 | 47.5/1.7 | 56.1/1.7 | 11.2/1.7 | 29.8/1.7 | 37.5/1.7 | 53.5/1.6 | 42.4/1.6 | 75.0/1.6 | 8.6/1.5 |
| Str. 25% | 35.3/1.5 | 24.7/1.5 | 66.1/1.5 | 46.2/1.5 | 58.1/1.5 | 30.6/1.5 | 34.2/1.5 | 50.0/1.5 | 57.9/1.5 | 41.5/1.5 | 73.0/1.5 | 17.3/1.4 |
| Pyr. 10% | 41.3/1.7 | 23.6/1.7 | 66.0/1.7 | 53.3/1.7 | 58.4/1.7 | 79.7/1.7 | 39.2/1.7 | 55.0/1.7 | 61.0/1.7 | 49.0/1.6 | 75.0/1.6 | 63.9/1.5 |
| Pyr. 25% | 43.0/1.5 | 26.2/1.5 | 67.5/1.5 | 53.0/1.5 | 59.8/1.5 | 84.8/1.5 | 41.8/1.5 | 55.0/1.5 | 60.4/1.5 | 49.4/1.5 | 76.0/1.5 | 74.4/1.4 |
| Our .01 | 43.3/1.6 | 29.3/1.5 | 69.4/1.5 | 53.3/1.6 | 59.7/1.6 | 82.8/1.6 | 46.7/1.6 | 55.0/1.5 | 61.7/1.5 | 48.9/1.5 | 75.0/1.4 | 75.1/1.4 |
| Our .1 | 43.8/1.7 | 28.9/1.7 | 69.2/1.7 | 53.2/1.7 | 59.7/1.7 | 72.2/1.7 | 40.3/1.7 | 57.5/1.7 | 57.7/1.6 | 47.0/1.6 | 76.0/1.6 | 40.8/1.5 |
| Qwen | ||||||||||||
| Full | 43.2/1.0 | 27.8/1.0 | 69.9/1.0 | 54.5/1.0 | 64.1/1.0 | 74.8/1.0 | 57.6/1.0 | 42.5/1.0 | 48.5/1.0 | 50.8/1.0 | 76.0/1.0 | 39.5/1.0 |
| Snap 10% | 41.3/1.3 | 21.3/1.3 | 62.2/1.3 | 54.5/1.3 | 59.5/1.3 | 45.3/1.3 | 53.6/1.3 | 37.5/1.3 | 46.7/1.3 | 49.9/1.3 | 74.0/1.3 | 12.7/1.3 |
| Snap 25% | 42.8/1.3 | 23.9/1.3 | 66.2/1.3 | 54.5/1.3 | 62.0/1.3 | 51.2/1.3 | 57.9/1.3 | 40.0/1.3 | 49.2/1.3 | 49.1/1.2 | 75.0/1.2 | 22.2/1.2 |
| Str. 10% | 30.1/1.3 | 19.7/1.3 | 62.8/1.3 | 23.2/1.3 | 53.8/1.3 | 6.9/1.3 | 27.1/1.3 | 22.5/1.3 | 38.1/1.3 | 46.3/1.3 | 70.0/1.3 | 6.3/1.3 |
| Str. 25% | 33.0/1.3 | 22.5/1.3 | 65.9/1.3 | 33.1/1.3 | 57.8/1.3 | 22.0/1.3 | 30.3/1.3 | 40.0/1.3 | 39.8/1.3 | 47.3/1.2 | 75.0/1.2 | 10.2/1.2 |
| Pyr. 10% | 40.5/1.3 | 22.2/1.3 | 61.9/1.3 | 54.5/1.3 | 60.0/1.3 | 38.1/1.3 | 52.0/1.3 | 35.0/1.3 | 47.3/1.3 | 49.0/1.3 | 71.0/1.3 | 10.2/1.3 |
| Pyr. 25% | 42.1/1.3 | 24.2/1.3 | 66.9/1.3 | 54.5/1.3 | 62.1/1.3 | 48.8/1.3 | 54.7/1.3 | 40.0/1.3 | 45.6/1.2 | 48.7/1.2 | 75.0/1.2 | 13.5/1.2 |
| Our .01 | 43.0/1.2 | 27.8/1.2 | 69.8/1.2 | 54.5/1.2 | 64.0/1.2 | 73.3/1.2 | 59.1/1.2 | 42.5/1.2 | 49.2/1.1 | 50.8/1.2 | 76.0/1.1 | 38.7/1.1 |
| Our .1 | 43.0/1.3 | 27.9/1.3 | 69.7/1.3 | 54.2/1.3 | 63.5/1.3 | 67.2/1.3 | 57.3/1.3 | 37.5/1.3 | 49.4/1.2 | 50.7/1.2 | 76.0/1.2 | 33.3/1.2 |
Table 1. Task-group quality–latency comparison. Each cell reports Accuracy/Acceleration, where Accuracy is the task-macro benchmark score and Acceleration is latency acceleration relative to Full, higher is better for both. Shaded cells are Pareto-optimal. Underlined cells have an absolute Accuracy drop versus Full of less than 0.5 point. Baselines use SnapKV/StreamLLM/PyramidKV.
Outperform full attention in certain tasks. Interestingly, our method can outperform full attention on tasks dominated by irrelevant context like LongBench-GovReport or RULER-NIAH-MultiKey. One possible explanation is that preserving salient blocks exactly while representing less relevant blocks acts as an adaptive information filter, allowing the model to focus more on task-relevant evidence.
Latency Breakdown. Figure 5 shows that RefineKV substantially reduces decoding latency. Under BF16, it achieves a 7.6× attention speedup and a 1.66× overall decoding speedup. The overall gain is limited by non-attention operations, particularly the GEMV kernels. FP8 cuts GEMV from 10.8 ms to 5.8 ms per step, under FP8, the overall decoding speedup increases to 2.00×. Results are measured on Llama-3.1-8B-Instruct with 128K input.
Figure 5. Latency Breakdown.
Ablation Study.
We ablate on Llama-3.1-8B-Instruct with RULER-128K; Ours uses , , the box summary, GQA-any and .
Selection score. Table 2 fixes the per-head token budget to that of Ours and changes only the score that ranks clusters. Importance alone () or deviation alone () falls far behind , and the Quest-style logit bound is also lower. The exact- oracle shows that a tighter summary would help most at small budgets.
| Score | Acc. | Acc. | ||
| Ours (, box) | 70.27 | — | 62.58 | — |
| , ellipsoid | 68.90 | −1.37 | 57.29 | −5.28 |
| Quest-style | 66.38 | −3.88 | 58.87 | −3.71 |
| 58.78 | −11.49 | 41.38 | −21.19 | |
| 59.35 | −10.92 | 42.87 | −19.71 | |
| 47.23 | −23.04 | 20.68 | −41.90 | |
| , exact | 72.00 | +1.73 | 69.06 | +6.49 |
| Full attention | 73.37 | +3.10 | 73.37 | +10.79 |
Table 2. Selection-score ablation at a matched per-head token budget (Llama-3.1-8B-Instruct, RULER-128K, ). Only the score that ranks clusters changes. is relative to Ours. Exact is an oracle that scans all keys.
Design choices. Table 3 changes one setting at a time. is the main quality–latency knob; barely affects accuracy; GQA-mean is slightly faster but less accurate; the box summary beats the ellipsoid in every setting; and prompt-query anchors further improve accuracy at some cost in speed (Appendix B.1).
| Metric | Ref. | Threshold | Cluster size | GQA | Summary | Anchors | ||||
| Full | Ours | mean | ellipsoid | |||||||
| Acc. | 73.37 | 70.19 | 73.63 | 62.58 | 34.67 | 70.36 | 70.34 | 68.82 | 68.90 | 72.99 |
| TPOT (ms) | 24.43 | 15.68 | 19.08 | 14.62 | 14.42 | 15.86 | 16.20 | 15.06 | 15.14 | 17.14 |
| Speedup | 1.00 | 1.56 | 1.28 | 1.67 | 1.69 | 1.54 | 1.51 | 1.62 | 1.61 | 1.43 |
Table 3. Ablation study of Llama-3.1-8B-Instruct on RULER-128K. Ours is the default configuration: , , box deviation summary, GQA-any, no prompt-query anchors (). Each other column changes one setting. TPOT is steady-state decode latency at 128K input under CUDA Graph; speedup is relative to Full Attention.
Related Works
Eviction-based KV Cache Compression. A prominent line of work reduces KV-cache overhead by permanently retaining only a subset of tokens deemed important ([30, 3, 9, 20, 23, 14] (Zhang et al. 2023)). H2O ((Zhang et al., 2023)) identifies heavy-hitter tokens from accumulated attention statistics and dynamically preserves them together with recent tokens. StreamingLLM ([30]) exploits the attention-sink phenomenon and maintains a small set of initial sink tokens alongside a sliding window of recent tokens. Another line of work compresses the cache by merging multiple KV states into fewer representatives ([28, 29, 33, 12] (Zhang et al. 2024)); while retaining more aggregate information than hard eviction, such merging is still generally lossy because the original token-level states cannot be exactly recovered once combined. Despite their different compression mechanisms, these methods make irreversible decisions about the KV cache: discarded or merged token-level states are no longer fully accessible to future queries.
Query-Aware Cluster-Based Attention. To avoid the irreversible information loss, another line of work preserves recoverable access to the original KV states and performs query-conditioned sparse attention at inference time. Block-based methods ([25, 18, 26]) partition the KV cache into contiguous pages and use compact page-level statistics to identify regions relevant to the current query. Quest ([25]) estimates the importance of each page using coordinate-wise key extrema and loads only the highest-scoring pages for exact attention. More recent methods, including Multipole Attention ([10]) and Double-P ([19]), further adopt a coarse-to-fine, mixed-resolution design. These approaches establish block and cluster summaries as an efficient interface for query-dependent access to long contexts. However, their refinement decisions are primarily driven by estimated attention scores, rather than by a direct characterization of the attention-output error introduced when a cluster remains at low resolution.
Adaptive Sparse-Attention Selection. Recent KV compression and sparse attention methods have increasingly explored adaptive computation budgets to accommodate the heterogeneous attention patterns across heads, layers, and queries ([6, 3]). A fixed top- budget cannot adapt to the substantial variation in attention concentration across queries, heads, and layers. Twilight ([16]) addresses this limitation by introducing top-p pruning, which dynamically adjusts the retained set. Tactic (Zhu et al., 2025)) uses function fitting to estimate the weight distributions under top-p clustering. Our method provides a complementary route to adaptive budgeting: instead of explicitly prescribing or allocating a budget, we expand clusters according to their query-conditioned approximation risk. Consequently, the KV access budget emerges naturally from error control, allocating more computation only when a coarse representation is insufficient to faithfully approximate the attention output.
Limitations and Future Work
Our work has several limitations that suggest promising directions for future research.
End-to-end error guarantee. Our theoretical analysis focuses on the approximation error of a single-head attention output and does not characterize how such errors propagate through Transformer layers. Extending the analysis toward end-to-end guarantees remains a challenging yet important direction.
Mixed-state re-scoring. RefineKV scores all clusters once, in the state where every cluster is approximated. Eq. (4) also bounds the output once some clusters are expanded, but expanding a cluster changes the softmax normalizer, so scores computed before expansion no longer match the error terms afterward. A natural extension is to re-score the remaining clusters after each round of expansion. This would track the error of the mixed output more closely, at the cost of extra rounds of KV access during decoding. Making this cheap, for example by updating the normalizer incrementally or limiting it to a few rounds, is left for future work.
Better estimation of . Our selection rule relies on a computable upper bound on the logit deviation of each block, which is cheap to evaluate but can be loose. When we replace this bound with the oracle , computed exactly from the keys and values inside each block, the method achieves a consistently better quality–compression trade-off under the same budget. We leave the design of tighter yet efficient approximations to it as future work.
Hierarchical clustering. our current method adopts contiguous clustering. A natural extension is hierarchical clustering, where decoding starts from coarse cluster summaries and progressively expands only the regions that require higher-resolution access. Such a hierarchy could enable flexible allocation of KV access budgets and provide a better trade-off between accuracy and decoding efficiency.
Other modalities. RefineKV is modality-agnostic: its summaries, score and kernels operate only on cached keys and values. Extending it to vision-language models raises two questions we leave to future work. First, contiguous blocks of raster-ordered patches may group spatially distant tokens, so 2D-tile or spatio-temporal clustering may yield tighter summaries; since decode attention does not depend on the order in which keys are stored, this only requires reordering tokens once at prefill. Second, fine-grained visual tasks such as OCR or small-object grounding may need a smaller , and differing value scales across modalities may call for per-modality thresholds.
Conclusion
In this work, we revisit KV compression from the perspective of query-adaptive access. Starting from attention output error, we derive a query-dependent cluster-wise risk score that characterizes whether each cluster can be faithfully approximated. Based on this criterion, we present RefineKV, a query-adaptive KV access method that preserves the full cache while selectively expanding clusters that require fine-grained attention. Experiments show that RefineKV achieves a favorable trade-off between quality and efficiency.
Acknowledgments
This work was funded by the National University of Singapore under its Start-up Grant (Award No: SUG-25IRES2505).
Derivation for cluster selection criterion
We provide a detailed derivation of our selection criterion in the following section. We present the formulation for a single attention head and omit layer and head indices for clarity.
Setup.
Let denote the KV cache, where , . Let be a partition of the KV cache. For each cluster , let and define
For a query , define the token and representative logits as
The exact and approximated unnormalized masses of cluster are
Equivalently, the representative of has logit .
The exact and approximated total mass are:
Define the exact within-cluster output
and the exact and approximated cluster probabilities
The exact and approximated attention outputs are therefore
Let
Decomposition of attention output.
We first decompose the single-head attention output into inter-cluster mass redistribution and intra-cluster value distortion. Defining the auxiliary output , we have:
This decomposition separates the output error into two sources: inter-cluster mass redistribution and intra-cluster value distortion. It reveals that the approximation error arises through two mechanisms: The first term, , reflects how the estimated cluster probability mass deviates from the real mass, capturing the redistribution of attention mass across clusters caused by approximating with cluster representatives.
The second term describes the error caused by approximating with . It satisfies a desired property: For a cluster , when all are close to , the cluster is well-approximated and this term gets close to zero. In particular, if , the term becomes exactly zero.
The first term, , does not satisfy this property. It reflects shift in probability assigned to cluster , which is coupled with approximation of all clusters due to softmax normalization. Instead, we want to measure how approximating cluster impacts the overall output. Therefore, we regroup the first term in a source-wise way.
Regrouping Inter-cluster mass redistribution
Lemma A.1 (Core Lemma: Source-wise regroup of inter-cluster mass redistribution). Define the auxiliary output
the cluster mass correction factor
Then the inter-cluster mass redistribution error admits the exact source-wise decomposition
In particular, if cluster has no mass approximation error, i.e., (equivalently, ), its source-wise contribution to the mass-redistribution error is exactly zero.
Using Lemma A.1, we first rewrite as:
With :
To connect the local mass correction with the approximation fidelity of cluster , we define the query-dependent logit deviation
By technical lemma A.2, . Note that , which gives
Since is monotonically increasing for , we obtain:
Intra-cluster value distortion
For the intra-cluster value distortion term, define the exact within-cluster attention weights as
Then
Therefore,
By Lemma A.3, since , and
we have
Hence,
Finally,
Combining Eq. (22) and Eq. (32) via the triangle inequality, we have
The maximum logit deviation , however, cannot be used directly for access decisions, since evaluating it requires inspecting all keys within cluster , defeating the purpose of cluster-level selection. We therefore construct an efficiently computable query-dependent upper bound from compact cluster statistics, such that
The specific construction of is deferred to Appendix A.7. Since the above error bound is monotonically non-decreasing with respect to each , replacing with yields a computable upper bound:
We write the resulting upper bound in a clusterwise form and use each clusterwise term as its risk score .
Proof of core lemma
Proof. We define absolute mass correction of cluster :
Proof of inequality can be done using Jensen’s inequality with . This revels that approximation underestimate the mass of cluster.
We have:
If we define as the effect of approximating on cluster :
Naturally we have:
And:
As analysed before, we want to know how much output distortion originates from approximating a particular cluster:
We define mass correction factor as
The total mass correction factor can be defined as:
We have:
Proof of technical lemmas
Lemma A.2 (Cluster Mass Correction Bound). For any cluster , let the query-dependent logit deviation be defined as
Then, the local mass correction factor satisfies
Proof. Let . By definition of , the mean of vanishes:
Moreover, by definition of , we have for all . By the convexity of the exponential function , any can be upper-bounded via the secant line between the endpoints:
Averaging this inequality over all tokens in cluster , we obtain
which completes the proof.
Lemma A.3 (Softmax deviation from uniform). Let satisfy
and define
Then
Proof. Since , for any ,
Let
so that
Denote
Then
For any random variable with , the convexity of implies
Applying this to the empirical distribution over gives
For a fixed ratio , the right-hand side is maximized at
which yields
Since ,
Therefore,
Computable upper bound for C.
The quantity directly measures the worst-case logit deviation within cluster under the current query:
While provides a natural measure of local fidelity, computing it exactly requires accessing all keys in the cluster, which defeats the purpose of efficient selection. We therefore seek a query-dependent upper bound such that
Axis-aligned box bound.
Let and be the coordinate-wise minimum and maximum keys in cluster , and define
Since every , , lies inside the box , its query-key score is bounded by
Therefore,
This bound requires two -dimensional vectors per cluster and query-time computation. It can be loose because its coordinate-wise extrema may come from different keys.
Diagonal-Ellipsoid Bound
For a centered key , define the coordinate-wise radii
For clarity, we assume ; a zero-width coordinate has zero residual for every key and can be omitted without affecting the bound. We further define
The vector normalizes the scale of each coordinate, while measures the largest residual after this normalization. Equivalently, all centered keys lie inside the diagonal ellipsoid
The resulting query-dependent bound is
Indeed, for every , weighted Cauchy–Schwarz gives
Therefore,
Both and are query-independent and can be precomputed once per block. The bound stores one vector and one scalar per block and takes operations to evaluate for each query–block pair.
RefineKV Details
Q-anchor
Prompt-Query Anchors. During prefill, we use the query vectors from the last prompt positions as anchors and cache the clusters they select. These anchor-selected clusters remain expanded throughout decoding, in addition to those selected by the current query. We use no anchors in main text, but we provide result for Q-anchors on Appendix § 12.§ 3.1. The anchor mask is computed once during prefill and reused throughout decoding. Table 4 quantifies the resulting quality–latency trade-off.
| Metric | Ref. Full | Number of query anchors | 0 (default) | 16 | 32 | 64 |
| Acc.↑ | 73.37 | 70.19 | 72.49 | 72.99 | 72.91 | |
| Steady TPOT (ms)↓ | 24.43 | 15.68 | 16.65 | 17.14 | 17.84 | |
| Speedup↑ | 1.00× | 1.56× | 1.47× | 1.42× | 1.37× |
Table 4. Query-anchor ablation of Llama-3.1-8B-Instruct on RULER-128K (260 samples). All variants use the default configuration (, , box summary, GQA-any) and differ only in the number of query anchors ; (no query anchors) is our default and is shown in bold. Latency is steady-state TPOT with CUDA Graph (130,944 input / 128 output tokens).
Ablation for Q-anchor. We additionally perform ablation on the number of query anchors. The results are shown in Table 4.
Kernel Implementation
We implement REFINEKV using custom Triton kernels. After prefill, the prompt K/V cache is partitioned into blocks of 32 tokens. For each block, we compute and cache its key and value representatives, diagonal-ellipsoid bound statistics, maximum value norm, and valid-token count. Prompt-anchor queries are captured during prefill, and their selected blocks are computed once and stored as a compact per-KV-head mask. These summaries and masks are reused throughout generation.
At each decoding step, the block-selection kernel jointly processes the query heads associated with each KV head. It computes the representative attention score and deviation bound for every block, applies the expansion criterion of REFINEKV, and combines the resulting decisions with the cached prompt-anchor mask. The output is a compact selection mask that remains on the GPU. The sparse-attention kernel then reads token-level K/V directly from the original cache only for selected blocks; unselected blocks contribute through their cached representatives, while generated suffix tokens are always processed exactly. The three types of contributions are merged using online softmax, with BF16 Tensor-Core operations for matrix products and FP32 accumulation for numerical stability. We use a preallocated static KV cache and reuse all intermediate workspaces across tokens. For fixed-length latency evaluation, the complete decoding step is captured in a CUDA Graph, reducing Python and kernel-launch overhead to one graph replay per token. For fair comparison, full Attention, and baselines are timed under the same CUDA Graph protocol. We provide additional eager results on Appendix C.6.
Correlation Analysis
Definition of the target. For a cluster and query , let
where is the Full Attention softmax normalizer. is ’s contribution to the Full Attention output, and is its contribution to the output in which every cluster is replaced by its representative. Hence is exactly the error of that approximation, and is ’s share of it.
Correlation analysis. We use Llama-3.1-8B on RULER-128K (26 prompts) in the main setting (, box, ). We take every layer and head at decode steps 0, 31 and 126. For each (step, layer, head), we compute the Spearman correlation between a score and the target across clusters, and we report the median. alone reaches .975, so the target is dominated by attention mass. We therefore also report the partial Spearman correlation given .
Within each instance, we rank-transform the score , the target and across clusters. We then regress the ranks of and of on the rank of by least squares, and take the Pearson correlation of the two residuals. Equivalently,
where each is a Spearman correlation. This measures how much a score explains about the error beyond attention mass. On this target, carries clear information beyond mass (partial ), more than a Quest-style bound (.32). The mass-weighted value norm carries almost none (.06). With the exact deviation in place of the box summary, the partial correlation rises to .81. The deviation term is therefore what separates from an importance score, and a tighter deviation summary would sharpen it further.
| Score | Raw | Partial |
| .975 | ||
| .975 | .06 | |
| Quest-style bound | .864 | .32 |
| (box ) | .975 | .49 |
| (exact , oracle) | .990 | .81 |
Table 5. Spearman correlation between each score and (Llama-3.1-8B, RULER-128K, , box, ). Values are medians over (step, layer, head). “Partial” is the correlation given .
Experiment Details
Critical KV Analysis
Top- KV analysis. For the top- analysis, we evaluate all 32 layers of Llama-3.1-8B on 20 non-overlapping 1,024-token segments from the WikiText-2 test split. For each query head, we select the smallest KV subset that accumulates attention mass . Because the model uses GQA, the four query heads sharing a KV head access the union of their selected subsets. We report the average per-query KV percentage, the union across all queries, and the union across distant queries satisfying . Output error is measured after renormalizing attention over the selected KVs as .
Perplexity evaluation. For the perplexity experiment, we use 20 non-overlapping 2,048-token WikiText-2 segments, totaling 40,940 next-token predictions. We compare our query-adaptive method against oracle top- and the query-independent H2O, RoCo, and TOVA eviction methods. The horizontal axis reports the measured fraction of KV entries accessed relative to full causal attention, rather than the nominal cache budget. All results are averaged across samples, and error bars show 95% confidence intervals.
Main Experiment Setup
Models
We evaluate Llama-3.1-8B-Instruct (Grattafiori et al. [7]) and Qwen2.5-7B-Instruct (Qwen et al. [22]) without additional training or fine-tuning. Llama-3.1-8B contains 32 transformer layers with 32 query heads and 8 KV heads, corresponding to four query heads per KV head. It uses the rotary position encoding (Su et al. [24]) with a native context length of 128K.
Qwen2.5-7B contains 28 layers with 28 query heads and 4 KV heads, resulting in a larger GQA group of seven query heads per KV head. Qwen2.5 natively supports a 32K context window with its default RoPE configuration. For the 64K and 128K evaluations, we follow the officially recommended long-context setting by enabling static YaRN (Peng et al. [21]) with a scaling factor of four and an original context length of 32K. This positional-encoding extension is applied identically to all methods. Both models have a head dimension of 128 and are evaluated in BF16 with batch size one and greedy decoding.
Benchmarks
For LongBench (Bai et al. [2]) , we use the 16-task English/code subset consisting of 14 English tasks, 1cc, and repobench-p, with 3,750 test examples per configuration. Quality is evaluated on LongBench using the official prompts, generation limits, and task-specific metrics, while latency is measured separately using standardized 128K prompts.
For RULER (Hsieh et al. [11]) , we evaluate all 13 official tasks at context length of 128K, using the same 20 source examples per task and length, for a total of 260 examples per configuration. RULER data are generated separately for each model and tokenizer.
For HELMET [32], we include all tasks with objective automatic evaluation and exclude only subjective tasks that require an LLM-as-a-judge. We follow the official task-specific formatting, generation limits, stopping rules, and evaluation metrics. For all benchmarks, we compute each task score independently and report the unweighted macro-average across tasks.
Baselines
Full Attention. Full Attention retains the complete visible KV cache and serves as the reference for both quality and latency. We use the model’s native GQA layout and optimized scaled dot-product attention without replicating KV heads. The latency implementation uses a preallocated static KV cache and captures each decoding step in a CUDA Graph, under the same BF16 and batch-size-one protocol as RefineKV and the eviction baselines.
SnapKV. We use the KVPress [5] implementation of SnapKV with an observation window of 64 tokens and a pooling kernel size of 5. We evaluate target KV-retention ratios of 10%, 25%, and 50%, where the percentage denotes the fraction of prompt KV states retained after prefill compression. Decode attention operates directly on the compressed cache, while newly generated tokens are retained.
StreamLLM. We use the KVPress [5] implementation of StreamLLM with four attention-sink tokens. After preserving these sink tokens, the remaining budget is assigned to the most recent prompt tokens. We evaluate prompt-KV retention ratios of 10%, 25%, and 50%. The prompt cache is compressed after prefill, and all newly generated tokens are retained during decoding.
PyramidKV. We configure PyramidKV with an observation window of 64 tokens, a pooling kernel size of 5, and . We evaluate mean retention targets of 10%, 25%, and 50%; because PyramidKV distributes its budget non-uniformly across layers, these percentages denote the configured average retention rather than an identical per-layer budget. The selected prompt KVs are stored in a visible-prefix static cache and processed with native-GQA attention; the decoding step is captured in a CUDA Graph.
Quest. We use a page size of 16 tokens and evaluate absolute token budgets of 512, 1,024, 2,048, and 4,096 tokens. Following the official setting, the first two transformer layers use Full Attention, while the remaining layers apply query-dependent page selection. The mandatory tail page is included in the reported token budget. We use paged CUDA decoding for Llama and a native-head parallel page-scoring implementation for Qwen, without physically replicating GQA KV heads.
Double-P. We use clusters of 32 prompt tokens, four iterations of per-KV-head -means, four exact sink tokens, and a 64-token exact local window. We evaluate the threshold pairs when complete measurements are available. Clusters outside the probability prefix are pruned, clusters between the and prefixes are represented by their centroids, and clusters inside the prefix are expanded to exact tokens. Prompt clustering is performed once after prefill, and generated tokens remain exact. Since the authors’ production kernels are not publicly available, we use our optimized Triton reimplementation and do not describe it as the official Double-P implementation.
Metrics.
We focus on steady-state decoding because REFINEKV primarily targets the repeated KV-cache access during autoregressive generation. Prefill processes all prompt tokens in parallel through regular, highly optimized matrix–matrix multiplications, whereas batch-one decoding executes sequentially for each generated token and is often dominated by memory-intensive KV-cache access. Prefill is therefore a one-time, highly parallelized cost, while decode latency accumulates with the output length. As shown in Table 6, our auxiliary experiment on Llama-3.1-8B shows that decoding accounts for 82.2% with 32K prefill/512 decode setting, and 90.3% with 32K/1024 setting. We thus evaluate serving efficiency using decode TPOT and treat prefill latency and time to first token as separate costs. Unless noted otherwise, all methods and Full Attention are timed with CUDA Graph; eager-mode results are in Appendix § 12.§ 6.
| Sequence length | Latency (s) | Fraction (%) | |||
| Prefill | Decode | Prefill | Decode | Prefill | Decode |
| 16K | 512 | 1.01 | 9.20 | 9.9 | 90.1 |
| 32K | 512 | 2.42 | 11.15 | 17.8 | 82.2 |
| 32K | 1024 | 2.41 | 22.37 | 9.7 | 90.3 |
Table 6. Latency breakdown of prefill and decoding on Llama-3.1-8B in BF16. Each result is averaged over three runs.
For every method, we disable early stopping and generate exactly 128 output tokens. We exclude the output token produced during prefill, as it does not require an autoregressive decoding step, and discard the first post-prefill iteration to remove one-time initialization overhead. Let denote the elapsed time of the remaining 126 decoding iterations. We compute
The timed region includes all method-specific operations, including token selection or routing, attention computation, Transformer execution, KV-cache updates, and generation-loop overhead, while excluding model loading, compilation, warm-up, and prefill.
Choice of generation length. We report latency using 128 generated tokens. As shown in Table 7, increasing the generation length to 256 or 512 tokens changes steady-state TPOT by at most 1.43% on average across all three benchmarks; the largest per-prompt change is 1.69%, within our predefined 3% practical threshold. Thus, 128 tokens are sufficient to obtain a stable estimate of steady-state decoding efficiency, while longer generations substantially increase evaluation cost without materially changing the conclusion. We therefore use 128 tokens in the main experiments.
| Benchmark | 128 tokens | 256 tokens | 512 tokens |
| LongBench | 14.76 | 14.61 (−1.03%) | 14.55 (−1.43%) |
| RULER | 16.35 | 16.20 (−0.92%) | 16.14 (−1.27%) |
| HELMET | 17.20 | 17.06 (−0.80%) | 17.01 (−1.07%) |
Table 7. Sensitivity of steady-state TPOT to the generation length. Values in parentheses denote the relative change from 128 tokens. All lengths use identical prompts, cache capacities, and method configurations.
Hardware Settings.
All experiments are conducted on NVIDIA RTX PRO 6000 Blackwell Server Edition GPUs. Each latency measurement uses a single exclusive GPU. Unless noted otherwise, all methods use bfloat16 and batch size one.
Extra Experiment Results
main table tasks
For compact presentation, we aggregate semantically related tasks into task groups; no tasks are cherry-picked or omitted, and every task is included exactly once. For LongBench, Doc QA combines single-document and multi-document question answering, Summ. denotes long-document summarization, Few-shot denotes few-shot learning, Synth. covers synthetic counting and retrieval, and Code evaluates long-context code understanding and completion. For RULER, NIAH combines single-key, multi-key, multi-value, and multi-query needle-in-a-haystack retrieval, A&T denotes aggregation and tracking, and QA denotes question answering. For HELMET, RAG denotes retrieval-augmented generation, LC-QA denotes long-context question answering, ICL denotes in-context learning, and Rec./Rank. combines recall and reranking tasks. We put the detail for subtask result in: Table 8, Table 9 and Table 10.
Table 8: LongBench per-task quality–latency comparison. Each cell reports Accuracy/Acceleration, where Accuracy is the task-macro benchmark score and Acceleration is latency acceleration relative to Full, higher is better for both. Shaded cells are Pareto-optimal. Underlined cells have an absolute Accuracy drop versus Full of less than 0.5 point. Baselines use SnapKV/StreamLLM/PyramidKV.
| Method | NarrativeQA | Qasper | MultiFieldQA | HotpotQA | 2WikiMQA | MuSiQue | GovReport | QMSum | MultiNews | TREC | TriviaQA | SAMSum | Count | Retrieval | LCC | RepoBench-P |
| Full | 29.8/1.0 | 45.5/1.0 | 54.7/1.0 | 55.2/1.0 | 45.0/1.0 | 31.2/1.0 | 35.0/1.0 | 25.3/1.0 | 27.2/1.0 | 72.5/1.0 | 91.7/1.0 | 43.4/1.0 | 6.5/1.0 | 99.5/1.0 | 63.1/1.0 | 56.1/1.0 |
| Snap 10% | 30.3/1.7 | 36.5/1.7 | 52.4/1.7 | 54.9/1.7 | 42.7/1.7 | 30.8/1.7 | 27.0/1.7 | 23.4/1.7 | 19.8/1.7 | 63.0/1.7 | 91.9/1.7 | 42.8/1.7 | 7.2/1.7 | 99.5/1.7 | 60.8/1.7 | 56.3/1.7 |
| Snap 25% | 30.0/1.5 | 42.2/1.5 | 54.2/1.5 | 55.1/1.5 | 44.4/1.5 | 31.1/1.5 | 30.4/1.5 | 25.0/1.5 | 23.4/1.5 | 68.5/1.5 | 91.6/1.5 | 42.4/1.5 | 6.9/1.5 | 99.5/1.5 | 62.8/1.5 | 56.8/1.5 |
| Str. 10% | 26.3/1.7 | 26.2/1.7 | 33.7/1.7 | 47.6/1.7 | 37.0/1.7 | 25.2/1.7 | 25.4/1.7 | 21.4/1.7 | 19.7/1.7 | 58.5/1.7 | 88.8/1.7 | 42.5/1.7 | 6.4/1.7 | 88.5/1.7 | 59.4/1.7 | 52.9/1.7 |
| Str. 25% | 28.1/1.5 | 31.3/1.5 | 35.6/1.5 | 50.4/1.5 | 40.9/1.5 | 25.3/1.5 | 29.1/1.5 | 22.0/1.5 | 23.0/1.5 | 66.0/1.5 | 90.0/1.5 | 42.4/1.5 | 7.9/1.5 | 84.5/1.5 | 60.9/1.5 | 55.3/1.5 |
| Pyr. 10% | 30.3/1.7 | 36.0/1.7 | 52.3/1.7 | 54.8/1.7 | 42.7/1.7 | 31.6/1.7 | 26.7/1.7 | 24.2/1.7 | 19.9/1.7 | 63.0/1.7 | 91.9/1.7 | 43.0/1.7 | 7.2/1.7 | 99.5/1.7 | 60.6/1.7 | 56.1/1.7 |
| Pyr. 25% | 30.5/1.5 | 42.5/1.5 | 53.8/1.5 | 55.4/1.5 | 44.4/1.5 | 31.6/1.5 | 30.1/1.5 | 24.9/1.5 | 23.6/1.5 | 67.5/1.5 | 91.5/1.5 | 43.6/1.5 | 6.4/1.5 | 99.5/1.5 | 62.8/1.5 | 56.9/1.5 |
| Quest | 30.5/1.1 | 45.1/1.1 | 55.5/1.1 | 55.3/1.1 | 45.9/1.1 | 32.8/1.1 | 35.8/1.1 | 25.8/1.1 | 27.2/1.1 | 72.0/1.1 | 91.5/1.1 | 43.1/1.1 | 6.9/1.1 | 99.5/1.1 | 62.9/1.1 | 56.4/1.1 |
| Double | 30.6/1.4 | 43.8/1.4 | 55.9/1.4 | 54.7/1.4 | 43.6/1.4 | 31.4/1.4 | 34.6/1.4 | 24.5/1.4 | 26.7/1.4 | 71.5/1.4 | 91.6/1.4 | 42.9/1.4 | 7.0/1.4 | 99.0/1.4 | 63.5/1.4 | 55.6/1.4 |
| Our .01 | 29.2/1.6 | 45.4/1.6 | 54.2/1.6 | 55.2/1.6 | 45.0/1.6 | 30.9/1.6 | 35.4/1.6 | 25.4/1.5 | 27.2/1.5 | 72.5/1.5 | 91.6/1.5 | 44.0/1.5 | 7.0/1.6 | 99.5/1.6 | 63.0/1.6 | 56.3/1.6 |
| Our .1 | 30.1/1.7 | 44.3/1.7 | 56.3/1.7 | 55.3/1.7 | 45.3/1.7 | 31.7/1.6 | 34.3/1.7 | 25.1/1.7 | 27.2/1.7 | 71.5/1.7 | 91.7/1.7 | 44.6/1.7 | 6.4/1.7 | 100.0/1.7 | 62.5/1.7 | 57.0/1.7 |
| Our .1 Q32 | 29.7/1.6 | 45.3/1.6 | 55.7/1.6 | 55.1/1.6 | 44.9/1.6 | 31.2/1.6 | 34.6/1.6 | 25.8/1.6 | 27.4/1.6 | 72.5/1.6 | 91.3/1.6 | 43.7/1.6 | 7.6/1.6 | 100.0/1.6 | 62.8/1.6 | 56.5/1.6 |
| Full | 28.6/1.0 | 44.6/1.0 | 51.4/1.0 | 58.3/1.0 | 46.5/1.0 | 29.6/1.0 | 33.3/1.0 | 24.3/1.0 | 25.8/1.0 | 73.5/1.0 | 89.4/1.0 | 46.9/1.0 | 9.0/1.0 | 100.0/1.0 | 61.2/1.0 | 66.9/1.0 |
| Snap 10% | 29.2/1.3 | 36.1/1.3 | 48.8/1.3 | 57.4/1.3 | 46.4/1.3 | 29.8/1.3 | 28.4/1.3 | 22.7/1.3 | 20.6/1.3 | 54.5/1.3 | 88.4/1.3 | 43.9/1.3 | 9.0/1.3 | 100.0/1.3 | 57.2/1.3 | 66.7/1.3 |
| Snap 25% | 29.9/1.3 | 41.1/1.3 | 50.7/1.3 | 58.3/1.3 | 46.1/1.3 | 30.6/1.3 | 28.4/1.3 | 23.3/1.3 | 20.1/1.3 | 66.0/1.3 | 88.8/1.3 | 44.9/1.3 | 9.0/1.3 | 100.0/1.3 | 57.7/1.3 | 66.7/1.3 |
| Str. 10% | 24.1/1.3 | 27.1/1.3 | 28.2/1.3 | 43.9/1.3 | 38.0/1.3 | 27.1/1.3 | 23.8/1.3 | 19.3/1.3 | 16.0/1.3 | 58.5/1.3 | 86.6/1.3 | 43.3/1.3 | 9.0/1.3 | 37.0/1.3 | 49.9/1.3 | 57.7/1.3 |
| Str. 25% | 25.9/1.3 | 29.9/1.3 | 31.3/1.3 | 47.5/1.3 | 40.7/1.3 | 22.8/1.3 | 27.7/1.3 | 20.1/1.3 | 19.5/1.3 | 64.5/1.3 | 89.1/1.3 | 44.0/1.3 | 9.0/1.3 | 57.2/1.3 | 53.4/1.3 | 62.3/1.3 |
| Pyr. 10% | 29.0/1.3 | 37.7/1.3 | 48.6/1.3 | 55.5/1.3 | 44.7/1.3 | 27.4/1.3 | 25.7/1.3 | 22.8/1.3 | 18.0/1.3 | 55.0/1.3 | 85.4/1.3 | 45.2/1.3 | 9.0/1.3 | 100.0/1.3 | 56.5/1.3 | 63.5/1.3 |
| Pyr. 25% | 29.9/1.3 | 41.5/1.3 | 49.3/1.3 | 56.9/1.3 | 45.6/1.3 | 29.5/1.3 | 28.1/1.3 | 23.2/1.3 | 21.5/1.3 | 67.0/1.3 | 87.0/1.3 | 46.6/1.3 | 9.0/1.3 | 100.0/1.3 | 60.3/1.3 | 63.9/1.3 |
| Quest | 29.0/0.9 | 43.7/0.9 | 52.3/0.9 | 57.4/0.9 | 46.3/0.9 | 28.9/0.9 | 33.1/0.9 | 23.4/0.9 | 23.4/0.9 | 72.0/0.9 | 89.6/0.9 | 45.9/0.9 | 7.5/0.9 | 99.5/0.9 | 59.5/0.9 | 65.0/0.9 |
| Double | 28.5/1.1 | 43.8/1.1 | 50.7/1.1 | 58.3/1.1 | 44.7/1.1 | 28.2/1.1 | 33.1/1.1 | 23.3/1.1 | 25.5/1.1 | 73.5/1.1 | 88.8/1.1 | 46.8/1.1 | 9.0/1.1 | 98.0/1.1 | 60.6/1.1 | 64.2/1.1 |
| Our .01 | 28.6/1.2 | 44.8/1.2 | 51.1/1.2 | 58.3/1.2 | 45.6/1.2 | 29.5/1.2 | 33.4/1.2 | 24.1/1.2 | 24.2/1.2 | 73.5/1.2 | 88.9/1.2 | 47.0/1.2 | 9.0/1.2 | 100.0/1.2 | 61.3/1.2 | 66.7/1.2 |
| Our .1 | 29.1/1.3 | 45.0/1.3 | 50.8/1.3 | 57.7/1.3 | 45.6/1.3 | 29.7/1.3 | 33.8/1.3 | 24.4/1.3 | 25.6/1.3 | 73.0/1.3 | 89.0/1.3 | 47.1/1.3 | 9.0/1.3 | 99.5/1.3 | 61.0/1.3 | 66.1/1.3 |
| Our .1 Q32 | 28.7/1.2 | 45.0/1.2 | 51.1/1.2 | 58.4/1.2 | 46.1/1.2 | 29.7/1.2 | 33.8/1.2 | 24.5/1.2 | 25.5/1.2 | 73.5/1.2 | 88.9/1.2 | 46.9/1.2 | 9.0/1.2 | 100.0/1.2 | 61.5/1.2 | 66.7/1.2 |
Table 8.
| Method | NIAH-S1 | NIAH-S2 | NIAH-S3 | NIAH-MK1 | NIAH-MK2 | NIAH-MK3 | NIAH-MV | NIAH-MQ | CWE | FWE | QA-1 | QA-2 | |
| Llama Full | 100.0/1.0 | 100.0/1.0 | 100.0/1.0 | 90.0/1.0 | 70.0/1.0 | 55.0/1.0 | 93.8/1.0 | 100.0/1.0 | 0.0/1.0 | 70.0/1.0 | 65.0/1.0 | 65.0/1.0 | 45.0/1.0 |
| Snap 10% | 100.0/1.7 | 100.0/1.7 | 70.0/1.7 | 90.0/1.7 | 60.0/1.7 | 30.0/1.7 | 88.8/1.7 | 97.5/1.7 | 0.5/1.7 | 61.7/1.7 | 60.0/1.7 | 65.0/1.7 | 45.0/1.7 |
| Snap 25% | 100.0/1.5 | 100.0/1.5 | 85.0/1.5 | 90.0/1.5 | 65.0/1.5 | 40.0/1.5 | 93.8/1.5 | 100.0/1.5 | 0.0/1.5 | 65.0/1.5 | 59.0/1.5 | 65.0/1.5 | 45.0/1.5 |
| Str. 10% | 5.0/1.7 | 20.0/1.7 | 5.0/1.7 | 10.0/1.7 | 10.0/1.7 | 20.0/1.7 | 10.0/1.7 | 10.0/1.7 | 0.5/1.7 | 80.0/1.7 | 9.0/1.7 | 50.0/1.7 | 25.0/1.7 |
| Str. 25% | 35.0/1.5 | 45.0/1.5 | 20.0/1.5 | 40.0/1.5 | 30.0/1.5 | 25.0/1.5 | 25.0/1.5 | 25.0/1.5 | 1.0/1.5 | 76.7/1.5 | 25.0/1.5 | 65.0/1.5 | 35.0/1.5 |
| Pyr. 10% | 100.0/1.7 | 100.0/1.7 | 70.0/1.7 | 90.0/1.7 | 60.0/1.7 | 35.0/1.7 | 83.8/1.7 | 98.8/1.7 | 0.5/1.7 | 55.0/1.7 | 62.0/1.7 | 65.0/1.7 | 45.0/1.7 |
| Pyr. 25% | 100.0/1.5 | 100.0/1.5 | 85.0/1.5 | 90.0/1.5 | 60.0/1.5 | 50.0/1.5 | 93.8/1.5 | 100.0/1.5 | 0.0/1.5 | 63.3/1.5 | 62.0/1.5 | 65.0/1.5 | 45.0/1.5 |
| Quest | 100.0/1.1 | 100.0/1.1 | 75.0/1.1 | 90.0/1.1 | 45.0/1.1 | 0.0/1.1 | 77.5/1.1 | 87.5/1.1 | 0.0/1.1 | 66.7/1.1 | 64.0/1.1 | 65.0/1.1 | 40.0/1.1 |
| Double | 95.0/1.4 | 80.0/1.4 | 95.0/1.4 | 85.0/1.4 | 20.0/1.4 | 5.0/1.4 | 42.5/1.4 | 53.8/1.4 | 0.5/1.4 | 68.3/1.4 | 34.0/1.4 | 65.0/1.4 | 45.0/1.4 |
| Our .01 | 100.0/1.6 | 100.0/1.5 | 100.0/1.5 | 95.0/1.6 | 55.0/1.5 | 25.0/1.6 | 90.0/1.5 | 97.5/1.5 | 0.0/1.6 | 70.0/1.6 | 70.0/1.6 | 65.0/1.5 | 45.0/1.5 |
| Our .1 | 100.0/1.7 | 95.0/1.7 | 100.0/1.7 | 90.0/1.7 | 30.0/1.7 | 5.0/1.7 | 71.2/1.7 | 86.2/1.7 | 0.0/1.7 | 60.0/1.7 | 61.0/1.7 | 70.0/1.7 | 45.0/1.7 |
| Our .1 Q32 | 100.0/1.7 | 100.0/1.6 | 100.0/1.6 | 90.0/1.7 | 60.0/1.7 | 20.0/1.7 | 83.8/1.6 | 93.8/1.6 | 0.0/1.7 | 63.3/1.7 | 65.0/1.7 | 65.0/1.6 | 45.0/1.6 |
| Qwen Full | 100.0/1.0 | 100.0/1.0 | 90.0/1.0 | 95.0/1.0 | 45.0/1.0 | 10.0/1.0 | 73.8/1.0 | 85.0/1.0 | 38.0/1.0 | 51.7/1.0 | 83.0/1.0 | 60.0/1.0 | 25.0/1.0 |
| Snap 10% | 100.0/1.3 | 95.0/1.3 | 0.0/1.3 | 75.0/1.3 | 0.0/1.3 | 0.0/1.3 | 20.0/1.3 | 72.5/1.3 | 35.5/1.3 | 43.3/1.3 | 82.0/1.3 | 55.0/1.3 | 20.0/1.3 |
| Snap 25% | 100.0/1.3 | 100.0/1.3 | 5.0/1.3 | 70.0/1.3 | 5.0/1.3 | 0.0/1.3 | 43.8/1.3 | 86.2/1.3 | 44.0/1.3 | 46.7/1.3 | 83.0/1.3 | 55.0/1.3 | 25.0/1.3 |
| Str. 10% | 5.0/1.3 | 20.0/1.3 | 5.0/1.3 | 5.0/1.3 | 0.0/1.3 | 0.0/1.3 | 10.0/1.3 | 10.0/1.3 | 18.0/1.3 | 48.3/1.3 | 15.0/1.3 | 25.0/1.3 | 20.0/1.3 |
| Str. 25% | 35.0/1.3 | 50.0/1.3 | 15.0/1.3 | 15.0/1.3 | 10.0/1.3 | 10.0/1.3 | 17.5/1.3 | 23.8/1.3 | 18.5/1.3 | 43.3/1.3 | 29.0/1.3 | 65.0/1.3 | 15.0/1.3 |
| Pyr. 10% | 95.0/1.3 | 80.0/1.3 | 0.0/1.3 | 50.0/1.3 | 5.0/1.3 | 0.0/1.3 | 18.8/1.3 | 56.2/1.3 | 21.0/1.3 | 45.0/1.3 | 90.0/1.3 | 45.0/1.3 | 25.0/1.3 |
| Pyr. 25% | 100.0/1.3 | 100.0/1.3 | 0.0/1.3 | 65.0/1.3 | 5.0/1.3 | 0.0/1.3 | 36.2/1.3 |
Table 9. RULER per-task quality–latency comparison.
| Method | KVL-1H-WP | KVL-1H-2Q | KVL-POP-QA | KVL-TF-WP | InB. Choice | InB. QA | LC-BANK-7 | LC-CLINC | LC-MULTI | LC-TREC | LC-TREC-F | SQuAD-NV | NIAH-MK2 | NIAH-MK3 | NIAH-MK1 | MS MARCO |
| Llama Full | 60.0/1.0 | 47.5/1.0 | 54.2/1.0 | 80.0/1.0 | 50.0/1.0 | 47.1/1.0 | 90.0/1.0 | 95.0/1.0 | 85.0/1.0 | 80.0/1.0 | 35.0/1.0 | 90.0/1.0 | 90.0/1.0 | 90.0/1.0 | 96.2/1.0 | 15.5/1.0 |
| Llama Snap 10% | 61.7/1.7 | 44.2/1.7 | 55.0/1.7 | 83.3/1.7 | 50.0/1.6 | 46.8/1.6 | 90.0/1.6 | 95.0/1.6 | 85.0/1.6 | 80.0/1.6 | 35.0/1.6 | 75.0/1.5 | 95.0/1.5 | 35.0/1.5 | 95.0/1.6 | 33.3/1.0 |
| Llama Snap 25% | 61.7/1.5 | 45.0/1.5 | 55.0/1.5 | 80.8/1.5 | 50.0/1.5 | 48.9/1.5 | 90.0/1.5 | 95.0/1.5 | 85.0/1.5 | 80.0/1.5 | 40.0/1.4 | 90.0/1.4 | 95.0/1.4 | 70.0/1.4 | 98.8/1.5 | 5.0/1.4 |
| Llama Str. 10% | 67.1/1.5 | 35.8/1.7 | 53.3/1.7 | 78.3/1.7 | 50.0/1.6 | 34.8/1.6 | 90.0/1.6 | 90.0/1.6 | 85.0/1.6 | 80.0/1.6 | 20.0/1.6 | 10.0/1.5 | 50.0/1.5 | 50.0/1.5 | 10.0/1.6 | 28.8/1.5 |
| Llama Str. 25% | 55.0/1.5 | 37.5/1.5 | 58.3/1.5 | 80.8/1.5 | 50.0/1.5 | 33.0/1.5 | 90.0/1.5 | 95.0/1.5 | 85.0/1.5 | 75.0/1.5 | 20.0/1.4 | 10.0/1.4 | 40.0/1.4 | 20.0/1.4 | 15.0/1.5 | 1.4/1.4 |
| Llama Pyr. 10% | 60.0/1.5 | 45.8/1.5 | 55.0/1.5 | 83.3/1.5 | 50.0/1.6 | 48.1/1.6 | 90.0/1.6 | 95.0/1.6 | 85.0/1.6 | 80.0/1.6 | 25.0/1.6 | 80.0/1.5 | 95.0/1.5 | 45.0/1.5 | 95.7/1.6 | 21.1/1.5 |
| Llama Pyr. 25% | 60.0/1.5 | 44.2/1.5 | 54.2/1.5 | 83.3/1.5 | 50.0/1.5 | 48.9/1.5 | 90.0/1.5 | 95.0/1.5 | 85.0/1.5 | 80.0/1.5 | 30.0/1.4 | 95.0/1.4 | 90.0/1.4 | 80.0/1.4 | 98.8/1.5 | 8.5/1.4 |
| Llama Quest | 57.1/1.4 | 40.8/1.4 | 47.5/1.1 | 76.7/1.1 | 50.0/1.1 | 47.5/1.1 | 95.0/1.1 | 95.0/1.1 | 80.0/1.1 | 80.0/1.1 | 35.0/1.1 | 50.0/1.1 | 90.0/1.1 | 90.0/1.1 | 93.8/1.1 | 16.4/1.0 |
| Llama Double | 58.3/1.4 | 46.7/1.4 | 55.0/1.4 | 84.2/1.4 | 50.0/1.4 | 47.0/1.4 | 90.0/1.4 | 95.0/1.4 | 85.0/1.4 | 85.0/1.4 | 30.0/1.4 | 25.0/1.4 | 60.0/1.4 | 15.0/1.4 | 57.5/1.4 | 61.2/1.4 |
| Llama Our .01 | 60.0/1.5 | 47.5/1.5 | 55.8/1.4 | 83.3/1.5 | 50.0/1.4 | 47.8/1.4 | 95.0/1.4 | 95.0/1.4 | 85.0/1.4 | 80.0/1.4 | 25.0/1.4 | 90.0/1.4 | 95.0/1.4 | 40.0/1.4 | 96.2/1.4 | 14.2/1.3 |
| Llama Our .1 | 55.0/1.6 | 40.8/1.6 | 53.3/1.6 | 81.7/1.6 | 50.0/1.6 | 44.0/1.6 | 90.0/1.6 | 95.0/1.6 | 75.0/1.6 | 80.0/1.6 | 40.0/1.6 | 30.0/1.5 | 80.0/1.5 | 15.0/1.5 | 70.0/1.6 | 9.1/1.4 |
| Llama Our .1 Q32 | 58.3/1.6 | 45.0/1.6 | 55.0/1.6 | 83.3/1.6 | 50.0/1.6 | 48.0/1.6 | 90.0/1.6 | 95.0/1.6 | 85.0/1.6 | 75.0/1.6 | 30.0/1.5 | 90.0/1.5 | 95.0/1.5 | 60.0/1.5 | 87.5/1.6 | 15.3/1.4 |
Table 10. HELMET per-task quality–latency comparison.
Risk Score Analysis and Ablations
Our risk score is derived by regrouping the attention-output error into cluster-wise terms and bounding their magnitudes. The resulting score captures the joint effect of global importance, measured by , and local distortion, characterized by
Computing exactly requires accessing all keys within a cluster, so we replace it with an efficiently computable upper bound in practice. This raises three questions:
How does a large affect the risk score, and can the score be simplified?
How does using the exact, oracle affect selection quality?
How does our risk score compare with simpler selection rules?
We investigate these questions in the following subsections.
Score Simplification
Simplified score. When is large, and , so simplifies to
Setting. Llama-3.1-8B, RULER-128K, , GQA-any, block size 32. We record every layer and query head of 26 prompts (2 per task), at and . Same set is the fraction of KV heads for which selects exactly the same clusters as at the same . Cluster Jaccard is between the two selected cluster sets, averaged over KV heads. (4) > 2V_{\max} is the fraction of heads for which (4) exceeds the trivial bound .
Results. Table 11 shows that, with the oracle deviation, Eq. (4) is well below the trivial bound. In practice, with the box or ellipsoid bound, and select the same clusters on 96–98% of KV heads.
Simplified does not invalidate RefineKV. RefineKV uses only through the ranking it over clusters. The simplified form, keeps the intuition behind RefineKV: we want to jointly capture Importance and Distortion . Both signals enter jointly through , and a mass-weighted value term is added.
Table 11: Agreement between and the simplified score (Eq. (93)), and how often Eq. (4) exceeds the trivial bound . Llama-3.1-8B, RULER-128K, , GQA-any, block size 32, 26 prompts. is reported as mean std.
| Deviation | Same set (%) | Same set (%) | Cluster Jaccard | Cluster Jaccard | Eq. 4 (%) | Eq. 4 (%) | |
| Box | 96.4 | 97.7 | 0.9999 | 0.9991 | 99.5 | 99.7 | |
| Diag. ellipsoid | 96.4 | 97.7 | 0.9998 | 0.9982 | 99.7 | 99.8 | |
| Exact (oracle) | 2.2 | 38.4 | 0.918 | 0.945 | 1.7 | 5.0 |
Table 11.
Selection with Oracle and simplified risk score
To separate the deviation estimate from the form of the score, we fix the per-head token budget to that selected by with the box (Ours) and change only the cluster ranking (Table 12). A tighter deviation ranks clusters better: at the low budget (), the box summary improves on the ellipsoid by 5.3 points (Table 2), and the non-deployable oracle adds another 6.5; at the oracle comes within 1.4 points of Full Attention. In contrast, replacing by its large- simplification changes accuracy by at most 1.1 points, and no paired 95% CI excludes zero.
Table 12: Selection with oracle and simplified at a fixed per-head token budget (Llama-3.1-8B-Instruct, RULER-128K, ). Every row expands exactly as many tokens per KV head as with the box (Ours) selects at the same decoding state; only the cluster selection differs.
| original | box | 70.27 | 62.58 |
| simplified | box | 70.19 | 62.67 |
| original | oracle | 72.00 | 69.06 |
| simplified | oracle | 72.13 | 68.01 |
| Full Attention | 73.37 |
Table 12.
Results on Qwen2.5-14B-Instruct
To test whether RefineKV and its thresholds carry over to a larger model, we evaluate Qwen2.5-14B-Instruct (48 layers, 40 query / 8 KV heads) on RULER-128K (13 tasks 20 samples). We change nothing in the method: we use the same thresholds , , the box summary, GQA-any and , and apply no retuning. As for Qwen2.5-7B, the context is extended with static YaRN (factor 4, original length 32,768). Full Attention and both RefineKV settings are timed in the same batch. SnapKV-25% uses the same CUDA Graph static-cache port as in the main experiments, and its same-batch Full Attention control measures 40.99 ms (versus 40.98 ms). is paired against Full Attention on the same 260 samples, with task-stratified bootstrap 95% CIs.
Table 13: Qwen2.5-14B-Instruct on RULER-128K, with Qwen2.5-7B-Instruct for reference. RefineKV uses the same on both models. is relative to Full Attention, with 95% paired bootstrap CIs. Qwen2.5-7B numbers are those of the main results;
| Method | Qwen2.5-14B Acc. | Qwen2.5-14B [95% CI] | Qwen2.5-14B TPOT (ms) | Qwen2.5-14B Speedup | Qwen2.5-7B Acc. | Qwen2.5-7B | Qwen2.5-7B Speedup |
| Full Attention | 72.96 | — | 40.98 | 1.00 | 65.88 | — | 1.00 |
| RefineKV () | 71.97 | −0.99 [−2.88, +1.04] | 29.56 | 1.39 | 65.28 | −0.60 | 1.19 |
| RefineKV () | 69.19 | −3.78 [−6.72, −0.91] | 26.49 | 1.55 | 60.35 | −5.53 | 1.27 |
| SnapKV (25%) | 68.44 | −4.52 [−7.50, −1.64] | 28.33 | 1.45 | 51.05 | −14.83 | 1.27 |
Table 13.
Speedup without CUDA Graph
The main results time Full Attention, RefineKV and the eviction baselines with CUDA Graph. To show that the speedups do not depend on it, and to compare with methods whose custom kernels do not support CUDA Graph (Quest), we also time RefineKV and Full Attention in eager mode with the same static cache and protocol. RefineKV produces token-identical outputs in both modes, so quality is unchanged. The eager speedups are 3–6% lower than the CUDA Graph ones, because CUDA Graph removes more kernel-launch overhead from RefineKV (eager/Graph TPOT 1.10–1.12) than from Full Attention (1.06–1.07).
| Llama-3.1-8B | Qwen2.5-7B | ||||||
| RULER | HELMET | LongBench | RULER | HELMET | LongBench | ||
| Full Attention | Quality | 73.37 | 69.10 | 48.86 | 65.88 | 54.57 | 49.34 |
| RefineKV, | Quality | 70.19 | 68.43 | 48.87 | 65.28 | 54.48 | 49.23 |
| Speedup, CUDA | 1.56× | 1.43× | 1.55× | 1.19× | 1.13× | 1.18× | |
| Speedup, eager | 1.49× | 1.37× | 1.49× | 1.15× | 1.10× | 1.15× | |
| RefineKV, | Quality | 62.58 | 56.80 | 48.95 | 60.35 | 52.83 | 49.13 |
| Speedup, CUDA | 1.67× | 1.56× | 1.67× | 1.27× | 1.23× | 1.27× | |
| Speedup, eager | 1.59× | 1.47× | 1.59× | 1.23× | 1.18× | 1.22× |
Table 14. Quality and decode speedup of RefineKV over Full Attention, with both methods using CUDA Graph or both in eager mode.
Context Length Ablation
We hold the model (Llama-3.1-8B-Instruct), the task set (RULER, 13 tasks × 20 samples) and fixed, and vary the input length from 16K to 128K. Full Attention and RefineKV see identical prompts at each length. “Expanded” is the fraction of visible KV entries loaded exactly at each decode step.
| Length | Full Attention | RefineKV () | RefineKV () | |||||||
| Acc. | TPOT | Acc. | Exp. | Speedup | Acc. | Exp. | Speedup | |||
| 16K | 89.03 | 14.46 | 89.22 | +0.19 | 52.8% | 1.01× | 85.34 | −3.69 | 10.9% | 1.05× |
| 32K | 83.41 | 15.86 | 83.42 | +0.01 | 32.8% | 1.07× | 75.12 | −8.29 | 6.7% | 1.14× |
| 64K | 82.80 | 18.71 | 81.94 | −0.86 | 18.7% | 1.24× | 74.74 | −8.06 | 4.6% | 1.33× |
| 128K | 73.35 | 24.43 | 70.27 | −3.08 | 11.2% | 1.56× | 62.58 | −10.77 | 4.0% | 1.67× |
Table 15. RULER accuracy(Acc.), expanded fraction(Exp.) and decode speed versus input length (Llama-3.1-8B-Instruct, fixed ). is relative to Full Attention.
At fixed , the expanded fraction falls steadily with length. At fixed , the expanded fraction falls steadily with length, from 52.8% at 16K to 11.2% at 128K for , and from 10.9% to 4.0% for . This is because bounds the per-step output error rather than fixing a budget, and on RULER most of the added context is filler that the cluster summaries approximate well. As a result, RefineKV’s TPOT stays nearly flat (14.4–15.7 ms) while Full Attention’s grows with the cache, and the speedup rises from about 1.0× at 16K to 1.56× at 128K. The quality gap widens with length: at , RefineKV matches Full Attention up to 32K, is within noise at 64K, and loses 3.08 points at 128K.
Limited speedup at short lengths. The decode speedup is small at 16K–32K (1.01–1.07× at ) and becomes substantial only from 64K onward. RefineKV reduces only the attention term of a decode step, while the remaining kernels, mainly the weight GEMVs, cost about 12 ms per step regardless of context length (Figure 5). At 16K, attention therefore accounts for only about 2 ms of Full Attention’s 14.46 ms TPOT, which caps the end-to-end speedup of any attention-side method at roughly 1.2×; in addition, more than half of the KV cache is still expanded at this length. RefineKV targets long-context decoding, where attention dominates the cost. Current LLMs commonly support 128K to 1M-token contexts, which fall within the regime RefineKV targets.
Paired results with full attention
At , the CI of contains zero on four of six panels. The two exceptions are Qwen LongBench, whose CI barely excludes zero ( points), and Llama RULER (), whose loss is concentrated in two tasks.
| Model | Benchmark | Full | Acc. | [95% CI] | Acc. | [95% CI] | |
| Llama-3.1-8B | RULER | 73.37 | 70.19 | [, ] | 62.58 | [, ] | |
| Llama-3.1-8B | HELMET | 69.10 | 68.43 | [, ] | 56.80 | [, ] | |
| Llama-3.1-8B | LongBench | 48.86 | 48.87 | [, ] | 48.95 | [, ] | |
| Qwen2.5-7B | RULER | 65.88 | 65.28 | [, ] | 60.35 | [, ] | |
| Qwen2.5-7B | HELMET | 54.57 | 54.48 | [, ] | 52.83 | [, ] | |
| Qwen2.5-7B | LongBench | 49.34 | 49.23 | [, ] | 49.13 | [, ] |
Table 16. RefineKV versus Full Attention, paired on identical samples. is RefineKV minus Full Attention, with its 95% bootstrap CI.
References
- [1]Joshua Ainslie, James Lee-Thorp, Michiel de Jong, Yury Zemlyanskiy, Federico Lebrón, and Sumit Sanghai. Gqa: Training generalized multi-query transformer models from multi-head checkpoints, 2023. URL https://arxiv.org/abs/2305.13245.
- [2]Yushi Bai, Xin Lv, JiaJie Zhang, Hongchang Lyu, Jiankai Tang, Zhidian Huang, Zhengxiao Du, Xiao Liu, Aohan Zeng, Lei Hou, Yuxiao Dong, Jie Tang, and Juanzi Li. Longbench: A bilingual, multitask benchmark for long context understanding, 2024. URL https://arxiv.org/abs/2308.14508.
- [3]Zefan Cai, Yichi Zhang, Bofei Gao, Yuliang Liu, Yucheng Li, Tianyu Liu, Keming Lu, Wayne Xiong, Yue Dong, Junjie Hu, and Wen Xiao. Pyramidkv: Dynamic kv cache compression based on pyramidal information funneling, 2025. URL https://arxiv.org/abs/2406.02069.
- [4]Ashwin Gerard Colaco and Nada Lahjouji. What to keep, what to forget: A rate–distortion view of memory compaction in llms and agents, 2026. URL https://arxiv.org/abs/2607.08032.
- [5]Alessio Devoto, Maximilian Jeblick, and Simon Jégou. Expected attention: Kv cache compression by estimating attention from future queries distribution. arXiv preprint arXiv:2510.00636, 2025. URL https://arxiv.org/abs/2510.00636.
- [6]Yuan Feng, Junlin Lv, Yukun Cao, Xike Xie, and S. Kevin Zhou. Ada-kv: Optimizing kv cache eviction by adaptive budget allocation for efficient llm inference, 2025. URL https://arxiv.org/abs/2407.11550.
- [7]Aaron Grattafiori, Abhimanyu Dubey, and Abhinav Jauhri et al. The llama 3 herd of models, 2024. URL https://arxiv.org/abs/2407.21783.
- [8]Daya Guo, Dejian Yang, Haowei Zhang, and et al. Deepseek-rl incentivizes reasoning in llms through reinforcement learning. Nature, 645(8081):633–638, 2025. ISSN 1476-4687. doi: 10.1038/s41586-025-09422-z. URL http://dx.doi.org/10.1038/s41586-025-09422-z.
- [9]Zhiyu Guo, Hidetaka Kamigaito, and Taro Watanabe. Attention score is not all you need for token importance indicator in kv cache reduction: Value also matters, 2024. URL https://arxiv.org/abs/2406.12335.
- [10]Coleman Hooper, Sebastian Zhao, Luca Manolache, Sehoon Kim, Michael W. Mahoney, Yakun Sophia Shao, Kurt Keutzer, and Amir Gholami. Multipole attention for efficient long context reasoning, 2025. URL https://arxiv.org/abs/2506.13059.
- [11]Cheng-Ping Hsieh, Simeng Sun, Samuel Kriman, Shantanu Acharya, Dima Rekesh, Fei Jia, Yang Zhang, and Boris Ginsburg. Ruler: What’s the real context size of your long-context language models?, 2024. URL https://arxiv.org/abs/2404.06654.
- [12]Jie Hu, Shengnan Wang, Yutong He, Ping Gong, Jiawei Yi, Juncheng Zhang, Youhui Bai, Renhai Chen, Gong Zhang, Cheng Li, and Kun Yuan. Centroidkv: Efficient long-context llm inference via kv cache clustering, 2026. URL https://arxiv.org/abs/2506.11418.
- [13]Haoyang Li, Yiming Li, Anxin Tian, Tianhao Tang, Zhanchao Xu, Xuejia Chen, Nicole Hu, Wei Dong, Qing Li, and Lei Chen. A survey on large language model acceleration based on kv cache management, 2025. URL https://arxiv.org/abs/2412.19442.
- [14]Yu Li, Binxu Li, and Tian Lan. Momentmkv: Closing the directional gap in kv cache eviction for long-context inference, 2026. URL https://arxiv.org/abs/2606.01563.
- [15]Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh, Acyır Locatelli, Hanchen Ye, Tianle Cai, Patrick Lewis, and Deming Chen. Snapkv: Llm knows what you are looking for before generation, 2024. URL https://arxiv.org/abs/2404.14469.
- [16]Chaofan Lin, Jiaming Tang, Shuo Yang, Hanshuo Wang, Tian Tang, Boyu Tian, Ion Stoica, Song Han, and Mingyu Gao. Twilight: Adaptive attention sparsity with hierarchical top-p pruning, 2025. URL https://arxiv.org/abs/2502.02770.
- [17]Zirui Liu, Jiayi Yuan, Hongye Jin, Shaochen Zhong, Zhaozhuo Xu, Vladimir Braverman, Beidi Chen, and Xia Hu. KIVI: A tuning-free asymmetric 2bit quantization for KV cache. In Ruslan Salakhutdinov, Zico Kolter, Katherine Heller, Adrian Weller, Nuria Oliver, Jonathan Scarlett, and Felix Berkenkamp (eds.), Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 32332–32344. PMLR, 21–27 Jul 2024. URL https://proceedings.mlr.press/v235/liu24bz.html.DOI
- [18]Enzhe Lu, Zhejun Jiang, Jingyuan Liu, Yulun Du, Tao Jiang, Chao Hong, Shaowei Liu, Weiran He, Enming Yuan, Yuzhi Wang, Zhiqi Huang, Huan Yuan, Suting Xu, Xinran Xu, Guokun Lai, Yanru Chen, Huabin Zheng, Junjie Yan, Jianlin Su, Yuxin Wu, Neo Y. Zhang, Zhilin Yang, Xinyu Zhou, Mingxing Zhang, and Jiezhong Qiu. Moba: Mixture of block attention for long-context llms, 2025. URL https://arxiv.org/abs/2502.13189.
- [19]Wentao Ni, Kangqi Zhang, Zhongming Yu, Oren Nelson, Mingu Lee, Hong Cai, Fatih Porikli, Jongryool Kim, Zhijian Liu, and Jishen Zhao. Double-p: Hierarchical top-p sparse attention for long-context llms, 2026. URL https://arxiv.org/abs/2602.05191.
- [20]Matanel Oren, Michael Hassid, Nir Yarden, Yossi Adi, and Roy Schwartz. Transformers are multi-state rnns, 2024. URL https://arxiv.org/abs/2401.06104.
- [21]Bowen Peng, Jeffrey Quesnelle, Honglu Fan, and Enrico Shippole. Yarn: Efficient context window extension of large language models, 2026. URL https://arxiv.org/abs/2309.00071.
- [22]Qwen, ., An Yang, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, Haoran Wei, Huan Lin, Jian Yang, Jianhong Tu, Jianwei Zhang, Jianxin Yang, Jiaxi Yang, Jingren Zhou, Junyang Lin, Kai Dang, Keming Lu, Keqin Bao, Kexin Yang, Le Yu, Mei Li, Mingfeng Xue, Pei Zhang, Qin Zhu, Rui Men, Runji Lin, Tianhao Li, Tianyi Tang, Tingyu Xia, Xingzhang Ren, Xuancheng Ren, Yang Fan, Yang Su, Yichang Zhang, Yu Wan, Yuqiong Liu, Zeyu Cui, Zhenru Zhang, and Zihan Qiu. Qwen2.5 technical report, 2025. URL https://arxiv.org/abs/2412.15115.
- [23]Siyu Ren and Kenny Q. Zhu. On the efficacy of eviction policy for key-value constrained generative language model inference, 2024. URL https://arxiv.org/abs/2402.06262.
- [24]Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, and Yunfeng Liu. Roformer: Enhanced transformer with rotary position embedding, 2023. URL https://arxiv.org/abs/2104.09864.
- [25]Jiaming Tang, Yilong Zhao, Kan Zhu, Guangxuan Xiao, Baris Kasikci, and Song Han. Quest: Query-aware sparsity for efficient long-context llm inference, 2024. URL https://arxiv.org/abs/2406.10774.
- [26]Alexander Tian, Aditya Ghai, Sanjit Neelam, Zaal Vasania, and Akshay Mishra. Cobs: Cumulant order block sparse attention, 2026. URL https://arxiv.org/abs/2607.09052.
- [27]Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In I. Guyon, U. Von Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (eds.), Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017. URL https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd0503c1c4a845aa-Paper.pdf.
- [28]Zhongwei Wan, Xinjian Wu, Yu Zhang, Xi Xin, Chaofan Tao, Zhihong Zhu, Xin Wang, Siqi Luo, Jing Xiong, Longyue Wang, and Mi Zhang. D2O: Dynamic discriminative operations for efficient long-context inference of large language models, 2025. URL https://arxiv.org/abs/2406.13035.
- [29]Zheng Wang, Boxiao Jin, Zhongzhi Yu, and Minjia Zhang. Model tells you where to merge: Adaptive kv cache merging for llms on long-context tasks, 2024. URL https://arxiv.org/abs/2407.08454.
- [30]Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, and Mike Lewis. Efficient streaming language models with attention sinks, 2024. URL https://arxiv.org/abs/2309.17453.
- [31]Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. React: Synergizing reasoning and acting in language models, 2023. URL https://arxiv.org/abs/2210.03629.
- [32]Howard Yen, Tianyu Gao, Minmin Hou, Ke Ding, Daniel Fleischer, Peter Izsak, Moshe Wasserblat, and Danqi Chen. Helmet: How to evaluate long-context language models effectively and thoroughly, 2025. URL https://arxiv.org/abs/2410.02694.
- [33]Jian Yuan, Ziwei He, Haoli Bai, Jingwen Leng, and Bo Jiang. Weightedkv: Attention scores weighted key-value cache merging for large language models, 2025. URL https://arxiv.org/abs/2503.01330.



