betaFeedback

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 q∈Rdq \in\mathbb{R}^{d} representing the current decoding position interacts with the key vectors ki∈Rdk_i \in\mathbb{R}^{d} of the context tokens at position ii to determine how their value vectors vi∈Rdvv_i \in\mathbb{R}^{d_v} are aggregated. For a context of NN tokens and query qq, the full-attention output o∈Rdvo \in\mathbb{R}^{d_v}:

o=∑i=1Nαivi,αi=exp⁡(qTki/d)∑j=1Nexp⁡(qTkj/d)(1)o = \sum_{i=1}^{N} \alpha_i v_i,\qquad\alpha_i = \frac{\exp\left(q^{\mathsf{T}} k_i / \sqrt{d}\right)}{\sum_{j=1}^{N} \exp\left(q^{\mathsf{T}} k_j / \sqrt{d}\right)} \tag*{(1)}

During decoding, the keys and values of previous tokens are reused across generation steps. The Key-Value cache (KV cache) stores these representations as {(ki,vi)}i=1N\{(k_i, v_i)\}_{i=1}^{N}, avoiding repeated computation. However, the cache grows linearly with context length NN, 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 o^\hat{o} from full attention output oo 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 p%p\%. 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 p=90%p = 90\%, 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.

Comparison of query-adaptive and query-independent KV access methods

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 p%p\% 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-kk 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 p=90%p = 90\%, 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-kk 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 C={C1,…,Cm}\mathcal{C} = \{C_1, \ldots, C_m\} be a partition of the KV cache. For each cluster CC, we use its mean key and value (kˉC,vˉC)(\bar{k}_C, \bar{v}_C) as a shared representative for every KV entry in CC. For a query qq, under full attention, let pCp_C denote the total attention weight assigned to cluster CC, and let vCv_C denote the attention-weighted average of its token values. Under approximation, the cluster receives total attention weight p^C\hat{p}_C and contributes its mean value vˉC\bar{v}_C. Formally,

pC=∑i∈Ceq⊤ki/d∑j=1Neq⊤kj/d,vC=∑i∈Ceq⊤ki/dvi∑j∈Ceq⊤kj/d,p^C=∣C∣eq⊤kˉC/d∑C′∈C∣C′∣eq⊤kˉC′/d.(2)p_C = \frac{\sum_{i \in C} e^{q^\top k_i / \sqrt{d}}}{\sum_{j=1}^{N} e^{q^\top k_j / \sqrt{d}}}, \qquad v_C = \frac{\sum_{i \in C} e^{q^\top k_i / \sqrt{d}}v_i}{\sum_{j \in C} e^{q^\top k_j / \sqrt{d}}}, \qquad \hat{p}_C = \frac{|C|e^{q^\top\bar{k}_C / \sqrt{d}}}{\sum_{C' \in\mathcal{C}} |C'|e^{q^\top\bar{k}_{C'} / \sqrt{d}}}. \tag*{(2)}

The error between exact attention output o=∑C∈CpCvCo = \sum_{C \in\mathcal{C}} p_Cv_C and approximate attention output o^=∑C∈Cp^CvˉC\hat{o} = \sum_{C \in\mathcal{C}} \hat{p}_C\bar{v}_C can be decomposed as:

o−o^=∑C∈CpCvC−∑C∈Cp^CvˉC=∑C∈C(pC−p^C)vC⏟inter-cluster mass redistribution+∑C∈Cp^C(vC−vˉC)⏟intra-cluster value distortion.(3)o - \hat{o} = \sum_{C \in\mathcal{C}} p_Cv_C - \sum_{C \in\mathcal{C}} \hat{p}_C\bar{v}_C = \underbrace{\sum_{C \in\mathcal{C}} (p_C - \hat{p}_C)v_C}_{\text{inter-cluster mass redistribution}} + \underbrace{\sum_{C \in\mathcal{C}} \hat{p}_C(v_C - \bar{v}_C)}_{\text{intra-cluster value distortion}}. \tag*{(3)}

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 vCv_C with vˉC\bar{v}_C. After regrouping the first term (Lemma A.1), both terms are related to the dispersion the logits q⊤kiq^\top k_i within a cluster: when all q⊤kiq^\top k_i are close to q⊤kˉCq^\top\bar{k}_C, 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: δC=max⁡i∈C∣q⊤(ki−kˉC)/d∣\delta_C = \max_{i \in C} |q^\top(k_i - \bar{k}_C)/\sqrt{d}|. However, computing δC\delta_C exactly would require scanning all keys in the cluster. We therefore use an efficiently computable upper bound δCbound≥δC\delta_C^{\mathrm{bound}} \ge\delta_C, constructed from compact cluster summaries (Details in Appendix A.7). Letting VC=max⁡i∈C∥vi∥2V_C = \max_{i \in C} \|v_i\|_2 and Vmax⁡=max⁡C∈CVCV_{\max} = \max_{C \in\mathcal{C}} V_C, we have:

∥o−o^∥2≤2∑C∈Cp^C(Vmax⁡cosh⁡(δCbound)−1∑C′∈Cp^C′cosh⁡(δC′bound)+VCtanh⁡(δCbound2)).(4)\|o - \hat{o}\|_2 \le2 \sum_{C \in\mathcal{C}} \hat{p}_C \left( V_{\max} \frac{\cosh(\delta_C^{\mathrm{bound}}) - 1}{\sum_{C' \in\mathcal{C}} \hat{p}_{C'} \cosh(\delta_{C'}^{\mathrm{bound}})} + V_C \tanh\left(\frac{\delta_C^{\mathrm{bound}}}{2}\right) \right). \tag*{(4)}

In (4), we write the resulting upper bound in a clusterwise form and use each clusterwise term as its risk score RCR_C. 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 p^C\hat{p}_C, and local distortion, measured by δC\delta_C and upper-bounded by δCbound\delta_C^{\mathrm{bound}}.

Global Importance p^C\hat{p}_C. 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 δCbound\delta_C^{\mathrm{bound}}. For a given query, a cluster is easy to approximate when its tokens behave similarly under the query. In particular, if all q⊤kiq^\top k_i are close to q⊤kˉCq^\top\bar{k}_C, 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 δCbound\delta_C^{\mathrm{bound}} and Global Importance p^C\hat{p}_C. The background color indicates the Risk score, and the tilted decision boundary RC=τR_C = \tau adaptively balances p^C\hat{p}_C against δCbound\delta_C^{\mathrm{bound}}.

Figure 2. Left: Cluster selection is jointly determined by importance and distortion. Each point represents a cluster positioned by its global importance p^C\hat{p}_C and local distortion δCbound\delta_C^{\mathrm{bound}}. Background color encodes the risk score RCR_C, with the dashed line denoting the decision boundary at RC=τR_C = \tau. 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 RCR_C strongly correlated with approximation error. These figures illustrate the correlation between Risk Score and cluster approximation error ∥oC−o^C∥2\lVert o_C - \hat{o}_C \rVert_2, where oCo_C and o^C\hat{o}_C denote original output and approximate output for cluster CC.

Beyond this theoretical intuition, the next question is whether risk score RCR_C faithfully reflects the true output error caused by approximation. Figure 2 (Right) plots the risk score against the cluster approximation error ∥oC−o^C∥2\lVert o_C - \hat{o}_C \rVert_2, where oCo_C and o^C\hat{o}_C denote original output and approximate output for cluster CC. 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 p^C\hat{p}_C.

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 (kˉC,vˉC)(\bar{k}_C, \bar{v}_C) as well as auxiliary metadata. At each decoding step tt, the incoming query qtq_t interacts only with these cluster-level summaries to estimate the approximation risk score RCR_C. Clusters with risk above a predefined threshold τ\tau 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 qtq_t uses the cached summaries to calculate risk score RCR_C. Clusters with RC>τR_C > \tau are expanded, while clusters with RC≤τR_C \le\tau retain only their representatives. The resulting mixed KV sequence is used to compute the output oto_t. The color depth of each block indicates attention score.

Efficient Estimation of Risk Score. Evaluating the risk score RCR_C in Eq. (4) requires four quantities: p^C\hat{p}_C, Vmax⁡V_{\max}, VCV_C, and δCbound\delta_C^{\mathrm{bound}}. Among these, p^C\hat{p}_C is computed directly from the cluster size ∣C∣\lvert C \rvert and centroid kˉC\bar{k}_C via Eq. (2), while VCV_C and Vmax⁡V_{\max} are precomputed cluster-level statistics. Finally, δCbound\delta_C^{\mathrm{bound}} 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 τ\tau to determine which clusters should be expanded for token-level attention. For a single

query head, the rule is straightforward: expand clusters with RC>τR_C > \tau 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 CC 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 τ\tau; 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, τ∈{0.01,0.1}\tau\in\{0.01, 0.1\}. 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 RCR_C 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 τ=0.01\tau= 0.01, REFINEKV nearly matches the quality of Full Attention in all six model–benchmark settings while reducing TPOT, achieving up to a 1.55×1.55\times 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 τ=0.1\tau= 0.1 enables more aggressive sparsification and further improves the maximum speedup to 1.66×1.66\times, 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 τ=0.01\tau= 0.01, which matches full attention performance across all settings while achieving up to 1.56×1.56\times decode speedup as measured by Time Per Output Token (TPOT). Our method extends the quality–latency Pareto frontier.

MethodLongBenchRULERHELMET
Doc QASumm.Few-shotSynth.CodeNIAHA&TQARAGLC-QAICLRec./Rank.
Llama
Full43.6/1.029.2/1.069.2/1.053.0/1.059.6/1.088.6/1.045.0/1.055.0/1.060.4/1.048.6/1.077.0/1.076.4/1.0
Snap 10%41.2/1.723.4/1.765.9/1.753.4/1.758.5/1.779.5/1.740.7/1.755.0/1.761.0/1.748.4/1.677.0/1.660.7/1.5
Snap 25%42.8/1.526.3/1.567.5/1.553.2/1.559.8/1.584.2/1.541.3/1.555.0/1.560.6/1.549.4/1.578.0/1.571.8/1.4
Str. 10%32.7/1.722.2/1.763.3/1.747.5/1.756.1/1.711.2/1.729.8/1.737.5/1.753.5/1.642.4/1.675.0/1.68.6/1.5
Str. 25%35.3/1.524.7/1.566.1/1.546.2/1.558.1/1.530.6/1.534.2/1.550.0/1.557.9/1.541.5/1.573.0/1.517.3/1.4
Pyr. 10%41.3/1.723.6/1.766.0/1.753.3/1.758.4/1.779.7/1.739.2/1.755.0/1.761.0/1.749.0/1.675.0/1.663.9/1.5
Pyr. 25%43.0/1.526.2/1.567.5/1.553.0/1.559.8/1.584.8/1.541.8/1.555.0/1.560.4/1.549.4/1.576.0/1.574.4/1.4
Our τ\tau.0143.3/1.629.3/1.569.4/1.553.3/1.659.7/1.682.8/1.646.7/1.655.0/1.561.7/1.548.9/1.575.0/1.475.1/1.4
Our τ\tau.143.8/1.728.9/1.769.2/1.753.2/1.759.7/1.772.2/1.740.3/1.757.5/1.757.7/1.647.0/1.676.0/1.640.8/1.5
Qwen
Full43.2/1.027.8/1.069.9/1.054.5/1.064.1/1.074.8/1.057.6/1.042.5/1.048.5/1.050.8/1.076.0/1.039.5/1.0
Snap 10%41.3/1.321.3/1.362.2/1.354.5/1.359.5/1.345.3/1.353.6/1.337.5/1.346.7/1.349.9/1.374.0/1.312.7/1.3
Snap 25%42.8/1.323.9/1.366.2/1.354.5/1.362.0/1.351.2/1.357.9/1.340.0/1.349.2/1.349.1/1.275.0/1.222.2/1.2
Str. 10%30.1/1.319.7/1.362.8/1.323.2/1.353.8/1.36.9/1.327.1/1.322.5/1.338.1/1.346.3/1.370.0/1.36.3/1.3
Str. 25%33.0/1.322.5/1.365.9/1.333.1/1.357.8/1.322.0/1.330.3/1.340.0/1.339.8/1.347.3/1.275.0/1.210.2/1.2
Pyr. 10%40.5/1.322.2/1.361.9/1.354.5/1.360.0/1.338.1/1.352.0/1.335.0/1.347.3/1.349.0/1.371.0/1.310.2/1.3
Pyr. 25%42.1/1.324.2/1.366.9/1.354.5/1.362.1/1.348.8/1.354.7/1.340.0/1.345.6/1.248.7/1.275.0/1.213.5/1.2
Our τ\tau.0143.0/1.227.8/1.269.8/1.254.5/1.264.0/1.273.3/1.259.1/1.242.5/1.249.2/1.150.8/1.276.0/1.138.7/1.1
Our τ\tau.143.0/1.327.9/1.369.7/1.354.2/1.363.5/1.367.2/1.357.3/1.337.5/1.349.4/1.250.7/1.276.0/1.233.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 τ=0.01\tau= 0.01, ∣C∣=32|C| = 32, the box summary, GQA-any and Q=0Q = 0.

Selection score. Table 2 fixes the per-head token budget to that of Ours and changes only the score that ranks clusters. Importance alone (p^C,p^CvC\hat{p}_C,\hat{p}_C v_C) or deviation alone (δC\delta_C) falls far behind RCR_C, and the Quest-style logit bound is also lower. The exact-δC\delta_C oracle shows that a tighter summary would help most at small budgets.

Scoreτ=0.01\tau=0.01 Acc.τ=0.01\tau=0.01 Δ\Deltaτ=0.1\tau=0.1 Acc.τ=0.1\tau=0.1 Δ\Delta
Ours (RCR_C, box)70.27—62.58—
RCR_C, ellipsoid68.90−1.3757.29−5.28
Quest-style66.38−3.8858.87−3.71
p^CvC\hat{p}_C v_C58.78−11.4941.38−21.19
p^C\hat{p}_C59.35−10.9242.87−19.71
δC\delta_C47.23−23.0420.68−41.90
RCR_C, exact δC\delta_C72.00+1.7369.06+6.49
Full attention73.37+3.1073.37+10.79

Table 2. Selection-score ablation at a matched per-head token budget (Llama-3.1-8B-Instruct, RULER-128K, Q=0Q=0). Only the score that ranks clusters changes. Δ\Delta is relative to Ours. Exact δC\delta_C is an oracle that scans all keys.

Design choices. Table 3 changes one setting at a time. τ\tau is the main quality–latency knob; ∣C∣|C| 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).

MetricRef.ThresholdCluster sizeGQASummaryAnchors
FullOursτ=0.001\tau=0.001τ=0.1\tau=0.1τ=1\tau=1∣C∣=16|C|=16∣C∣=64|C|=64meanellipsoidQ=32Q=32
Acc.↑\uparrow73.3770.1973.6362.5834.6770.3670.3468.8268.9072.99
TPOT (ms)↓\downarrow24.4315.6819.0814.6214.4215.8616.2015.0615.1417.14
Speedup↑\uparrow1.00×\times1.56×\times1.28×\times1.67×\times1.69×\times1.54×\times1.51×\times1.62×\times1.61×\times1.43×\times

Table 3. Ablation study of Llama-3.1-8B-Instruct on RULER-128K. Ours is the default configuration: τ=0.01\tau=0.01, ∣C∣=32|C|=32, box deviation summary, GQA-any, no prompt-query anchors (Q=0Q=0). 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-kk 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 δ\delta. Our selection rule relies on a computable upper bound on the logit deviation δ\delta of each block, which is cheap to evaluate but can be loose. When we replace this bound with the oracle δ\delta, 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 τ\tau, 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 {(ki,vi)}i=1N\{(k_i, v_i)\}_{i=1}^{N} denote the KV cache, where ki∈Rdk_i \in\mathbb{R}^{d}, vi∈Rdvv_i \in\mathbb{R}^{d_v}. Let C={C1,…,Cm}\mathcal{C} = \{C_1, \ldots, C_m\} be a partition of the KV cache. For each cluster C∈CC \in\mathcal{C}, let nC=∣C∣n_C = |C| and define

kˉC=1nC∑i∈Cki,vˉC=1nC∑i∈Cvi.(5)\bar{k}_C = \frac{1}{n_C}\sum_{i\in C} k_i,\qquad\bar{v}_C = \frac{1}{n_C}\sum_{i\in C} v_i. \tag*{(5)}

For a query q∈Rdq \in\mathbb{R}^{d}, define the token and representative logits as

si=q⊤kid,sC=q⊤kˉCd.(6)s_i = \frac{q^\top k_i}{\sqrt{d}},\qquad s_C = \frac{q^\top\bar{k}_C}{\sqrt{d}}. \tag*{(6)}

The exact and approximated unnormalized masses of cluster CC are

zC=∑i∈Cesi,z^C=nCesC.(7)z_C = \sum_{i\in C} e^{s_i},\qquad\hat{z}_C = n_C e^{s_C}. \tag*{(7)}

Equivalently, the representative of CC has logit sC+log⁡nCs_C + \log n_C.

The exact and approximated total mass are:

Z=∑C∈CzC,Z^=∑C∈Cz^C.(8)Z = \sum_{C\in\mathcal{C}} z_C,\qquad\hat{Z} = \sum_{C\in\mathcal{C}} \hat{z}_C. \tag*{(8)}

Define the exact within-cluster output

vC=∑i∈CesivizC,(9)v_C = \frac{\sum_{i\in C} e^{s_i}v_i}{z_C}, \tag*{(9)}

and the exact and approximated cluster probabilities

pC=zCZ,p^C=z^CZ^.(10)p_C = \frac{z_C}{Z},\qquad\hat{p}_C = \frac{\hat{z}_C}{\hat{Z}}. \tag*{(10)}

The exact and approximated attention outputs are therefore

o=∑C∈CpCvC,o^=∑C∈Cp^CvˉC.(11)o = \sum_{C\in\mathcal{C}} p_Cv_C,\qquad\hat{o} = \sum_{C\in\mathcal{C}} \hat{p}_C\bar{v}_C. \tag*{(11)}

Let

Vmax⁡=max⁡i∥vi∥2,VC=max⁡i∈C∥vi∥2.(12)V_{\max} = \max_i \|v_i\|_2,\qquad V_C = \max_{i\in C} \|v_i\|_2. \tag*{(12)}

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 o~=∑C∈Cp^CvC\tilde{o} = \sum_{C \in\mathcal{C}} \hat{p}_C v_C, we have:

o−o^=(o−o~)+(o~−o^)(13)o - \hat{o} = (o - \tilde{o}) + (\tilde{o} - \hat{o}) \tag*{(13)}
=∑C∈C(pC−p^C)vC⏟inter-cluster mass redistribution+∑C∈Cp^C(vC−vˉC)⏟intra-cluster value distortion.(14)= \underbrace{\sum_{C \in\mathcal{C}} (p_C - \hat{p}_C)v_C}_{\text{inter-cluster mass redistribution}} + \underbrace{\sum_{C \in\mathcal{C}} \hat{p}_C(v_C - \bar{v}_C)}_{\text{intra-cluster value distortion}}. \tag*{(14)}

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, (pC−p^C)(p_C - \hat{p}_C), 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 vCv_C with vˉC\bar{v}_C. It satisfies a desired property: For a cluster CC, when all q⊤kiq^{\top} k_i are close to q⊤kˉCq^{\top} \bar{k}_C, the cluster is well-approximated and this term gets close to zero. In particular, if q⊤ki=q⊤kˉC,∀i∈Cq^{\top} k_i = q^{\top} \bar{k}_C, \forall i \in C, the term becomes exactly zero.

The first term, pC−p^Cp_C - \hat{p}_C, does not satisfy this property. It reflects shift in probability assigned to cluster CC, which is coupled with approximation of all clusters due to softmax normalization. Instead, we want to measure how approximating cluster CC 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

o~=∑C∈Cp^CvC,(15)\tilde{o} = \sum_{C \in\mathcal{C}} \hat{p}_C v_C, \tag*{(15)}

the cluster mass correction factor

mC=zCz^C,(16)m_C = \frac{z_C}{\hat{z}_C}, \tag*{(16)}

Then the inter-cluster mass redistribution error admits the exact source-wise decomposition

o−o~=∑C∈Cp^CmC−1∑C′∈Cp^C′mC′(vC−o~).(17)o - \tilde{o} = \sum_{C \in\mathcal{C}} \hat{p}_C \frac{m_C - 1}{\sum_{C' \in\mathcal{C}} \hat{p}_{C'}m_{C'}}(v_C - \tilde{o}). \tag*{(17)}

In particular, if cluster CC has no mass approximation error, i.e., zC=z^Cz_C = \hat{z}_C (equivalently, mC=1m_C = 1), its source-wise contribution to the mass-redistribution error is exactly zero.

Using Lemma A.1, we first rewrite o−o~o - \tilde{o} as:

o−o~=∑C∈Cp^CmC−1∑C′∈Cp^C′mC′(vC−o~).(18)o - \tilde{o} = \sum_{C \in\mathcal{C}} \hat{p}_C \frac{m_C - 1}{\sum_{C' \in\mathcal{C}} \hat{p}_{C'}m_{C'}}(v_C - \tilde{o}). \tag*{(18)}

With ∥vC−o~∥2≤2Vmax⁡\lVert v_C - \tilde{o} \rVert_2 \leq2V_{\max}:

∥o−o~∥2≤2Vmax⁡∑C∈Cp^C(mC−1)∑C′∈Cp^C′mC′.(19)\lVert o - \tilde{o} \rVert_2 \leq2V_{\max} \frac{\sum_{C \in\mathcal{C}} \hat{p}_C(m_C - 1)}{\sum_{C' \in\mathcal{C}} \hat{p}_{C'}m_{C'}}. \tag*{(19)}

To connect the local mass correction mCm_C with the approximation fidelity of cluster CC, we define the query-dependent logit deviation

δC=max⁡i∈C∣si−sC∣=max⁡i∈C∣q⊤(ki−kˉC)d∣.(20)\delta_C = \max_{i \in C} \lvert s_i - s_C \rvert= \max_{i \in C} \left\lvert\frac{q^{\top}(k_i - \bar{k}_C)}{\sqrt{d}} \right\rvert. \tag*{(20)}

By technical lemma A.2, mC≤cosh⁡(δC)m_C \leq\cosh(\delta_C). Note that ∑C∈Cp^C=1\sum_{C \in\mathcal{C}} \hat{p}_C = 1, which gives

∑C∈Cp^C(mC−1)∑C∈Cp^CmC=1−1∑C∈Cp^CmC.(21)\frac{\sum_{C \in\mathcal{C}} \hat{p}_C(m_C - 1)}{\sum_{C \in\mathcal{C}} \hat{p}_C m_C} = 1 - \frac{1}{\sum_{C \in\mathcal{C}} \hat{p}_C m_C}. \tag*{(21)}

Since t↦1−1/tt \mapsto1 - 1/t is monotonically increasing for t≥1t \ge1, we obtain:

∥o−o~∥2≤2Vmax⁡∑C∈Cp^C(cosh⁡(δC)−1)∑C∈Cp^Ccosh⁡(δC).(22)\lVert o-\tilde{o}\rVert_2 \le2V_{\max}\frac{\sum_{C\in\mathcal{C}}\hat{p}_C\left(\cosh(\delta_C)-1\right)}{\sum_{C\in\mathcal{C}}\hat{p}_C\cosh(\delta_C)}. \tag*{(22)}

Intra-cluster value distortion

For the intra-cluster value distortion term, define the exact within-cluster attention weights as

wi∣C=esizC,∑i∈Cwi∣C=1.(23)w_{i\mid C}=\frac{e^{s_i}}{z_C},\qquad\sum_{i\in C}w_{i\mid C}=1. \tag*{(23)}

Then

vC−vˉC=∑i∈Cwi∣Cvi−∑i∈C1nCvi(24)v_C-\bar{v}_C=\sum_{i\in C}w_{i\mid C}v_i-\sum_{i\in C}\frac{1}{n_C}v_i \tag*{(24)}
=∑i∈C(wi∣C−1nC)vi.(25)=\sum_{i\in C}\left(w_{i\mid C}-\frac{1}{n_C}\right)v_i. \tag*{(25)}

Therefore,

∥vC−vˉC∥2≤∑i∈C∣wi∣C−1nC∣∥vi∥2(26)\lVert v_C-\bar{v}_C\rVert_2\le\sum_{i\in C}\left|w_{i\mid C}-\frac{1}{n_C}\right|\lVert v_i\rVert_2 \tag*{(26)}
≤VC∑i∈C∣wi∣C−1nC∣.(27)\le V_C\sum_{i\in C}\left|w_{i\mid C}-\frac{1}{n_C}\right|. \tag*{(27)}

By Lemma A.3, since ∣si−sC∣≤δC\lvert s_i-s_C\rvert\le\delta_C, and

wi∣C=esi−sC∑j∈Cesj−sC,(28)w_{i\mid C}=\frac{e^{s_i-s_C}}{\sum_{j\in C}e^{s_j-s_C}}, \tag*{(28)}

we have

∑i∈C∣wi∣C−1nC∣≤2tanh⁡(δC2).(29)\sum_{i\in C}\left|w_{i\mid C}-\frac{1}{n_C}\right|\le2\tanh\left(\frac{\delta_C}{2}\right). \tag*{(29)}

Hence,

∥vC−vˉC∥2≤2VCtanh⁡(δC2).(30)\lVert v_C-\bar{v}_C\rVert_2\le2V_C\tanh\left(\frac{\delta_C}{2}\right). \tag*{(30)}

Finally,

∥∑C∈Cp^C(vC−vˉC)∥2≤∑C∈Cp^C∥vC−vˉC∥2(31)\left\lVert\sum_{C\in\mathcal{C}}\hat{p}_C(v_C-\bar{v}_C)\right\rVert_2\le\sum_{C\in\mathcal{C}}\hat{p}_C\lVert v_C-\bar{v}_C\rVert_2 \tag*{(31)}
≤2∑C∈Cp^CVCtanh⁡(δC2).(32)\le2\sum_{C\in\mathcal{C}}\hat{p}_CV_C\tanh\left(\frac{\delta_C}{2}\right). \tag*{(32)}

Combining Eq. (22) and Eq. (32) via the triangle inequality, we have

∥o−o^∥2≤∥o−o~∥2+∥o~−o^∥2(33)\lVert o-\hat{o}\rVert_2\le\lVert o-\tilde{o}\rVert_2+\lVert\tilde{o}-\hat{o}\rVert_2 \tag*{(33)}
≤2Vmax⁡∑C∈Cp^C(cosh⁡(δC)−1)∑C∈Cp^Ccosh⁡(δC)+2∑C∈Cp^CVCtanh⁡(δC2)(34)\le2V_{\max}\frac{\sum_{C\in\mathcal{C}}\hat{p}_C\left(\cosh(\delta_C)-1\right)}{\sum_{C\in\mathcal{C}}\hat{p}_C\cosh(\delta_C)}+2\sum_{C\in\mathcal{C}}\hat{p}_CV_C\tanh\left(\frac{\delta_C}{2}\right) \tag*{(34)}
=2∑C∈Cp^C(Vmax⁡cosh⁡(δC)−1∑C′∈Cp^C′cosh⁡(δC′)+VCtanh⁡(δC2)).(35)=2\sum_{C\in\mathcal{C}}\hat{p}_C\left(V_{\max}\frac{\cosh(\delta_C)-1}{\sum_{C'\in\mathcal{C}}\hat{p}_{C'}\cosh(\delta_{C'})}+V_C\tanh\left(\frac{\delta_C}{2}\right)\right). \tag*{(35)}

The maximum logit deviation δC\delta_C, however, cannot be used directly for access decisions, since evaluating it requires inspecting all keys within cluster CC, defeating the purpose of cluster-level selection. We therefore construct an efficiently computable query-dependent upper bound δCbound\delta_C^{\mathrm{bound}} from compact cluster statistics, such that

δC≤δCbound.(36)\delta_C \le\delta_C^{\mathrm{bound}}. \tag*{(36)}

The specific construction of δCbound\delta_C^{\mathrm{bound}} is deferred to Appendix A.7. Since the above error bound is monotonically non-decreasing with respect to each δC\delta_C, replacing δC\delta_C with δCbound\delta_C^{\mathrm{bound}} yields a computable upper bound:

∥o−o^∥2≤2∑C∈Cp^C(Vmax⁡cosh⁡(δCbound)−1∑C′∈Cp^C′cosh⁡(δC′bound)+VCtanh⁡(δCbound2)⏟Risk Score RC for cluster C).(37)\lVert o-\hat{o}\rVert_2 \le2\sum_{C\in\mathcal{C}}\hat{p}_C\left(\underbrace{V_{\max}\frac{\cosh(\delta_C^{\mathrm{bound}})-1}{\sum_{C'\in\mathcal{C}}\hat{p}_{C'}\cosh(\delta_{C'}^{\mathrm{bound}})}+V_C\tanh\left(\frac{\delta_C^{\mathrm{bound}}}{2}\right)}_{\text{Risk Score }R_C\text{ for cluster }C}\right). \tag*{(37)}

We write the resulting upper bound in a clusterwise form and use each clusterwise term as its risk score RCR_C.

Proof of core lemma

Proof. We define absolute mass correction of cluster CC:

ΔzC=zC−z^C≥0(38)\Delta z_C=z_C-\hat{z}_C\ge0 \tag*{(38)}

Proof of inequality can be done using Jensen’s inequality with 1/nC∑isi=sC1/n_C\sum_i s_i=s_C. This revels that approximation underestimate the mass of cluster.

We have:

pC−p^C=zCZ−p^C(39)p_C-\hat{p}_C=\frac{z_C}{Z}-\hat{p}_C \tag*{(39)}
=ΔzC+z^C−p^CZZ(40)=\frac{\Delta z_C+\hat{z}_C-\hat{p}_C Z}{Z} \tag*{(40)}
=ΔzC+p^CZ^−p^CZZ(41)=\frac{\Delta z_C+\hat{p}_C\hat{Z}-\hat{p}_C Z}{Z} \tag*{(41)}
=ΔzCZ⏟effect of cluster C−p^C∑C′ΔzC′Z⏟effect of changed global normalization.(42)=\underbrace{\frac{\Delta z_C}{Z}}_{\text{effect of cluster }C}-\underbrace{\frac{\hat{p}_C\sum_{C'}\Delta z_{C'}}{Z}}_{\text{effect of changed global normalization}}. \tag*{(42)}

If we define TC,C′T_{C,C'} as the effect of approximating C′C' on cluster CC:

TC,C′=ΔzC′Z(1[C=C′]−p^C).(43)T_{C,C'}=\frac{\Delta z_{C'}}{Z}\left(\mathbf{1}_{[C=C']}-\hat{p}_C\right). \tag*{(43)}

Naturally we have:

pC−p^C=∑C′TC,C′.(44)p_C-\hat{p}_C=\sum_{C'}T_{C,C'}. \tag*{(44)}

And:

o−o~=∑C(pC−p^C)vC=∑C∑C′TC,C′vC(45)o-\tilde{o}=\sum_C(p_C-\hat{p}_C)v_C=\sum_C\sum_{C'}T_{C,C'}v_C \tag*{(45)}

As analysed before, we want to know how much output distortion originates from approximating a particular cluster:

o−o~=∑C′∑CTC,C′vC(46)o-\tilde{o}=\sum_{C'}\sum_C T_{C,C'}v_C \tag*{(46)}
=∑C′∑CΔzC′Z(1[C=C′]−p^C)vC(47)=\sum_{C'}\sum_C\frac{\Delta z_{C'}}{Z}\left(\mathbf{1}_{[C=C']}-\hat{p}_C\right)v_C \tag*{(47)}
=∑C′ΔzC′Z(vC′−∑Cp^CvC)(48)=\sum_{C'}\frac{\Delta z_{C'}}{Z}\left(v_{C'}-\sum_C\hat{p}_Cv_C\right) \tag*{(48)}
=∑C′ΔzC′Z(vC′−o~)(49)=\sum_{C'}\frac{\Delta z_{C'}}{Z}\left(v_{C'}-\tilde{o}\right) \tag*{(49)}

We define mass correction factor mCm_C as

mC=zCz~C=1nC∑i∈Cesi−sC≥1(50)m_C=\frac{z_C}{\tilde{z}_C}=\frac{1}{n_C}\sum_{i\in C}e^{s_i-s_C}\ge1 \tag*{(50)}

The total mass correction factor MM can be defined as:

M=ZZ^=∑C∈CzCZ^=∑C∈CmCz~CZ^=∑C∈Cp^CmC(51)M=\frac{Z}{\hat{Z}}=\frac{\sum_{C\in\mathcal{C}}z_C}{\hat{Z}}=\frac{\sum_{C\in\mathcal{C}}m_C\tilde{z}_C}{\hat{Z}}=\sum_{C\in\mathcal{C}}\hat{p}_Cm_C \tag*{(51)}

We have:

o−o~=∑CΔzCZ(vC−o~)(52)o-\tilde{o}=\sum_C\frac{\Delta z_C}{Z}(v_C-\tilde{o}) \tag*{(52)}
=∑Cz~C(mC−1)Z^M(vC−o~)(53)=\sum_C\frac{\tilde{z}_C(m_C-1)}{\hat{Z}M}(v_C-\tilde{o}) \tag*{(53)}
=∑Cp^C(mC−1)M(vC−o~)(54)=\sum_C\frac{\hat{p}_C(m_C-1)}{M}(v_C-\tilde{o}) \tag*{(54)}

Proof of technical lemmas

Lemma A.2 (Cluster Mass Correction Bound). For any cluster C∈CC\in\mathcal{C}, let the query-dependent logit deviation be defined as

δC:=max⁡i∈C∣si−sC∣=max⁡i∈C∣qT(ki−kˉC)d∣.(55)\delta_C:=\max_{i\in C}|s_i-s_C|=\max_{i\in C}\left|\frac{q^{\mathsf{T}}(k_i-\bar{k}_C)}{\sqrt{d}}\right|. \tag*{(55)}

Then, the local mass correction factor mC:=1nC∑i∈Cesi−sCm_C:=\frac{1}{n_C}\sum_{i\in C}e^{s_i-s_C} satisfies

mC≤cosh⁡(δC).(56)m_C\le\cosh(\delta_C). \tag*{(56)}

Proof. Let xi=si−sCx_i=s_i-s_C. By definition of sCs_C, the mean of {xi}i∈C\{x_i\}_{i\in C} vanishes:

1nC∑i∈Cxi=1nC∑i∈Csi−sC=0.(57)\frac{1}{n_C}\sum_{i\in C}x_i=\frac{1}{n_C}\sum_{i\in C}s_i-s_C=0. \tag*{(57)}

Moreover, by definition of δC\delta_C, we have xi∈[−δC,δC]x_i\in[-\delta_C,\delta_C] for all i∈Ci\in C. By the convexity of the exponential function x↦exx\mapsto e^x, any x∈[−δC,δC]x\in[-\delta_C,\delta_C] can be upper-bounded via the secant line between the endpoints:

ex≤δC+x2δCeδC+δC−x2δCe−δC.(58)e^x\le\frac{\delta_C+x}{2\delta_C}e^{\delta_C}+\frac{\delta_C-x}{2\delta_C}e^{-\delta_C}. \tag*{(58)}

Averaging this inequality over all tokens in cluster CC, we obtain

mC=1nC∑i∈Cexi(59)m_C = \frac{1}{n_C}\sum_{i \in C} e^{x_i} \tag*{(59)}
≤1nC∑i∈C[δC+xi2δCeδC+δC−xi2δCe−δC](60)\le\frac{1}{n_C}\sum_{i \in C}\left[\frac{\delta_C+x_i}{2\delta_C}e^{\delta_C}+\frac{\delta_C-x_i}{2\delta_C}e^{-\delta_C}\right] \tag*{(60)}
=δC+1nC∑i∈Cxi2δCeδC+δC−1nC∑i∈Cxi2δCe−δC(61)= \frac{\delta_C+\frac{1}{n_C}\sum_{i \in C}x_i}{2\delta_C}e^{\delta_C}+\frac{\delta_C-\frac{1}{n_C}\sum_{i \in C}x_i}{2\delta_C}e^{-\delta_C} \tag*{(61)}
=eδC+e−δC2(62)= \frac{e^{\delta_C}+e^{-\delta_C}}{2} \tag*{(62)}
=cosh⁡(δC),(63)= \cosh(\delta_C), \tag*{(63)}

which completes the proof.

Lemma A.3 (Softmax deviation from uniform). Let x1,…,xn∈Rx_1,\ldots,x_n \in\mathbb{R} satisfy

∣xi∣≤δ,i=1,…,n,(64)|x_i| \le\delta,\qquad i=1,\ldots,n, \tag*{(64)}

and define

wi=exi∑j=1nexj.(65)w_i = \frac{e^{x_i}}{\sum_{j=1}^{n}e^{x_j}}. \tag*{(65)}

Then

∑i=1n∣wi−1n∣≤2tanh⁡(δ2).(66)\sum_{i=1}^{n}\left|w_i-\frac{1}{n}\right| \le2\tanh\left(\frac{\delta}{2}\right). \tag*{(66)}

Proof. Since xi∈[−δ,δ]x_i \in[-\delta,\delta], for any i,ji,j,

wiwj=exi−xj≤e2δ.(67)\frac{w_i}{w_j}=e^{x_i-x_j}\le e^{2\delta}. \tag*{(67)}

Let

ri=nwi,(68)r_i=nw_i, \tag*{(68)}

so that

1n∑i=1nri=1.(69)\frac{1}{n}\sum_{i=1}^{n}r_i=1. \tag*{(69)}

Denote

a=min⁡iri,b=max⁡iri.(70)a=\min_i r_i,\qquad b=\max_i r_i. \tag*{(70)}

Then

0<a≤1≤b,ba≤e2δ.(71)0<a\le1\le b,\qquad\frac{b}{a}\le e^{2\delta}. \tag*{(71)}

For any random variable R∈[a,b]R\in[a,b] with E[R]=1\mathbb{E}[R]=1, the convexity of ∣R−1∣|R-1| implies

12E∣R−1∣≤(1−a)(b−1)b−a.(72)\frac{1}{2}\mathbb{E}|R-1|\le\frac{(1-a)(b-1)}{b-a}. \tag*{(72)}

Applying this to the empirical distribution over {ri}i=1n\{r_i\}_{i=1}^{n} gives

12∑i=1n∣wi−1n∣≤(1−a)(b−1)b−a.(73)\frac{1}{2}\sum_{i=1}^{n}\left|w_i-\frac{1}{n}\right|\le\frac{(1-a)(b-1)}{b-a}. \tag*{(73)}

For a fixed ratio R=b/aR=b/a, the right-hand side is maximized at

a=1R,b=R,(74)a=\frac{1}{\sqrt{R}},\qquad b=\sqrt{R}, \tag*{(74)}

which yields

(1−a)(b−1)b−a≤R−1R+1.(75)\frac{(1-a)(b-1)}{b-a} \le\frac{\sqrt{R}-1}{\sqrt{R}+1}. \tag*{(75)}

Since R≤e2δR \le e^{2\delta},

R−1R+1≤eδ−1eδ+1=tanh⁡(δ2).(76)\frac{\sqrt{R}-1}{\sqrt{R}+1} \le\frac{e^\delta-1}{e^\delta+1}=\tanh\left(\frac{\delta}{2}\right). \tag*{(76)}

Therefore,

∑i=1n∣wi−1n∣≤2tanh⁡(δ2).(77)\sum_{i=1}^{n}\left|w_i-\frac{1}{n}\right| \le2\tanh\left(\frac{\delta}{2}\right). \tag*{(77)}

Computable upper bound for C.

The quantity δC\delta_C directly measures the worst-case logit deviation within cluster CC under the current query:

δC=max⁡i∈C∣qT(ki−kˉC)d∣.(78)\delta_C=\max_{i\in C}\left|\frac{q^{\mathsf T}(k_i-\bar{k}_C)}{\sqrt{d}}\right|. \tag*{(78)}

While δC\delta_C 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 DC(q)D_C(q) such that

δCbound(q)≥δC.(79)\delta_C^{\mathrm{bound}}(q)\ge\delta_C. \tag*{(79)}

Axis-aligned box bound.

Let kCmin⁡k_C^{\min} and kCmax⁡k_C^{\max} be the coordinate-wise minimum and maximum keys in cluster CC, and define

sC=qTkˉCd.(80)s_C=\frac{q^{\mathsf T}\bar{k}_C}{\sqrt{d}}. \tag*{(80)}

Since every kik_i, i∈Ci\in C, lies inside the box [kCmin⁡,kCmax⁡][k_C^{\min},k_C^{\max}], its query-key score is bounded by

sCupper=1d∑j=1dmax⁡{qjkC,jmin⁡,qjkC,jmax⁡}.(81)s_C^{\mathrm{upper}}=\frac{1}{\sqrt{d}}\sum_{j=1}^{d}\max\{q_jk_{C,j}^{\min},q_jk_{C,j}^{\max}\}. \tag*{(81)}
sClower=1d∑j=1dmin⁡{qjkC,jmin⁡,qjkC,jmax⁡}.(82)s_C^{\mathrm{lower}}=\frac{1}{\sqrt{d}}\sum_{j=1}^{d}\min\{q_jk_{C,j}^{\min},q_jk_{C,j}^{\max}\}. \tag*{(82)}

Therefore,

δCbox(q)=max⁡{∣sCupper−sC∣,∣sClower−sC∣}≥δC.(83)\delta_C^{\mathrm{box}}(q)=\max\{|s_C^{\mathrm{upper}}-s_C|,|s_C^{\mathrm{lower}}-s_C|\}\ge\delta_C. \tag*{(83)}

This bound requires two dd-dimensional vectors per cluster and O(d)O(d) query-time computation. It can be loose because its coordinate-wise extrema may come from different keys.

Diagonal-Ellipsoid Bound

For a centered key ri=ki−kˉCr_i=k_i-\bar{k}_C, define the coordinate-wise radii

wC,j=max⁡i∈C∣ri,j∣.(84)w_{C,j}=\max_{i\in C}|r_{i,j}|. \tag*{(84)}

For clarity, we assume wC,j>0w_{C,j}>0; a zero-width coordinate has zero residual for every key and can be omitted without affecting the bound. We further define

ρC=max⁡i∈C(∑j=1dkri,j2wC,j2)1/2.(85)\rho_C=\max_{i\in C}\left(\sum_{j=1}^{d_k}\frac{r_{i,j}^{2}}{w_{C,j}^{2}}\right)^{1/2}. \tag*{(85)}

The vector wC\mathbf{w}_C normalizes the scale of each coordinate, while ρC\rho_C measures the largest residual after this normalization. Equivalently, all centered keys lie inside the diagonal ellipsoid

∑j=1dkrj2wC,j2≤ρC2.(86)\sum_{j=1}^{d_k} \frac{r_j^2}{w_{C,j}^2} \le\rho_C^2. \tag*{(86)}

The resulting query-dependent bound is

δCell(q)=ρCdk(∑j=1dkqj2wC,j2)1/2.(87)\delta_C^{\mathrm{ell}}(\mathbf{q}) = \frac{\rho_C}{\sqrt{d_k}}\left(\sum_{j=1}^{d_k}q_j^2w_{C,j}^2\right)^{1/2}. \tag*{(87)}

Indeed, for every i∈Ci \in C, weighted Cauchy–Schwarz gives

∣q⊤ri∣=∣∑j=1dk(qjwC,j)ri,jwC,j∣(88)\left|\mathbf{q}^{\top}\mathbf{r}_i\right| = \left|\sum_{j=1}^{d_k}(q_jw_{C,j})\frac{r_{i,j}}{w_{C,j}}\right| \tag*{(88)}
≤(∑j=1dkqj2wC,j2)1/2(∑j=1dkri,j2wC,j2)1/2(89)\le\left(\sum_{j=1}^{d_k}q_j^2w_{C,j}^2\right)^{1/2}\left(\sum_{j=1}^{d_k}\frac{r_{i,j}^2}{w_{C,j}^2}\right)^{1/2} \tag*{(89)}
≤ρC(∑j=1dkqj2wC,j2)1/2.(90)\le\rho_C\left(\sum_{j=1}^{d_k}q_j^2w_{C,j}^2\right)^{1/2}. \tag*{(90)}

Therefore,

δCell(q)≥max⁡i∈C∣q⊤(ki−k‾C)∣dk.(91)\delta_C^{\mathrm{ell}}(\mathbf{q}) \ge\max_{i\in C}\frac{\left|\mathbf{q}^{\top}(\mathbf{k}_i-\overline{\mathbf{k}}_C)\right|}{\sqrt{d_k}}. \tag*{(91)}

Both wC\mathbf{w}_C and ρC\rho_C are query-independent and can be precomputed once per block. The bound stores one vector and one scalar per block and takes O(dk)O(d_k) 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 QQ 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 QQ 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.

MetricRef. FullNumber of query anchors QQ0 (default)163264
Acc.↑73.3770.1972.4972.9972.91
Steady TPOT (ms)↓24.4315.6816.6517.1417.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 (τ=0.01\tau=0.01, ∣C∣=32|C|=32, box summary, GQA-any) and differ only in the number of query anchors QQ; Q=0Q=0 (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 CC and query qq, let

oC=1Z∑i∈Ceq⊤ki/dvi,o^C=p^CvˉC,p^C=∣C∣eq⊤kˉC/d∑C′∣C′∣eq⊤kˉC′/do_C = \frac{1}{Z}\sum_{i\in C} e^{q^\top k_i/\sqrt{d}}v_i,\qquad\hat{o}_C = \hat{p}_C\bar{v}_C,\qquad\hat{p}_C = \frac{|C|e^{q^\top\bar{k}_C/\sqrt{d}}}{\sum_{C'}|C'|e^{q^\top\bar{k}_{C'}/\sqrt{d}}}

where ZZ is the Full Attention softmax normalizer. oCo_C is CC’s contribution to the Full Attention output, and o^C\hat{o}_C is its contribution to the output in which every cluster is replaced by its representative. Hence ∑C(oC−o^C)\sum_C(o_C-\hat{o}_C) is exactly the error of that approximation, and ∥oC−o^C∥\lVert o_C-\hat{o}_C\rVert is CC’s share of it.

Correlation analysis. We use Llama-3.1-8B on RULER-128K (26 prompts) in the main setting (B=32B=32, box, τ=.01\tau=.01). 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. p^C\hat{p}_C alone reaches .975, so the target is dominated by attention mass. We therefore also report the partial Spearman correlation given p^C\hat{p}_C.

Within each instance, we rank-transform the score ss, the target yy and p^C\hat{p}_C across clusters. We then regress the ranks of ss and of yy on the rank of p^C\hat{p}_C by least squares, and take the Pearson correlation of the two residuals. Equivalently,

ρsy⋅p^=ρsy−ρsp^ρyp^(1−ρsp^2)(1−ρyp^2)\rho_{sy\cdot\hat{p}}=\frac{\rho_{sy}-\rho_{s\hat{p}}\rho_{y\hat{p}}}{\sqrt{(1-\rho_{s\hat{p}}^2)(1-\rho_{y\hat{p}}^2)}}

where each ρ\rho is a Spearman correlation. This measures how much a score explains about the error beyond attention mass. On this target, RCR_C carries clear information beyond mass (partial ρ=.49\rho=.49), more than a Quest-style bound (.32). The mass-weighted value norm p^C∥vˉC∥\hat{p}_C\lVert\bar{v}_C\rVert 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 RCR_C from an importance score, and a tighter deviation summary would sharpen it further.

ScoreRawPartial
p^C\hat{p}_C.975
p^C∥vˉC∥\hat{p}_C \lVert\bar{v}_C\rVert.975.06
Quest-style bound.864.32
RCR_C (box δ\delta).975.49
RCR_C (exact δ\delta, oracle).990.81

Table 5. Spearman correlation between each score and ∥oC−o^C∥\lVert o_C-\hat{o}_C\rVert (Llama-3.1-8B, RULER-128K, B=32B=32, box, τ=.01\tau=.01). Values are medians over (step, layer, head). “Partial” is the correlation given p^C\hat{p}_C.

Experiment Details

Critical KV Analysis

Top-pp KV analysis. For the top-pp 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 p∈{0,0.25,0.5,0.75,0.9,0.95,0.99,1}p \in\{0, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 1\}. 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 q−k≥64q-k \ge64. Output error is measured after renormalizing attention over the selected KVs as ∥Op−Ofull∥2/∥Ofull∥2\lVert O_p-O_{\mathrm{full}}\rVert_2/\lVert O_{\mathrm{full}}\rVert_2.

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-kk 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 β=20\beta= 20. 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 kk-means, four exact sink tokens, and a 64-token exact local window. We evaluate the threshold pairs (p1,p2)∈{(0.85,0.50),(0.85,0.70),(0.90,0.60),(0.95,0.70)}(p_1,p_2) \in\{(0.85, 0.50), (0.85, 0.70), (0.90, 0.60), (0.95, 0.70)\} when complete measurements are available. Clusters outside the p1p_1 probability prefix are pruned, clusters between the p1p_1 and p2p_2 prefixes are represented by their centroids, and clusters inside the p2p_2 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 lengthLatency (s)Fraction (%)
PrefillDecodePrefillDecodePrefillDecode
16K5121.019.209.990.1
32K5122.4211.1517.882.2
32K10242.4122.379.790.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 TsteadyT_{\mathrm{steady}} denote the elapsed time of the remaining 126 decoding iterations. We compute

TPOT=Tsteady126 ms/token.\mathrm{TPOT} = \frac{T_{\mathrm{steady}}}{126}\ \mathrm{ms/token}.

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.

Benchmark128 tokens256 tokens512 tokens
LongBench14.7614.61 (−1.03%)14.55 (−1.43%)
RULER16.3516.20 (−0.92%)16.14 (−1.27%)
HELMET17.2017.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.

MethodNarrativeQAQasperMultiFieldQAHotpotQA2WikiMQAMuSiQueGovReportQMSumMultiNewsTRECTriviaQASAMSumCountRetrievalLCCRepoBench-P
Full29.8/1.045.5/1.054.7/1.055.2/1.045.0/1.031.2/1.035.0/1.025.3/1.027.2/1.072.5/1.091.7/1.043.4/1.06.5/1.099.5/1.063.1/1.056.1/1.0
Snap 10%30.3/1.736.5/1.752.4/1.754.9/1.742.7/1.730.8/1.727.0/1.723.4/1.719.8/1.763.0/1.791.9/1.742.8/1.77.2/1.799.5/1.760.8/1.756.3/1.7
Snap 25%30.0/1.542.2/1.554.2/1.555.1/1.544.4/1.531.1/1.530.4/1.525.0/1.523.4/1.568.5/1.591.6/1.542.4/1.56.9/1.599.5/1.562.8/1.556.8/1.5
Str. 10%26.3/1.726.2/1.733.7/1.747.6/1.737.0/1.725.2/1.725.4/1.721.4/1.719.7/1.758.5/1.788.8/1.742.5/1.76.4/1.788.5/1.759.4/1.752.9/1.7
Str. 25%28.1/1.531.3/1.535.6/1.550.4/1.540.9/1.525.3/1.529.1/1.522.0/1.523.0/1.566.0/1.590.0/1.542.4/1.57.9/1.584.5/1.560.9/1.555.3/1.5
Pyr. 10%30.3/1.736.0/1.752.3/1.754.8/1.742.7/1.731.6/1.726.7/1.724.2/1.719.9/1.763.0/1.791.9/1.743.0/1.77.2/1.799.5/1.760.6/1.756.1/1.7
Pyr. 25%30.5/1.542.5/1.553.8/1.555.4/1.544.4/1.531.6/1.530.1/1.524.9/1.523.6/1.567.5/1.591.5/1.543.6/1.56.4/1.599.5/1.562.8/1.556.9/1.5
Quest30.5/1.145.1/1.155.5/1.155.3/1.145.9/1.132.8/1.135.8/1.125.8/1.127.2/1.172.0/1.191.5/1.143.1/1.16.9/1.199.5/1.162.9/1.156.4/1.1
Double30.6/1.443.8/1.455.9/1.454.7/1.443.6/1.431.4/1.434.6/1.424.5/1.426.7/1.471.5/1.491.6/1.442.9/1.47.0/1.499.0/1.463.5/1.455.6/1.4
Our τ\tau.0129.2/1.645.4/1.654.2/1.655.2/1.645.0/1.630.9/1.635.4/1.625.4/1.527.2/1.572.5/1.591.6/1.544.0/1.57.0/1.699.5/1.663.0/1.656.3/1.6
Our τ\tau.130.1/1.744.3/1.756.3/1.755.3/1.745.3/1.731.7/1.634.3/1.725.1/1.727.2/1.771.5/1.791.7/1.744.6/1.76.4/1.7100.0/1.762.5/1.757.0/1.7
Our τ\tau.1 Q3229.7/1.645.3/1.655.7/1.655.1/1.644.9/1.631.2/1.634.6/1.625.8/1.627.4/1.672.5/1.691.3/1.643.7/1.67.6/1.6100.0/1.662.8/1.656.5/1.6
Full28.6/1.044.6/1.051.4/1.058.3/1.046.5/1.029.6/1.033.3/1.024.3/1.025.8/1.073.5/1.089.4/1.046.9/1.09.0/1.0100.0/1.061.2/1.066.9/1.0
Snap 10%29.2/1.336.1/1.348.8/1.357.4/1.346.4/1.329.8/1.328.4/1.322.7/1.320.6/1.354.5/1.388.4/1.343.9/1.39.0/1.3100.0/1.357.2/1.366.7/1.3
Snap 25%29.9/1.341.1/1.350.7/1.358.3/1.346.1/1.330.6/1.328.4/1.323.3/1.320.1/1.366.0/1.388.8/1.344.9/1.39.0/1.3100.0/1.357.7/1.366.7/1.3
Str. 10%24.1/1.327.1/1.328.2/1.343.9/1.338.0/1.327.1/1.323.8/1.319.3/1.316.0/1.358.5/1.386.6/1.343.3/1.39.0/1.337.0/1.349.9/1.357.7/1.3
Str. 25%25.9/1.329.9/1.331.3/1.347.5/1.340.7/1.322.8/1.327.7/1.320.1/1.319.5/1.364.5/1.389.1/1.344.0/1.39.0/1.357.2/1.353.4/1.362.3/1.3
Pyr. 10%29.0/1.337.7/1.348.6/1.355.5/1.344.7/1.327.4/1.325.7/1.322.8/1.318.0/1.355.0/1.385.4/1.345.2/1.39.0/1.3100.0/1.356.5/1.363.5/1.3
Pyr. 25%29.9/1.341.5/1.349.3/1.356.9/1.345.6/1.329.5/1.328.1/1.323.2/1.321.5/1.367.0/1.387.0/1.346.6/1.39.0/1.3100.0/1.360.3/1.363.9/1.3
Quest29.0/0.943.7/0.952.3/0.957.4/0.946.3/0.928.9/0.933.1/0.923.4/0.923.4/0.972.0/0.989.6/0.945.9/0.97.5/0.999.5/0.959.5/0.965.0/0.9
Double28.5/1.143.8/1.150.7/1.158.3/1.144.7/1.128.2/1.133.1/1.123.3/1.125.5/1.173.5/1.188.8/1.146.8/1.19.0/1.198.0/1.160.6/1.164.2/1.1
Our τ\tau.0128.6/1.244.8/1.251.1/1.258.3/1.245.6/1.229.5/1.233.4/1.224.1/1.224.2/1.273.5/1.288.9/1.247.0/1.29.0/1.2100.0/1.261.3/1.266.7/1.2
Our τ\tau.129.1/1.345.0/1.350.8/1.357.7/1.345.6/1.329.7/1.333.8/1.324.4/1.325.6/1.373.0/1.389.0/1.347.1/1.39.0/1.399.5/1.361.0/1.366.1/1.3
Our τ\tau.1 Q3228.7/1.245.0/1.251.1/1.258.4/1.246.1/1.229.7/1.233.8/1.224.5/1.225.5/1.273.5/1.288.9/1.246.9/1.29.0/1.2100.0/1.261.5/1.266.7/1.2

Table 8.

MethodNIAH-S1NIAH-S2NIAH-S3NIAH-MK1NIAH-MK2NIAH-MK3NIAH-MVNIAH-MQCWEFWEτ\tauQA-1QA-2
Llama Full100.0/1.0100.0/1.0100.0/1.090.0/1.070.0/1.055.0/1.093.8/1.0100.0/1.00.0/1.070.0/1.065.0/1.065.0/1.045.0/1.0
Snap 10%100.0/1.7100.0/1.770.0/1.790.0/1.760.0/1.730.0/1.788.8/1.797.5/1.70.5/1.761.7/1.760.0/1.765.0/1.745.0/1.7
Snap 25%100.0/1.5100.0/1.585.0/1.590.0/1.565.0/1.540.0/1.593.8/1.5100.0/1.50.0/1.565.0/1.559.0/1.565.0/1.545.0/1.5
Str. 10%5.0/1.720.0/1.75.0/1.710.0/1.710.0/1.720.0/1.710.0/1.710.0/1.70.5/1.780.0/1.79.0/1.750.0/1.725.0/1.7
Str. 25%35.0/1.545.0/1.520.0/1.540.0/1.530.0/1.525.0/1.525.0/1.525.0/1.51.0/1.576.7/1.525.0/1.565.0/1.535.0/1.5
Pyr. 10%100.0/1.7100.0/1.770.0/1.790.0/1.760.0/1.735.0/1.783.8/1.798.8/1.70.5/1.755.0/1.762.0/1.765.0/1.745.0/1.7
Pyr. 25%100.0/1.5100.0/1.585.0/1.590.0/1.560.0/1.550.0/1.593.8/1.5100.0/1.50.0/1.563.3/1.562.0/1.565.0/1.545.0/1.5
Quest100.0/1.1100.0/1.175.0/1.190.0/1.145.0/1.10.0/1.177.5/1.187.5/1.10.0/1.166.7/1.164.0/1.165.0/1.140.0/1.1
Double95.0/1.480.0/1.495.0/1.485.0/1.420.0/1.45.0/1.442.5/1.453.8/1.40.5/1.468.3/1.434.0/1.465.0/1.445.0/1.4
Our τ\tau.01100.0/1.6100.0/1.5100.0/1.595.0/1.655.0/1.525.0/1.690.0/1.597.5/1.50.0/1.670.0/1.670.0/1.665.0/1.545.0/1.5
Our τ\tau.1100.0/1.795.0/1.7100.0/1.790.0/1.730.0/1.75.0/1.771.2/1.786.2/1.70.0/1.760.0/1.761.0/1.770.0/1.745.0/1.7
Our τ\tau.1 Q32100.0/1.7100.0/1.6100.0/1.690.0/1.760.0/1.720.0/1.783.8/1.693.8/1.60.0/1.763.3/1.765.0/1.765.0/1.645.0/1.6
Qwen Full100.0/1.0100.0/1.090.0/1.095.0/1.045.0/1.010.0/1.073.8/1.085.0/1.038.0/1.051.7/1.083.0/1.060.0/1.025.0/1.0
Snap 10%100.0/1.395.0/1.30.0/1.375.0/1.30.0/1.30.0/1.320.0/1.372.5/1.335.5/1.343.3/1.382.0/1.355.0/1.320.0/1.3
Snap 25%100.0/1.3100.0/1.35.0/1.370.0/1.35.0/1.30.0/1.343.8/1.386.2/1.344.0/1.346.7/1.383.0/1.355.0/1.325.0/1.3
Str. 10%5.0/1.320.0/1.35.0/1.35.0/1.30.0/1.30.0/1.310.0/1.310.0/1.318.0/1.348.3/1.315.0/1.325.0/1.320.0/1.3
Str. 25%35.0/1.350.0/1.315.0/1.315.0/1.310.0/1.310.0/1.317.5/1.323.8/1.318.5/1.343.3/1.329.0/1.365.0/1.315.0/1.3
Pyr. 10%95.0/1.380.0/1.30.0/1.350.0/1.35.0/1.30.0/1.318.8/1.356.2/1.321.0/1.345.0/1.390.0/1.345.0/1.325.0/1.3
Pyr. 25%100.0/1.3100.0/1.30.0/1.365.0/1.35.0/1.30.0/1.336.2/1.3

Table 9. RULER per-task quality–latency comparison.

MethodKVL-1H-WPKVL-1H-2QKVL-POP-QAKVL-TF-WPInB. ChoiceInB. QALC-BANK-7LC-CLINCLC-MULTILC-TRECLC-TREC-FSQuAD-NVNIAH-MK2NIAH-MK3NIAH-MK1MS MARCO
Llama Full60.0/1.047.5/1.054.2/1.080.0/1.050.0/1.047.1/1.090.0/1.095.0/1.085.0/1.080.0/1.035.0/1.090.0/1.090.0/1.090.0/1.096.2/1.015.5/1.0
Llama Snap 10%61.7/1.744.2/1.755.0/1.783.3/1.750.0/1.646.8/1.690.0/1.695.0/1.685.0/1.680.0/1.635.0/1.675.0/1.595.0/1.535.0/1.595.0/1.633.3/1.0
Llama Snap 25%61.7/1.545.0/1.555.0/1.580.8/1.550.0/1.548.9/1.590.0/1.595.0/1.585.0/1.580.0/1.540.0/1.490.0/1.495.0/1.470.0/1.498.8/1.55.0/1.4
Llama Str. 10%67.1/1.535.8/1.753.3/1.778.3/1.750.0/1.634.8/1.690.0/1.690.0/1.685.0/1.680.0/1.620.0/1.610.0/1.550.0/1.550.0/1.510.0/1.628.8/1.5
Llama Str. 25%55.0/1.537.5/1.558.3/1.580.8/1.550.0/1.533.0/1.590.0/1.595.0/1.585.0/1.575.0/1.520.0/1.410.0/1.440.0/1.420.0/1.415.0/1.51.4/1.4
Llama Pyr. 10%60.0/1.545.8/1.555.0/1.583.3/1.550.0/1.648.1/1.690.0/1.695.0/1.685.0/1.680.0/1.625.0/1.680.0/1.595.0/1.545.0/1.595.7/1.621.1/1.5
Llama Pyr. 25%60.0/1.544.2/1.554.2/1.583.3/1.550.0/1.548.9/1.590.0/1.595.0/1.585.0/1.580.0/1.530.0/1.495.0/1.490.0/1.480.0/1.498.8/1.58.5/1.4
Llama Quest57.1/1.440.8/1.447.5/1.176.7/1.150.0/1.147.5/1.195.0/1.195.0/1.180.0/1.180.0/1.135.0/1.150.0/1.190.0/1.190.0/1.193.8/1.116.4/1.0
Llama Double58.3/1.446.7/1.455.0/1.484.2/1.450.0/1.447.0/1.490.0/1.495.0/1.485.0/1.485.0/1.430.0/1.425.0/1.460.0/1.415.0/1.457.5/1.461.2/1.4
Llama Our τ\tau.0160.0/1.547.5/1.555.8/1.483.3/1.550.0/1.447.8/1.495.0/1.495.0/1.485.0/1.480.0/1.425.0/1.490.0/1.495.0/1.440.0/1.496.2/1.414.2/1.3
Llama Our τ\tau.155.0/1.640.8/1.653.3/1.681.7/1.650.0/1.644.0/1.690.0/1.695.0/1.675.0/1.680.0/1.640.0/1.630.0/1.580.0/1.515.0/1.570.0/1.69.1/1.4
Llama Our τ\tau.1 Q3258.3/1.645.0/1.655.0/1.683.3/1.650.0/1.648.0/1.690.0/1.695.0/1.685.0/1.675.0/1.630.0/1.590.0/1.595.0/1.560.0/1.587.5/1.615.3/1.4

Table 10. HELMET per-task quality–latency comparison.

Risk Score Analysis and Ablations

∥o−o^∥2≤2∑C∈Cp^C(Vmax⁡cosh⁡(δCbound)−1∑C′∈Cp^C′cosh⁡(δC′bound)+VCtanh⁡(δCbound2)).(92)\lVert o-\hat{o}\rVert_2 \le2\sum_{C\in\mathcal{C}}\hat{p}_C\left(V_{\max}\frac{\cosh(\delta_C^{\mathrm{bound}})-1}{\sum_{C'\in\mathcal{C}}\hat{p}_{C'}\cosh(\delta_{C'}^{\mathrm{bound}})}+V_C\tanh\left(\frac{\delta_C^{\mathrm{bound}}}{2}\right)\right). \tag*{(92)}

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 p^C\hat{p}_C, and local distortion, characterized by

δC=max⁡i∈C∣qT(ki−kˉC)/d∣.\delta_C=\max_{i\in C}\left|\mathbf{q}^{\mathsf{T}}(\mathbf{k}_i-\bar{\mathbf{k}}_C)/\sqrt{d}\right|.

Computing δC\delta_C exactly requires accessing all keys within a cluster, so we replace it with an efficiently computable upper bound δCbound\delta_C^{\mathrm{bound}} in practice. This raises three questions:

  • How does a large δCbound\delta_C^{\mathrm{bound}} affect the risk score, and can the score be simplified?

  • How does using the exact, oracle δC\delta_C 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 δC\delta_C is large, cosh⁡(x)≈ex/2\cosh(x)\approx e^x/2 and tanh⁡(x)≈1\tanh(x)\approx1, so RCR_C simplifies to

R~C=Vmax⁡softmax⁡C(log⁡p^C+δC)+p^CVC.(93)\widetilde{R}_C=V_{\max}\operatorname{softmax}_C(\log\hat{p}_C+\delta_C)+\hat{p}_CV_C. \tag*{(93)}

Setting. Llama-3.1-8B, RULER-128K, Q=0Q=0, GQA-any, block size 32. We record every layer and query head of 26 prompts (2 per task), at τ=.01\tau=.01 and τ=.1\tau=.1. Same set is the fraction of KV heads for which R~C\widetilde{R}_C selects exactly the same clusters as RCR_C at the same τ\tau. Cluster Jaccard is ∣A∩B∣/∣A∪B∣|A\cap B|/|A\cup B| 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 2Vmax⁡2V_{\max}.

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, RCR_C and R^C\hat{R}_C select the same clusters on 96–98% of KV heads.

Simplified RCR_C does not invalidate RefineKV. RefineKV uses RCR_C only through the ranking it over clusters. The simplified form, keeps the intuition behind RefineKV: we want to jointly capture Importance p^C\hat{p}_C and Distortion δC\delta_C. Both signals enter jointly through softmax⁡C(log⁡p^C+δC)\operatorname{softmax}_C(\log\hat{p}_C+\delta_C), and a mass-weighted value term p^CVC\hat{p}_C V_C is added.

Table 11: Agreement between RCR_C and the simplified score R~C\widetilde{R}_C (Eq. (93)), and how often Eq. (4) exceeds the trivial bound 2Vmax⁡2V_{\max}. Llama-3.1-8B, RULER-128K, Q=0Q=0, GQA-any, block size 32, 26 prompts. δC\delta_C is reported as mean ±\pm std.

Deviation δC\delta_CδC\delta_CSame set (%) τ=.01\tau=.01Same set (%) τ=.1\tau=.1Cluster Jaccard τ=.01\tau=.01Cluster Jaccard τ=.1\tau=.1Eq. 4 >2Vmax⁡>2V_{\max} (%) τ=.01\tau=.01Eq. 4 >2Vmax⁡>2V_{\max} (%) τ=.1\tau=.1
Box21.92±5.3121.92 \pm5.3196.497.70.99990.999199.599.7
Diag. ellipsoid23.48±7.5923.48 \pm7.5996.497.70.99980.998299.799.8
Exact (oracle)4.17±1.794.17 \pm1.792.238.40.9180.9451.75.0

Table 11.

Selection with Oracle δ\delta 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 RCR_C with the box δCbound\delta_C^{\mathrm{bound}} (Ours) and change only the cluster ranking (Table 12). A tighter deviation ranks clusters better: at the low budget (τ=0.1\tau=0.1), the box summary improves on the ellipsoid by 5.3 points (Table 2), and the non-deployable oracle adds another 6.5; at τ=0.01\tau=0.01 the oracle comes within 1.4 points of Full Attention. In contrast, replacing RCR_C by its large-δ\delta simplification Vmax⁡softmax⁡C(log⁡p^C+δC)+p^CVCV_{\max}\operatorname{softmax}_C(\log\hat{p}_C+\delta_C)+\hat{p}_C V_C changes accuracy by at most 1.1 points, and no paired 95% CI excludes zero.

Table 12: Selection with oracle and simplified RCR_C at a fixed per-head token budget (Llama-3.1-8B-Instruct, RULER-128K, Q=0Q=0). Every row expands exactly as many tokens per KV head as RCR_C with the box δCbound\delta_C^{\mathrm{bound}} (Ours) selects at the same decoding state; only the cluster selection differs.

RCR_CδC\delta_Cτ=0.01\tau=0.01τ=0.1\tau=0.1
originalbox70.2762.58
simplifiedbox70.1962.67
originaloracle72.0069.06
simplifiedoracle72.1368.01
Full Attention73.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 ×\times 20 samples). We change nothing in the method: we use the same thresholds τ∈{0.01,0.1}\tau\in\{0.01, 0.1\}, ∣C∣=32\lvert C\rvert=32, the box summary, GQA-any and Q=0Q=0, 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). Δ\Delta 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 τ\tau on both models. Δ\Delta is relative to Full Attention, with 95% paired bootstrap CIs. Qwen2.5-7B numbers are those of the main results;

MethodQwen2.5-14B Acc.↑\uparrowQwen2.5-14B Δ\Delta [95% CI]Qwen2.5-14B TPOT (ms)↓\downarrowQwen2.5-14B Speedup↑\uparrowQwen2.5-7B Acc.↑\uparrowQwen2.5-7B Δ\DeltaQwen2.5-7B Speedup↑\uparrow
Full Attention72.96—40.981.00×\times65.88—1.00×\times
RefineKV (τ=0.01\tau=0.01)71.97−0.99 [−2.88, +1.04]29.561.39×\times65.28−0.601.19×\times
RefineKV (τ=0.1\tau=0.1)69.19−3.78 [−6.72, −0.91]26.491.55×\times60.35−5.531.27×\times
SnapKV (25%)68.44−4.52 [−7.50, −1.64]28.331.45×\times51.05−14.831.27×\times

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-8BQwen2.5-7B
RULERHELMETLongBenchRULERHELMETLongBench
Full AttentionQuality73.3769.1048.8665.8854.5749.34
RefineKV, τ=0.01\tau=0.01Quality70.1968.4348.8765.2854.4849.23
Speedup, CUDA1.56×1.43×1.55×1.19×1.13×1.18×
Speedup, eager1.49×1.37×1.49×1.15×1.10×1.15×
RefineKV, τ=0.1\tau=0.1Quality62.5856.8048.9560.3552.8349.13
Speedup, CUDA1.67×1.56×1.67×1.27×1.23×1.27×
Speedup, eager1.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 τ\tau 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.

LengthFull AttentionRefineKV (τ=0.01\tau=0.01)RefineKV (τ=0.1\tau=0.1)
Acc.TPOTAcc.Δ\DeltaExp.SpeedupAcc.Δ\DeltaExp.Speedup
16K89.0314.4689.22+0.1952.8%1.01×85.34−3.6910.9%1.05×
32K83.4115.8683.42+0.0132.8%1.07×75.12−8.296.7%1.14×
64K82.8018.7181.94−0.8618.7%1.24×74.74−8.064.6%1.33×
128K73.3524.4370.27−3.0811.2%1.56×62.58−10.774.0%1.67×

Table 15. RULER accuracy(Acc.), expanded fraction(Exp.) and decode speed versus input length (Llama-3.1-8B-Instruct, fixed τ\tau). Δ\Delta is relative to Full Attention.

At fixed τ\tau, the expanded fraction falls steadily with length. At fixed τ\tau, the expanded fraction falls steadily with length, from 52.8% at 16K to 11.2% at 128K for τ=0.01\tau=0.01, and from 10.9% to 4.0% for τ=0.1\tau=0.1. This is because τ\tau 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 τ=0.01\tau=0.01, 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 τ=0.01\tau=0.01) 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 τ=0.01\tau=0.01, the CI of Δ\Delta contains zero on four of six panels. The two exceptions are Qwen LongBench, whose CI barely excludes zero (−0.11-0.11 points), and Llama RULER (−3.17-3.17), whose loss is concentrated in two tasks.

τ=0.01\tau=0.01τ=0.1\tau=0.1
ModelBenchmarkFullAcc.Δ\Delta [95% CI]Acc.Δ\Delta [95% CI]
Llama-3.1-8BRULER73.3770.19−3.17-3.17 [−5.44-5.44, −1.02-1.02]62.58−10.79-10.79 [−13.67-13.67, −7.90-7.90]
Llama-3.1-8BHELMET69.1068.43−0.67-0.67 [−2.16-2.16, +0.77+0.77]56.80−12.29-12.29 [−15.34-15.34, −9.43-9.43]
Llama-3.1-8BLongBench48.8648.87+0.01+0.01 [−0.11-0.11, +0.13+0.13]48.95+0.09+0.09 [−0.15-0.15, +0.35+0.35]
Qwen2.5-7BRULER65.8865.28−0.60-0.60 [−2.23-2.23, +1.07+1.07]60.35−5.53-5.53 [−8.66-8.66, −2.47-2.47]
Qwen2.5-7BHELMET54.5754.48−0.09-0.09 [−1.68-1.68, +1.52+1.52]52.83−1.74-1.74 [−3.86-3.86, +0.39+0.39]
Qwen2.5-7BLongBench49.3449.23−0.11-0.11 [−0.23-0.23, −0.00-0.00]49.13−0.21-0.21 [−0.39-0.39, −0.04-0.04]

Table 16. RefineKV versus Full Attention, paired on identical samples. Δ\Delta is RefineKV minus Full Attention, with its 95% bootstrap CI.

References

  1. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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. [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.

Paper details

vlnc:W_nzynmazh
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents