Introduction
Large Language Models (LLMs) face a significant memory bottleneck during long-context generation: the Key-Value (KV) cache. This cache stores past token representations to avoid redundant computation but grows linearly with context length. KV-DISTILL introduces a novel framework to compress this cache, enabling models to handle massive contexts without exhausting GPU memory. Unlike previous "question-aware" methods that require knowing the query in advance, KV-DISTILL provides a "question-independent" compression, allowing a document to be compressed once and queried multiple times with minimal performance loss.
Methodology: Student-Teacher Distillation
KV-DISTILL treats context compression as a distillation problem where a "student" model (using a compressed cache) learns to mimic a "teacher" model (using the full cache).
The framework consists of three core components:
- State Selection: A feedforward network scores token importance, retaining only the top-$k$ tokens.
- Conditional Computation: Selected tokens are processed through trainable LoRA-adapted query and output matrices, while discarded tokens pass through frozen weights. This allows the model to "pack" information from discarded tokens into the retained representations.
- Next-Token Distillation: The model is trained using a combined forward and reverse KL divergence loss, balancing mode-seeking and mean-seeking behaviors to accurately match the teacher's output distribution.
Experimental Setup
The model was trained on a curated instruction dataset (Self-Instruct, P3, LongAlpaca, etc.) and evaluated across several benchmarks:
- Needle-In-a-Haystack: For exact retrieval.
- SQuAD: For extractive QA sensitivity.
- QuALITY & SQuALITY: For long-document QA and summarization.
- GovReport: For domain-specific fine-tuning.
Key Results and Insights
KV-DISTILL demonstrates remarkable robustness. In the Needle-in-a-Haystack test, it achieved near-perfect retrieval even after discarding 90% of the KV cache. On extractive QA (SQuAD), Llama-3 8B maintained 86.0% accuracy at 20% retention, compared to the 87.6% baseline.
Even at extreme compression rates, such as 0.1% retention on the QuALITY benchmark, the model exhibits "graceful semantic degradation." Instead of producing gibberish, it retains the general plot or gist of the text, though it may lose fine-grained details. This suggests the distillation process successfully teaches the model to build a reusable, general-purpose compressed representation.
Limitations and Future Work
While effective, the distillation process is computationally intensive. Performance also varies across different model architectures. Future work aims to scale KV-DISTILL to 128k context lengths (e.g., for Llama-3.1) and explore more efficient scoring functions and architectural designs.
Summary updated