arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.12491cs.CL
收藏

CAKE:基于层优先级的级联和自适应KV缓存淘汰

CAKE: Cascading and Adaptive KV Cache Eviction with Layer Preferences

Shanghai Jiao Tong University(上海交通大学);Ant Group(蚂蚁集团)

Ziran Qin, Yuchen Cao, Mingbao Lin, Wen Hu, Shixuan Fan, Ke Cheng, Weiyao Lin, Jianguo Li

AI总结:

CAKE通过级联和自适应机制优化KV缓存淘汰,提升低内存下的模型性能和解码效率。

摘要:

大型语言模型(LLMs)在处理长序列方面表现出色,这增加了对键值(KV)缓存的需求。尽管最近的KV缓存淘汰努力减轻了推理负担,但它们往往无法在具有不同注意力模式的层之间合理分配资源。在本文中,我们引入了级联和自适应KV缓存淘汰(CAKE),一种将KV缓存淘汰视为“蛋糕切割问题”的新方法。CAKE通过考虑空间和时间维度上的注意力动态来评估各层的特定偏好,相应地分配合理的缓存大小,并以级联方式进行内存限制管理。这种方法使缓存分配具有全局视角,能够自适应地在多样化的注意力机制之间分配资源,同时保持内存预算。CAKE还采用了一个新的淘汰指标,考虑了随时间变化的token重要性变化,解决了现有方法忽视时间动态性的局限。在LongBench和NeedleBench上的全面实验表明,CAKE仅使用3.2%的KV缓存即可保持模型性能,并在各种模型和内存限制下一致优于当前基线,特别是在低内存设置中。此外,CAKE在使用FlashAttention-2处理128K token上下文时,解码延迟比全缓存快超过10倍。我们的代码可在https://github.com/antgroup/cakekv上获得。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑