Manuscript Offprint

arXiv:2609.02029

HeadWiseKV: Budgeted Per-Head Cache Residency for Hybrid Long-Context Language Models

Renjie Xie, Juncheng Yang, Aoting Hu, Mingxi Zhang, Liyao Wu, Zheheng Hong, Wei Xu

Abstract

Long-context inference retains a growing key-value (KV) cache during decoding, which consumes substantial GPU memory and can reduce generation throughput. This bottleneck remains in hybrid language models because their residual global-attention layers can dominate context-dependent cache demand. We study how to allocate this state under an aggregate KV-residency budget. We introduce HeadWiseKV, a training-free framework that compresses the residual global KV caches of hybrid language models while preserving their native local, recurrent, and linear paths. It assigns each physical KV head a static, multilevel history window, making cache demand predictable before serving. We formulate this allocation as a restricted operational rate-distortion problem and propose SeqCalib as the core policy-generation algorithm in HeadWiseKV. SeqCalib processes layers in execution order and conditions each decision on the lower-layer policy used at deployment, thereby accounting for interactions across depth. A grouped-cache runtime materializes the selected policy as actual per-head KV residency rather than a mask over a full cache. We evaluate downstream quality across four hybrid long-context models and study physical residency and serving behavior on Qwen3.6-27B. HeadWiseKV retains near-Full-KV RULER and LoCoMo quality across the evaluated models. In the fixed-model systems study, it reduces sampled peak device memory by 8.59% at a 112K context length and extends the largest verified successful context from 114K to 161K.

1 Introduction

During long-context autoregressive inference, each full-attention layer stores key and value vectors for every cached token. This KV cache grows with context length and concurrency and can exhaust device memory (Zhang et al. 2023). Hybrid language models reduce the burden but do not eliminate it. Gemma 2 and Gemma 3 interleave global and local sliding-window attention (Gemma Team et al. 2024, 2025), whereas Qwen3-Next and Qwen3.6 interleave full or gated attention with recurrent Gated-DeltaNet blocks (Qwen Team 2025, 2026; Yang, Kautz, and Hatamizadeh 2025). Their remaining global blocks still retain histories that grow with the prompt. Hybridization therefore relocates the KV bottleneck rather than eliminating it: a small set of residual global layers can determine whether a long request fits in memory.

KV compression involves two distinct choices: when the retention policy is determined and how that policy is realized in memory. Prompt-dependent methods derive token or head decisions from the current request, observed attention, or online eviction state (Ge et al. 2024; Feng et al. 2025; Fu et al. 2025; Rehg 2024; Zhang et al. 2025; Qin et al. 2025). This adaptation can preserve isolated distant evidence that is important to a particular prompt. Its systems benefit, however, depends on the runtime. A logical sparse mask can reduce attention work while leaving the allocated KV cache unchanged. Compaction or eviction can reduce decoding-time residency, but a method that first constructs a full cache need not reduce the prefill memory peak. Online scoring, indexing, and KV movement also add request-time overhead, so sparse attention does not automatically imply higher end-to-end throughput.

Static policies make the complementary trade-off. Capacities fixed before prefill allow a runtime to allocate bounded storage directly, yielding predictable memory demand without request-time selection. The policy cannot inspect the current prompt, and therefore cannot identify which isolated past tokens a future query may need. Existing static methods mitigate this limitation by assigning full history to retrieval heads and compressed or streaming caches to other heads (Tang et al. 2025; Xiao et al. 2025). This binary split is regular to deploy but can be too coarse for hybrid models whose residual global heads require different amounts of history. Table 1 separates policy timing from physical cache realization and summarizes this trade-off.

Static allocation also creates a calibration problem across depth. Sensitivity varies by head and layer (Ge et al. 2024; Tang et al. 2025; Fu et al. 2025; Zhang et al. 2025; Wang, Cui, and Gan 2025; Cai et al. 2025; Wan et al. 2025; Qin et al. 2025). A common window can waste memory on tolerant

∗^{*}These authors contributed equally.

heads while truncating sensitive ones. Moreover, shortening an early cache changes the representations consumed by later layers. A higher layer calibrated under an all-full prefix may therefore see different inputs after deployment. A deployable static policy must choose fine-grained per-head capacities under the lower-layer decisions that will actually be active, and the runtime must realize those capacities as physical storage.

We introduce HeadWiseKV to meet these requirements. It assigns each residual global KV head one of several contiguous history lengths offline and keeps the resulting policy fixed during serving. This multilevel allocation is more expressive than binary head specialization while retaining a regular, prompt-independent layout. Its runtime stores only the selected histories, so the policy determines physical residency rather than logical access to an all-full cache. HeadWiseKV thus exchanges request-specific token selection for a fine-grained memory plan that is known before prefill.

HeadWiseKV connects three technical pieces in an offline-to-online pipeline. A structured residency model first defines the candidate history lengths and their storage cost. At the core of HeadWiseKV is SeqCalib, the offline algorithm that selects one history length for every configurable KV head. For each layer, SeqCalib keeps the previously selected lower-layer windows active and compares candidate pre-gate attention outputs with a conditional full-history reference under that same lower-layer policy. It chooses the lowest-cost codebook entry meeting a mean-cosine threshold. For the realized lower prefix, this finite search is stage-wise exact, not a guarantee of joint global optimality. Running SeqCalib over a finite set of thresholds produces static policy matrices spanning different residency costs. A deterministic budget selector then chooses among the feasible matrices. A grouped cache runtime loads the chosen matrix once and allocates the corresponding physical history for each head. In short, the residency model defines the choices, SeqCalib decides what to retain, and the runtime makes that decision real. None of these steps requires retraining or architectural changes. We cast the finite allocation as a restricted operational rate distortion problem (Shannon 1959; Cover and Thomas 2006). Its stage-wise guarantee does not establish globally optimal joint allocation or downstream quality.

Figure 1 summarizes the central advantage of HeadWiseKV: it lowers device-memory demand and supports longer contexts while preserving long-context quality. On Qwen3.6-27B (Qwen Team 2026), HeadWiseKV reduces sampled peak device memory by 8.59% at 112K tokens and increases the largest verified successful context from 114K to 161K, while retaining near-Full-KV performance on RULER and LoCoMo. The systems and quality panels report separately recorded operating points; full protocols and results appear in Section 4.

Figure

Figure 1: Qwen3.6-27B memory, capacity, and quality summary. HeadWiseKV lowers sampled peak device memory and expands the verified context range while preserving long-context quality. Panel (a) combines matched memory measurements with independent adjacent-grid capacity brackets; panel (b) reports recorded RULER and LoCoMo scores. The systems and quality panels use separately recorded τ=.995\tau = .995 operating points and do not form a joint quality–systems result.

Our contributions are:

  • a budgeted physical-residency formulation for the residual global KV heads of hybrid models, together with an analysis motivating nonuniform allocation and deployment-conditioned calibration;
  • HeadWiseKV and its prefix-conditioned SeqCalib algorithm, which construct static, multilevel per-head suffix policies under a prescribed KV-residency budget; and
  • a grouped physical per-head cache runtime that materializes the selected policy as actual cache residency, together with an evaluation across model families, compression budgets, and long-context workloads.

References (46)

  • $τ^2$-Bench: Evaluating Conversational Agents in a Dual-Control Environment
  • PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funneling
  • A.; and Weissman, T. 2014
  • M.; and Thomas, J. A. 2006
  • Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inference
  • Not All Heads Matter: A Head-Level KV Cache Compression Method with Integrated Retrieval and Reasoning
  • Model Tells You What to Discard: Adaptive KV Cache Compression for LLMs
  • Gemma 3 Technical Report
  • Gemma 2: Improving Open Language Models at a Practical Size
  • KVQuant: Towards 10 Million Context Length LLM Inference with KV Cache Quantization
  • RULER: What's
  • Efficient Memory Management for Large Language Model Serving with PagedAttention
  • SnapKV: LLM Knows What You are Looking for Before Generation
  • Scissorhands: Exploiting the Persistence of Importance Hypothesis for LLM KV Cache Compression at Test Time
  • KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
  • Evaluating Very Long-Term Conversational Memory of LLM Agents
  • Pointer Sentinel Mixture Models
  • vAttention: Dynamic Memory Management for Serving LLMs without PagedAttention
  • CAKE: Cascading and Adaptive KV Cache Eviction with Layer Preferences
  • KV-Compress: Paged KV-Cache Compression with Variable Compression Rates per Attention Head (opens arXiv in a new tab)
  • RazorAttention: Efficient KV Cache Compression Through Retrieval Heads
  • QUEST: Query-Aware Sparsity for Efficient Long-Context LLM Inference
  • D2O: Dynamic Discriminative Operations for Efficient Long-Context Inference of Large Language Models
  • LLMs Know What to Drop: Self-Attention Guided KV Cache Eviction for Efficient Long-Context Inference (opens arXiv in a new tab)
  • SqueezeAttention: 2D Management of KV-Cache in LLM Inference via Layer-wise Optimal Budget
  • LongMemEval: Benchmarking Chat Assistants on Long-Term Interactive Memory
  • TokenSelect: Efficient Long-Context Inference and Length Extrapolation for LLMs via Dynamic Token-Level KV Cache Selection
  • InfLLM: Training-Free Long-Context Extrapolation for LLMs with an Efficient Context Memory
  • DuoAttention: Efficient Long-Context LLM Inference with Retrieval and Streaming Heads
  • Efficient Streaming Language Models with Attention Sinks
  • PyramidInfer: Pyramid KV Cache Compression for High-throughput LLM Inference
  • Gated Delta Networks: Improving Mamba2 with Delta Rule
  • $τ$-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains
  • DiffKV: Differentiated Memory Management for Large Language Models with Parallel KV Compaction
  • H $_{2}$O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models
  • The case $m_w = 0$ is exact, while a nonempty suffix containing a finite unmasked logit ensures $m_w < 1$
  • A fixed suffix can therefore produce different local deviations across heads
  • Suppose $T_b$ is $L_b$-Lipschitz on $\mathcal{X}_b$, for finite $L_b \geq 0$, and assume
  • For $\epsilon_{cos} = 10^{-12}$, define
  • (12), and abbreviate
  • Conditional on the realized lower-layer prefix, the vector of windows selected at each layer has minimum nominal layer cost among same-layer choices satisfying all local similarity floors
  • If a shared window $w \in \mathcal{W}$ satisfies
  • The matrix determines its rate, while $\tau_g,\widehat{\Phi}_g$, and $g$ identify the calibration operating point used for offline selection; deployment uses the chosen matrix
  • Let $Z_{a,t} = g_a(X_t, S_t)$ be the state obtained by rerunning policy $a$
  • Abbreviate $(X, S, Z_{a}) = (X_{J}, S_{J}, Z_{a,J})$, and define
  • This decomposition interprets the ideal objective; SeqCalib instead uses the local activation criterion in Eq