通过分存键值缓存提升长文本大模型推理速度
ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM Inference
- 将低秩键缓存保留在GPU,值缓存移至CPU以降低内存占用
- 动态选择最小稀疏键值对,实现3.04倍吞吐提升
- 适合需要高并发长文本处理的部署场景
随着长上下文大语言模型(LLMs)的广泛应用,高效支持高吞吐推理的需求日益增长。然而,随着序列长度增加,键值(KV)缓存的内存占用和每次生成需访问缓存的问题导致长上下文推理吞吐量下降。尽管已有多种动态稀疏注意力方法在保持生成质量的同时加速推理,但它们或无法充分减少显存消耗,或因将KV缓存卸载至CPU而引入显著解码延迟。本文提出ShadowKV,一种高吞吐长上下文LLM推理系统,通过将低秩键缓存保留在GPU并卸载值缓存,有效降低内存开销,支持更大批量和更长序列。为最小化解码延迟,ShadowKV采用精确的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等模型的评估表明,其可在A100 GPU上支持高达6×更大的批量大小,吞吐量最高提升3.04×,且不牺牲精度,甚至超越假设无限显存下无限批量的性能。代码已开源。
原文摘要 · Abstract (English)
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 6$\times$ larger batch sizes and boost throughput by up to 3.04$\times$ 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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。