Code for Focus-KV, a static head-wise KV-cache compression method that allocates more cache capacity to attention heads that are important for reasoning. Head importance is estimated offline on a reasoning probe set, and the resulting budgets remain fixed during decoding.
Do different attention heads contribute equally to a model's reasoning ability? We study the contribution of different attention heads to reasoning and arrive at a clear conclusion: the model's reasoning ability is highly concentrated in a small number of reasoning-critical heads. Suppressing these heads causes reasoning performance to drop sharply, whereas suppressing other heads is much less damaging.
We first measure the importance of each query head on a reasoning probe set. The profiling procedure is described in Importance Signal via Causal Ablation. As shown in Figure 2, reasoning-critical heads are sparse: most heads have importance values close to zero, and only a small number of heads show large importance. This indicates strong non-uniformity across heads.
We further measure how much these reasoning heads contribute to a downstream reasoning task. We evaluate with the R-KV algorithm on MATH-500 using a KV-cache budget of 4096. To disable a query head, we scale the output of that query head by
Figure 1. Reasoning Head Ablation. Disabling important heads causes a much larger accuracy drop and generates more tokens than disabling non-important heads. Results use R-KV on MATH-500 with a KV-cache budget of 4096.
As shown in Figure 1, the model's reasoning ability is highly sensitive to important heads. Compared with disabling non-important heads, disabling only a small fraction of important heads causes a much larger accuracy drop and leads the model to generate more tokens.
These results show two facts. First, our importance estimation method can identify reasoning heads. Second, the model's reasoning ability is concentrated in a small number of reasoning-critical heads. This finding drives the core design of Focus-KV: under a fixed budget, allocating more budget to reasoning heads can better preserve the model's reasoning ability.
Motivated by the observation that reasoning ability is concentrated in a sparse subset of attention heads, we propose Focus-KV, a static head-wise KV-cache compression algorithm. Focus-KV improves the model's reasoning ability by assigning non-uniform cache budgets across KV heads. Using the importance signal obtained from the probe set, Focus-KV uses a balanced allocation rule with an explicit budget floor and budget cap, ensuring that reasoning-critical heads receive more cache capacity while other heads still retain sufficient budget to keep their basic functionality. By shifting more cache budget toward reasoning-critical heads, Focus-KV improves reasoning performance under the same overall memory constraint.
Notation. We write
Focus-KV consists of four steps:
- Construct a high-quality probe set.
- Estimate the contribution of each query head to reasoning tasks.
- Convert head importance into a balanced KV-head budget allocation.
- Compress the KV cache using the allocated head-wise budgets, computed before inference and fixed during decoding.
We construct the probe set <think>...</think> reasoning trace and (b) the per-sample difficulty, defined as
Following recent long-CoT data-selection practice (Yang et al., 2025b), samples are ranked in descending order by reasoning trace length (
selects the top 100 samples: long, hard reasoning problems that can effectively reflect the model's reasoning ability.
Given the probe set, we estimate the importance of each query head by measuring how much the model's next-token prediction loss changes when that head is disabled. First, we perform a forward-pass evaluation on the probe set and compute the next-token cross-entropy loss, denoted as
This score has a direct causal interpretation: if disabling a head causes a large increase in next-token cross-entropy, then the head contributes substantially to the model's reasoning trajectory; if the loss change is close to zero, then this head is much less important for the reasoning task.
Figure 2. Importance Signal Visualization. Per-query-head importance measured on the reasoning probe set for Qwen3-14B, Qwen3-8B, and DeepSeek-R1-Distill-Llama-8B. Rows denote layers and columns denote query-head indices. Reasoning-critical heads are sparse: most heads have importance values close to zero, while only a small subset shows high importance.
For models using GQA, each KV head corresponds to
Then, for all KV heads, we clip negative importance scores to zero and normalize them to satisfy
Let
where
where
If some heads reach the cap, their extra budget is fixed to
If
The active set and remaining pool are then updated as
We repeat this cap-and-redistribute step until every uncapped head satisfies
At inference time, Focus-KV reuses the R-KV scoring step (Cai et al., 2026) to evict tokens. For each compression event, each KV head
where
Figure 3. Focus-KV compared with R-KV, ReasonAlloc, Ada-KV, and Full-KV on MATH-500 and AIME24. Results are reported as pass@1 based on 32 generated responses per question. Focus-KV improves accuracy over R-KV across the evaluated models, with particularly large gains under constrained KV-cache budgets.
Figure 4. Accuracy (%) of Focus-KV, R-KV, ReasonAlloc, and Full-KV on MuSR, LiveCodeBench, ZebraLogic, and SATBench using Qwen3-14B. These results evaluate reasoning performance beyond the mathematical domain used for head-importance profiling.
| Path | Contents |
|---|---|
compression/focuskv.py |
Importance loading, head-wise budget allocation, and variable-length per-head KV-cache compression. |
compression/focuskv_v2.py |
Rectangular-cache implementation with per-head padding for batched attention. |
modeling.py |
Attention and model-forward integration. |
monkeypatch.py |
Entry points for patching Llama, Qwen2, and Qwen3. |
utils.py |
Attention-score, similarity, and supporting utilities. |
probeset/find_reasoning_heads_multigpu.py |
Multi-GPU query-head ablation and importance profiling. |
probeset/probeset.jsonl |
Probe data containing 300 records; the probe-set construction procedure selects 100 samples for profiling. |
head_importance/ |
Precomputed query-head importance profiles for Qwen3-8B, Qwen3-14B, and DeepSeek-R1-Distill-Llama-8B. |
- Hugging Face (2025). Open R1: A Fully Open Reproduction of DeepSeek-R1.
- Cehao Yang et al. (2025b). Select2Reason: Efficient Instruction-Tuning Data Selection for Long-CoT Reasoning.
- Zefan Cai et al. (2026). R-KV: Redundancy-Aware KV Cache Compression for Reasoning Models.



