Manuscript Offprint

arXiv:2610.36950

DCKV: Learned Transform Coding of the Prompt KV Cache in Hybrid Language Models

Egor Maximov, Aleksei Merkelov, Vasiliy Alekseev, Ivan Krivorotov, Valentin Beliaev, Nikita Arsenin, Dmitry Bocharov, Aleksei Goncharov

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

Abstract

Hybrid language models keep a key-value (KV) cache only in their few full-attention layers, but this cache is still the part of a prompt's state that grows with the prompt and that must be stored or moved to reuse it. We present DCKV, a differentiable codec for the KV cache and the first KV-cache codec that is trained end to end. Its transform, its quantizer and its entropy models, which are conditioned on the prompt tokens and on already decoded neighbouring positions, are optimized together against the frozen language model, both for the code length that the entropy models assign and for the change of the model's output. On Qwen3.5-2B, DCKV stores a compressed token in more than 55 times fewer bytes than bf16 at a loss of at most 1.8 points on three long-context benchmarks, and in more than 100 times fewer bytes at a loss of at most 3.6 points.

1 Introduction

Reusing the key-value (KV) cache of a long prompt saves its prefill, which dominates the time to the first token on long inputs. To reuse prompt caches, serving systems keep them outside GPU memory and move them between devices and machines [30, 31]. Because such a cache is written once and read one or more times, a codec for it can afford entropy coding. What matters is the number of stored bytes at a given answer quality [43].

Recent hybrid models interleave a few full-attention layers with linear-attention or state-space layers [28, 39]. In Qwen3.5-2B, 6 of the 24 layers use full attention, and the other 18 are Gated DeltaNet layers [46] with a recurrent state of fixed size, 9.84 MiB per request. Although the KV cache is small, 12,288 bytes per token in bf16, it is still the only part of the state that grows with the prompt, to 48 MiB at 4K tokens and 1.5 GiB at 128K. We judge a codec by the memory of a stored request, recurrent state included.

KV cache transform coding (KVTC) [43] decorrelates keys and values with PCA, allocates bits by dynamic programming and applies a general-purpose lossless coder. Its transform and its bit allocation minimize the reconstruction error of the cache and do not see the output of the model. Learned image and video codecs train the transform and the quantizer on a rate-distortion objective [4] and condition the entropy model on what the decoder already has [5, 18]. For a language model, the natural distortion is the change of its output distribution, which some methods that compress the cache for decoding already use to learn cache projections [29].

We present DCKV, a Differentiable Codec for the KV cache. It is a learned codec for the stored prompt cache of a hybrid model and the first KV-cache codec whose transform, quantizer and entropy models are trained end to end. Our contributions are:

• A codec with one joint transform for the keys and values of all attention layers, linear with a small nonlinear correction, with a learned quantization step for each component and GPU rANS coding, trained against the frozen model on the code length plus the KL divergence of the output ( §3\S3).

• Conditional entropy models that predict each code from the embedding of its token and from already decoded neighbouring tokens, trained together with the transform. With the correction they remove 12–16% of the bytes at the same quality; fitted in closed form to a codec that is already trained, they give a similar saving on RULER 4K without retraining ( §3.4\S3.4, §5.2\S5.2).

• An evaluation on Qwen3.5-2B with paired per-task comparisons and a memory accounting that separates the state of a request from the codec weights ( §4§4, §5§5). Over three rates, DCKV needs 72% fewer bytes than KVTC at equal score on RULER 4K and 62% fewer on LongBench.

At prompts of 4K to 11K tokens the recurrent state takes about three quarters of the memory of a stored request. A smaller payload then reduces the request memory by a much smaller fraction than the stored cache. At 32K tokens, where the payload of DCKV is more than a third of the request memory, DCKV scores 6.5 points higher than KVTC at about the same request memory ( §5.3§5.3).

References (16)