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

XKV:面向长上下文大语言模型推理的个性化KV缓存内存缩减方法

XKV: Personalized KV Cache Memory Reduction for Long-Context LLM Inference

Northeastern University(东北大学);Guangzhou University(广州大学)

Weizhuo Li, Zhigang Wang, Yu Gu, Ge Yu

AI总结:

针对长上下文LLM推理中KV缓存内存占用过高的问题,本文提出XKV方法,通过量化不同层缓存对精度的影响,以个性化分层缓存分配的组合优化方案,实现了内存大幅缩减与效率、吞吐量的显著提升。

摘要:

近年来,生成式大语言模型(LLM)已在众多应用中取得显著成功。值得注意的是,其推理过程逐个生成输出token,会产生大量冗余计算。被广泛使用的KV-Cache(键值缓存)框架在时间复杂度与空间复杂度之间做出了权衡。然而,缓存数据会带来持续增长的内存需求,会快速耗尽GPU等现代加速器的有限内存容量,在长上下文推理任务中尤为明显。现有研究通过逐出部分对推理精度影响较小的缓存数据来降低内存消耗,但由于不同LLM网络层采用静态缓存分配策略,实际效果远未达到理想状态。本文观察到,不同层的缓存数据对精度的影响存在显著差异。我们量化了这种差异,并通过实验和理论验证了该结论。我们据此开展了正式分析,结果表明,以个性化方式为每一层定制缓存大小,可在保持精度相当的同时大幅缩减内存。我们将缓存分配建模为组合优化问题,并给出了全局最优解。具体而言,我们设计了一种基于轻量版LLM模型的小型采样推理方法,以快速捕捉层间差异,再将其输入个性化算法。在真实数据集上开展的大量实验表明,我们提出的方案可平均降低61.6%的KV缓存内存消耗,计算效率提升2.1倍,吞吐量最高提升5.5倍。

英文摘要:

Recently the generative Large Language Model (LLM) has achieved remarkable success in numerous applications. Notably its inference generates output tokens one-by-one, leading to many redundant computations. The widely-used KV-Cache framework makes a compromise between time and space complexities. However, caching data generates the increasingly growing memory demand, that can quickly exhaust the limited memory capacity of the modern accelerator like GPUs, particularly in long-context inference tasks. Existing studies reduce memory consumption by evicting some of cached data that have less important impact on inference accuracy. But the benefit in practice is far from ideal due to the static cache allocation across different LLM network layers. This paper observes that the layer-specific cached data have very different impacts on accuracy. We quantify this difference, and give experimental and theoretical validation. We accordingly make a formal analysis and shows that customizing the cache size for each layer in a personalized manner can yield a significant memory reduction, while still providing comparable accuracy. We simulate the cache allocation as a combinatorial optimization problem and give a global optimal solution. In particular, we devise a mini- and sampling-based inference over a lightweight variant of the LLM model, so as to quickly capture the difference and then feed it into the personalized algorithms. Extensive experiments on real-world datasets demonstrate that our proposals can reduce KV cache memory consumption by 61.6% on average, improve computational efficiency by 2.1x and then increase the throughput by up to 5.5x.

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

↑