2024-10-30 · 进阶 · 机器学习 · 自然语言处理

ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM Inference

ShadowKV通过将低秩键缓存保留在GPU上,将值缓存卸载到CPU,并采用准确的键值选择策略,实现了高吞吐量长上下文LLM推理。

更新于 2025-02-16。作者:Hanshi Sun、Li-Wen Chang、Wenlei Bao、Size Zheng、Ningxin Zheng、Xin Liu、Harry Dong、Yuejie Chi、Beidi Chen。

中文摘要

随着长上下文大型语言模型(LLMs)的广泛应用,对高效支持高吞吐量推理的需求日益增长。然而,随着键值(KV)缓存随序列长度的增加而扩展,内存占用增加以及每个标记生成时都需要访问它,这在服务于长上下文LLMs时会导致吞吐量低下。尽管已经提出了各种动态稀疏注意力方法来加速推理同时保持生成质量,但它们要么未能充分减少GPU内存消耗,要么通过将KV缓存卸载到CPU而引入了显著的解码延迟。我们提出了ShadowKV,一个高吞吐量的长上下文LLM推理系统,它存储低秩键缓存并将值缓存卸载以减少更大批量和更长序列的内存占用。为了最小化解码延迟,ShadowKV采用了一种准确的KV选择策略,它实时重建最小稀疏KV对。通过在包括RULER、LongBench和Needle In A Haystack等广泛基准以及Llama-3.1-8B、Llama-3-8B-1M、GLM-4-9B-1M、Yi-9B-200K、Phi-3-Mini-128K和Qwen2-7B-128K等模型上评估ShadowKV,我们证明了它在A100 GPU上可以支持高达6倍更大的批大小,并将吞吐量提高高达3.04倍,而不会牺牲准确性,甚至在假设无限GPU内存的情况下,其性能甚至超过了无限批大小所能达到的性能。代码可在https://github.com/bytedance/ShadowKV获取。

英文摘要

With the widespread deployment of long-context large language models (LLMs), there has been a growing demand for efficient support of high-throughput inference. However, as the key-value (KV) cache expands with the sequence length, the increasing memory footprint and the need to access it for each token generation both result in low throughput when serving long-context LLMs. While various dynamic sparse attention methods have been proposed to speed up inference while maintaining generation quality, they either fail to sufficiently reduce GPU memory consumption or introduce significant decoding latency by offloading the KV cache to the CPU. We present ShadowKV, a high-throughput long-context LLM inference system that stores the low-rank key cache and offloads the value cache to reduce the memory footprint for larger batch sizes and longer sequences. To minimize decoding latency, ShadowKV employs an accurate KV selection strategy that reconstructs minimal sparse KV pairs on-the-fly. By evaluating ShadowKV on a broad range of benchmarks, including RULER, LongBench, and Needle In A Haystack, and models like Llama-3.1-8B, Llama-3-8B-1M, GLM-4-9B-1M, Yi-9B-200K, Phi-3-Mini-128K, and Qwen2-7B-128K, we demonstrate that it can support up to 6times larger batch sizes and boost throughput by up to 3.04times on an A100 GPU without sacrificing accuracy, even surpassing the performance achievable with infinite batch size under the assumption of infinite GPU memory. The code is available at https://github.com/bytedance/ShadowKV.

解读

一句话总结

ShadowKV通过将低秩键缓存保留在GPU上,将值缓存卸载到CPU,并采用准确的键值选择策略,实现了高吞吐量长上下文LLM推理。

问题1:这篇论文想要解决什么具体问题?

• 问题背景:随着长上下文LLMs的广泛应用,对高效推理支持的需求日益增长。然而,随着键值(KV)缓存的增长,内存占用增加和每个标记生成时访问缓存的需求导致在服务长上下文LLMs时吞吐量低。 • 现有方案不足:现有的动态稀疏注意力方法要么未能充分减少GPU内存消耗,要么通过将KV缓存卸载到CPU而引入显著的解码延迟。 • 研究目标:设计一个高吞吐量长上下文LLM推理系统,通过存储低秩键缓存和卸载值缓存来减少内存占用,同时通过准确的KV选择策略最小化解码延迟。

问题2:论文的核心创新点是什么?

• 技术创新:提出了一种将低秩键缓存保留在GPU上,将值缓存卸载到CPU的方法,并通过CUDA多流重叠恢复选定的键缓存与获取相应的值缓存,以减少解码延迟。 • 方法改进:开发了一种准确的KV选择方法,以最小的稀疏预算(1.56%)维持准确性,并通过存储少量异常块作为静态缓存来保持准确性。 • 优势:与现有方法相比,ShadowKV可以支持更大的批量大小,提高吞吐量,同时保持准确性。

问题3:实验结果如何验证了方法的有效性?

• 关键实验:在RULER、LongBench和Needle In A Haystack等基准测试中评估ShadowKV,并使用Llama-3.1-8B、Llama-3-8B-1M、GLM-4-9B-1M等模型。 • 性能提升:ShadowKV可以支持高达6倍更大的批量大小,并在A100 GPU上提高吞吐量高达3.04倍,而不会牺牲准确性。 • 对比结果:与基线方法相比,ShadowKV在吞吐量和准确性方面都有显著提升。

问题4:这个研究的实际应用价值是什么?

• 应用场景:适用于需要高吞吐量长上下文LLM推理的领域,如问答、信息检索和多文档处理。 • 实施建议:在部署时,应考虑模型的特性和应用场景,选择合适的键秩和块大小,以优化性能。 • 局限与展望:目前,ShadowKV主要针对Transformer架构的LLMs,未来可以扩展到其他架构。此外,可以通过探索更先进的压缩和卸载技术来进一步提高性能。

来源