KV-Distill: Nearly Lossless Learnable Context Compression for LLMs
About
Sequence-to-sequence tasks often benefit from long contexts, but the quadratic complexity of self-attention in standard Transformers renders this non-trivial. During generation, temporary representations -stored in the so-called KV cache-account for a large portion of GPU memory usage and scale linearly with context length. We introduce KV-Distill, a Transformer compression framework that distills long context KV caches into significantly shorter representations in a question-independent fashion. KV-Distill can be trained as a parameter-efficient adaptor for pretrained models, and enables the compression of arbitrary spans of a context while preserving pre-trained model capabilities. We treat a compressed-uncompressed cache as a student-teacher pairing and apply a KL-type divergence to match the generated outputs. KV-Distill outperforms other compression techniques in worst-case extractive tasks and approaches uncompressed performance in long context question answering and summarization, and it can be fine-tuned on domain-specific contexts to reduce lengths by up to 99% while preserving downstream performance. We demonstrate the generalizability of KV-Distill across various model sizes and architectures.
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Multiple-Choice Questions | Four-domain MCQ (test) | Accuracy65.3 | 43 | |
| Free-form summarization | HELMET multi_lexsum | Utilization85.5 | 15 | |
| Long-context evaluation | RULER 128k Zero-shot transfer | Accuracy (RULER 128k Zero-shot)22 | 12 | |
| Long-context evaluation | RULER 128k (matched-train holdout) | Accuracy20.3 | 12 | |
| Long-context evaluation | RULER 32k Zero-shot transfer | Accuracy24.1 | 12 | |
| Long-context evaluation | RULER 64k Zero-shot transfer | Accuracy21.8 | 12 | |
| Long-context evaluation | RULER 32k (matched-train holdout) | Accuracy26.5 | 12 | |
| Long-context evaluation | RULER 64k (matched-train holdout) | Accuracy21.9 | 12 | |
| Free-form summarization | LongBench V1 | Overall Score53.4 | 2 | |
| Long-context evaluation | LongBench context-dependent transfer v2 | Score (32k Context)26 | 2 |