Skip to main content
Back

Soochow University's DapQ Cuts AI Memory Cache to 3% Without Losing Accuracy

A new KV cache compression method fakes future queries using position codes alone, hitting 99.5% Needle-in-a-Haystack accuracy at just 3% of the cache budget.

Pro

  • DapQ compresses the KV cache by simulating future decoding queries using only positional encodings, not generated content.
  • Authors find query vectors are dominated by position after RoPE, giving 2.1x higher similarity than content-based approximations.
  • Achieves 99.5% Needle-in-a-Haystack accuracy on LLaMA-3-8B with only 256 KV tokens retained, near full-cache.
  • Beats SnapKV by 58 points on Ruler S-NIAH-3 at a 512-token budget, and 6.75 points on LongBenchV2 Hard.
  • Prefill overhead and time-to-first-token are essentially identical to SnapKV across 8K to 128K contexts.
  • Code released at github.com/tianzhenxu/DapQ; paper tested on LLaMA-3, LLaMA-3.1, Qwen2.5, and Qwen3.

Long-context inference has a memory problem, and the KV cache sits at the center of it. A team from Soochow University has released DapQ, a KV cache eviction method that decides which tokens to keep by simulating the queries the model will produce during decoding, using nothing but positional encodings. The result is a lightweight framework that nearly matches full-cache performance while retaining as little as 3% of the cache.

The prefill-versus-decode mismatch

The KV cache stores the keys and values computed for every token during the prefill stage, so the model does not have to recompute attention for previous tokens on each new step. A key enabler of efficient inference is the KV cache mechanism, which significantly accelerates autoregressive decoding by reducing the computational complexity of self-attention from O(n^2) to O(n). The trade-off is memory: as context length grows, the cache balloons.

Existing eviction methods like SnapKV and PyramidKV score token importance using an observation window, typically the last 16 to 32 tokens of the prompt. The input-centric observation window is inherently misaligned with the dynamic query of actual decoding and relies solely on static prompt-based features, typically the last 16-32 tokens. Consequently, they fail to reflect the importance distribution determined by the output-side generation process, leading to misidentification of the critical tokens for decoding, particularly in complex or noisy contexts. In other words, the tokens the prompt cares about are not necessarily the tokens the generation will attend to.

The obvious fix would be to use the actual decoding queries to score importance, but those do not exist yet at prefill time. One prior attempt, LAQ++, generates pseudo responses to approximate them, but its two-stage pipeline creates a memory spike that defeats the purpose.

Position beats content

The DapQ authors ran a cosine-similarity study comparing fake queries to the ground-truth decoding queries under four conditions: same or different content, same or different positional IDs. Pseudo queries assigned correct future positional IDs but composed of completely irrelevant or nonsensical content exhibit strong cosine similarity (0.7238) to the actual target decoding queries. Conversely, queries with the identical semantic content but incorrect positional IDs fail to accurately approximate the target queries (0.3522 vs 1.0000). Maintaining correct positional alignment achieves 2.1x higher similarity than maintaining correct content alone.

The takeaway: after Rotary Position Embedding (RoPE) is applied, a query vector is dominated by where it sits in the sequence, not what token it represents. That means you can fabricate a decent stand-in for a future query using just its position ID.

How DapQ actually works

DapQ architecture diagram

The mechanism is refreshingly simple. For a prompt of length L, DapQ appends N synthetic tokens with position IDs [L, L+1, ..., L+N-1], corresponding to where the first N generated tokens will live. During the standard prefill pass, the model produces query vectors for these synthetic positions. Those pseudo queries are then used to score every prompt token by aggregated attention, the top-K keys and values are retained, and the synthetic segment is discarded before decoding begins from position L.

Two implementation details matter:

  • Pseudo queries are constructed by concatenating a small number of tokens from the beginning and the end of the input sequence (e.g., the first 4 and last 28 tokens, the first 2 and last 30 tokens). The beginning tokens, often high-frequency special tokens, possess stable and generalizable embeddings due to their extensive exposure during training; the ending tokens carry the most recent context.
  • The window size N is non-monotonic: too small leaves gaps in the importance estimate, too large dilutes the signal with speculative future positions that no longer resemble real decoding queries.

Benchmark numbers

DapQ was tested on LLaMA-3-8B-Instruct, LLaMA-3.1-8B-Instruct, Qwen2.5-7B-Instruct, and Qwen3-8B across LongBench, LongBenchV2, Ruler, HELMET, and Needle-in-a-Haystack. The headline result comes from NIAH:

DapQ NIAH heatmap at 99.46% accuracy

On LLaMA3-8B with a cache size of 256, DapQ achieves 99.5% accuracy, closely approaching full-cache performance. For context, SnapKV lands at 90.97% and H2O at 66.81% under the same budget. On the tougher Ruler S-NIAH-3 task with a 512-token budget, DapQ attains a notable 59.6% accuracy, substantially outperforming SnapKV (1.4%) and H2O (2.4%). On LongBenchV2's Hard split at a 64-token budget, DapQ improves over SnapKV by an absolute 6.75 points.

What it costs, and when it breaks

Efficiency is close to a wash with existing eviction methods. Time-to-first-token from 8K to 128K context length is within a few milliseconds of SnapKV, and throughput at batch sizes up to 50 tracks the other compression baselines. The overhead of the extra N synthetic tokens during prefill is essentially free.

The method has honest limitations. Semantic content still contributes something, and the paper notes that layer-wise sensitivity to positional versus semantic information varies, suggesting adaptive per-layer pseudo-query construction as future work. DapQ also assumes RoPE-style positional encodings, which is fine for LLaMA and Qwen but not universal.

Why this matters

The practical implication for anyone running long-context inference is that you can now retain a few percent of the KV cache and still get near-lossless retrieval on needle tasks, without training, without a second decoding pass, and without changing the model. It slots into any prefill-stage compression pipeline, and reference code is available on GitHub. For deployment scenarios where memory, not compute, is the bottleneck, a drop-in eviction upgrade that closes most of the gap to full attention is worth trying.