In-context KV-Cache Eviction for LLMs via Attention-Gate
Zihao Zeng, Bokai Lin, Tianqi Hou, Hao Zhang, Zhijie Deng
TL;DR
This work tackles the KV-Cache bottleneck in large language model inference by introducing Attention-Gate (AG), a lightweight, trainable module placed before each self-attention layer that, using global contextual information, outputs eviction flags to selectively prune KV states. AG leverages a reduced multi-head attention mechanism $\text{MHA}'$ to produce eviction decisions and a gating function to determine retention per token and head, enabling flexible, per-head, per-layer eviction with minimal overhead. Training uses an Eviction Loss to target a desired eviction rate and employs STE to handle the discrete gating, achieving strong results across continual pre-training and supervised fine-tuning benchmarks while delivering memory efficiency gains. The approach demonstrates robust, context-aware token eviction that can improve both inference efficiency and model performance, with practical implications for scaling LLMs to longer contexts. Overall, AG provides a scalable method to dynamically manage KV-Cache contents, preserving crucial tokens while discarding redundancies in a task- and context-sensitive manner.
Abstract
The KV-Cache technique has become the standard for the inference of large language models (LLMs). Yet, it is widely criticized that KV-Cache can become a bottleneck of the LLM inference system. This paper enables a novel dynamic KV-Cache eviction policy by injecting a lightweight module called Attention-Gate to the model. It accepts the global context as input and yields eviction flags for each token. The self-attention modules in the model proceed according to the flags and cache only a subset of the KV states for next token prediction. The Attention-Gates can yield various flags for different heads and layers and be easily tuned on top of a pre-trained LLM via continual pre-training or supervised fine-tuning. The computational and memory overhead introduced by Attention-Gates can be minimal. We empirically evaluate the proposed approach across multiple scenarios, showing that effective eviction of redundant tokens can not only improve efficiency but also enhance performance.
