arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.36520

Folding Attention Biases into Keys Makes Compacted KV Caches Run on Standard Kernels

Utkarsh Kanwat

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Attention Matching (AM) compacts a KV cache by keeping some keys per head, refitting their values and adding a bias to each kept key's logit. FlashAttention and vLLM's paged caches have no input for it. We fold the bias into the keys along one closed-form direction per head, fitted on context queries, giving a plain cache with AM's size and head dimension and the model's own query path; the output error is bounded by how far each query's projection on that direction is from 1. With equal per-head budgets, unmodified vLLM serves folded caches through a KV connector, matching Hugging Face's answers on all 51 Qwen3-4B questions and its greedy output on 180 of 200 Qwen3-14B LongBench samples. With equal budgets on QuALITY (Qwen3-1.7B, 4B, 8B, Llama-3.1-8B) and LongHealth (three Qwen3 models), the fold is within noise of AM's accuracy in 13 of 14 settings, with lower KL to the full cache than dropping the bias in all 12 where both ran. Under the published per-head budgets, on Qwen3-4B, its Instruct-2507 variant and Llama-3.1-8B, it is within noise of AM in 9 of 10, no longer beats dropping the bias in KL, and the two each win once in accuracy.

1 Introduction

A model answering questions about a long document holds a key and a value for every token in every layer. For Qwen3-4B in fp16 that is 144 KiB per token, and vLLM's KV pool on one T4 holds 4 requests over QuALITY prompts of 6,533 tokens on average, with 256 generated tokens each. Attention Matching (AM) [33] shrinks this cache once the document is read. Each head keeps a small subset of the keys and refits their values by least squares. A kept key now stands in for many dropped ones, so AM also adds a scalar bias βj\beta_j to its logit, q⋅kj/d+βjq \cdot k_j / \sqrt{d} + \beta_j, fitted so that the kept keys carry the attention mass of the full context. Later methods keep the bias, whether they learn part of the cache [8, 21] or apply AM to reasoning traces [16] and agent turns [17].

Serving systems have nowhere to put the bias. FlashAttention [10] and vLLM's paged caches [11] hold plain key and value tensors, PyTorch's flash backend rejects any additive mask, and prefix caches and KV transfer between engines move plain blocks. The obstacle is availability, not speed. A biased kernel costs little per call: AM reports a negligible change in attention runtime, ARC-KV measures its bias-aware path at 1.06 to 1.09 times the time of FlashAttention-2 [21], and our own timings agree (Section 6). Yet every engine serving the cache needs this second, biased path, written and tuned for each GPU and cache layout; paged and prefix caches, KV transfer and FlashAttention itself have none, and papers that keep a per-entry logit term name this as their deployment gap [8, 9, 19, 22]. Two plain caches exist today. An exact one adds a coordinate to every query and key, the rank-one case of FlashBias [26]: it changes the model's query path, and vLLM would store its keys and values at head dimension 136 with FlashAttention or 256 with

FlashInfer instead of 128 (Section 8). The other drops β\beta, as Still [19] and QREAM [4] do, and gives up the mass correction AM fits it for.

We keep the bias and move it into the keys. If a kept key moves to kj′=kj+βjduk_j' = k_j + \beta_j \sqrt{d} u for a direction uu, its logit becomes q⋅kj/d+βj(q⋅u)q \cdot k_j / \sqrt{d} + \beta_j (q \cdot u). The bias adds βj\beta_j for every query, the move adds βj(q⋅u)\beta_j (q \cdot u), and the two agree whenever q⋅u=1q \cdot u = 1. Prior work [2] uses this identity for queries known in advance. Future queries are not known, so we fit uu per head in closed form on the queries it produced while reading the context: q⋅uq \cdot u has mean 1 there, with, up to a small ridge, the smallest variance any such direction allows. The folded and biased outputs then differ by at most 32DV∣q⋅u−1∣\frac{3}{2} D_V |q \cdot u - 1|, where DVD_V is the largest distance between two attended values, and a value refit absorbs part of this error on those queries. Dropping β\beta from AM's cache is the fold with q⋅u=0q \cdot u = 0, so when the attended biases vary little the fold's error is, to first order, ∣q⋅u−1∣|q \cdot u - 1| times the error of dropping β\beta. The fold gives a plain cache the size of AM's, at the model's own head dimension and with its query path unchanged, so with equal budgets per head any kernel that runs an uncompacted cache runs it (Section 3.5). The fold removes the obstacle the bias poses. Per-head budgets pose a separate one, ragged per-head cache lengths, which AM's published schedule needs from the engine's memory manager whether or not β\beta is kept; we therefore serve equal budgets and measure per-head budgets for accuracy (Appendix A.3).

We contribute:

  • The fold. One closed-form direction per head turns a biased cache into a plain one with the same size, head dimension and query path, with a bound on the output error in terms of ∣q⋅u−1∣|q \cdot u - 1| and a first-order comparison with dropping the bias (Section 3).

• Accuracy. With equal budgets per head, on QuALITY with four models and LongHealth with three, the folded cache is within noise of AM's accuracy in 13 of 14 settings. Its KL to the full cache is lower than dropping β\beta in all 12 settings where both ran, beyond noise in 10; dropping β\beta leaves more questions with KL above 1 in 11 of 12, and in accuracy the two differ beyond noise once, by 4.5 points in the fold's favor (Section 5, Tables 2 and 3). Under the published per-head budgets it is within noise of AM in 9 of 10 settings and level with drop in KL (Appendix A.3). Section 5 and Appendix A.4 diagnose the two losses.

• Beyond AM. The fold applies structurally to any per-entry logit term that does not depend on the query, which a census finds in AM’s successors and in log-count merging (Table 7). It reproduces a capped log-count merged cache within noise on QuALITY and LongHealth and runs inside KV-Surgeon’s own pipeline [23] on two biased compactors with no detected loss (Section 5).

• Serving. Unmodified vLLM serves folded caches through a KV connector at the model’s own head dimension. With equal budgets per head, answers match Hugging Face on all 51 Qwen3-4B questions, and greedy output matches on 180 of 200 LongBench samples with Qwen3-14B; capacity and decode-speed runs with random weights extend to Qwen3-32B (Section 6).

References (29)