CAKE: Cascading and Adaptive KV Cache Eviction with Layer Preferences
Ziran Qin, Yuchen Cao, Mingbao Lin, Wen Hu, Shixuan Fan, Ke Cheng, Weiyao Lin, Jianguo Li
TL;DR
CAKE introduces a cascading and adaptive KV cache eviction framework for long-context LLMs. By quantifying per-layer attention dynamics through spatial dispersion and temporal shift, it allocates memory adaptively via a preference score and employs cascading prefilling to bound memory usage. An attention-shift tolerant eviction indicator preserves tokens with sustained importance and low volatility, while experiments on LongBench and NeedleBench show CAKE outperforms baselines and matches full-cache performance under modest budgets, with substantial reductions in memory and decoding latency. The approach is compatible with existing eviction methods and demonstrates strong generalization across architectures and tasks, offering a practical solution for memory-constrained inference at scale.
Abstract
Large language models (LLMs) excel at processing long sequences, boosting demand for key-value (KV) caching. While recent efforts to evict KV cache have alleviated the inference burden, they often fail to allocate resources rationally across layers with different attention patterns. In this paper, we introduce Cascading and Adaptive KV cache Eviction (CAKE), a novel approach that frames KV cache eviction as a "cake-slicing problem." CAKE assesses layer-specific preferences by considering attention dynamics in both spatial and temporal dimensions, allocates rational cache size for layers accordingly, and manages memory constraints in a cascading manner. This approach enables a global view of cache allocation, adaptively distributing resources across diverse attention mechanisms while maintaining memory budgets. CAKE also employs a new eviction indicator that considers the shifting importance of tokens over time, addressing limitations in existing methods that overlook temporal dynamics. Comprehensive experiments on LongBench and NeedleBench show that CAKE maintains model performance with only 3.2% of the KV cache and consistently outperforms current baselines across various models and memory constraints, particularly in low-memory settings. Additionally, CAKE achieves over 10x speedup in decoding latency compared to full cache when processing contexts of 128K tokens with FlashAttention-2. Our code is available at https://github.com/antgroup/cakekv.
