Locret: Enhancing Eviction in Long-Context LLM Inference with Trained Retaining Heads on Consumer-Grade Devices
Yuxiang Huang, Binhang Yuan, Xu Han, Chaojun Xiao, Zhiyuan Liu
TL;DR
Locret addresses the challenge of long-context inference on consumer-grade devices by introducing a lightweight, training-based KV cache eviction policy realized through trainable retaining heads that predict a causal importance score (CIS) for each KV unit. The framework integrates with a chunked prefill pipeline, using stabilizers to preserve local continuity and enable memory budgets to be respected during streaming input. A query-aware variant, Locret-Q, extends the approach to query-driven tasks, achieving faster prefill and robust performance on benchmarks like RULER. Across Phi-3-mini-128K and Llama-3.1-8B-instruct, Locret demonstrates substantial KV cache compression (up to $20\times$) with minimal quality loss, enabling up to 128K+ context on a single 4090 GPU and showing strong practicality for democratizing long-context LLM use on consumer hardware.
Abstract
Scaling the input context length of a large language model (LLM) incurs a significant increase in computation cost and memory footprint to maintain the attention key-value (KV) cache. Existing KV cache compression methods suffer from inefficient compression strategies and limited memory reduction effects, making it difficult for LLMs to conduct long-context inference on consumer-grade devices, especially when inferring long-context stream input. Such obstacles prevent consumer-grade devices from supporting more complex applications, creating challenges for the democratization of LLMs. To overcome this, we propose Locret, the first framework to create an eviction policy compatible with chunked prefill. By evaluating the causal importance of KV cache units by learnable retaining heads, Locret enables precise eviction of cache units, facilitating efficient long-context inference. In our extensive empirical studies, Locret outperforms the recent popular and competitive approaches in terms of memory efficiency and generation quality -- Locret achieves up to 20x of KV cache compression ratio within less than 10% performance loss. Furthermore, Locret achieves 128K+ long-context inference on a single NVIDIA 4090 GPU without compromising generation quality and only costs <1 GPU hour of additional training.
