arXiv:2504.00970cs.CLcs.AI2025-04被引 9

通过句子语义分组压缩缓存,提升长文本生成效率

SentenceKV: Efficient LLM Inference via Sentence-Level Semantic KV Caching

  • 按句子语义相似性分组,用紧凑向量替代冗余键值对
  • 在长上下文场景下内存占用降低60%以上,首词生成速度更快
  • 适合需要高效处理长文档的问答与生成任务

大型语言模型在处理长上下文时面临显著的计算与内存挑战。推理过程中,高效管理存储中间激活值的键值(KV)缓存对降低内存开销、提升计算效率至关重要。传统基于标记的高效缓存方法忽略语义信息,将标记独立处理;而现有保留语义的缓存方法往往内存开销大、首词生成延迟高。为此,我们提出SentenceKV,一种新的句子级语义缓存方法,在预填充阶段根据句子级语义相似性分组标记,将句子表示压缩为简洁的语义向量直接存储于GPU,而单个键值对则卸载至CPU。解码阶段,通过检索与查询语义相似的句子级缓存条目生成标记,确保生成准确且避免加载无关数据,显著降低内存占用并维持稳定推理延迟,即使在极长上下文场景下亦然。在PG-19、LongBench和Needle-In-A-Haystack等基准上的广泛评估表明,SentenceKV在效率与内存使用上均显著优于当前最优方法,且不牺牲模型准确性。

原文摘要 · Abstract (English)

Large language models face significant computational and memory challenges when processing long contexts. During inference, efficient management of the key-value (KV) cache, which stores intermediate activations for autoregressive generation, is critical to reducing memory overhead and improving computational efficiency. Traditional token-level efficient KV caching methods overlook semantic information, treating tokens independently without considering their semantic relationships. Meanwhile, existing semantic-preserving KV cache management approaches often suffer from substantial memory usage and high time-to-first-token. To address these limitations, we propose SentenceKV, a novel sentence-level semantic KV caching approach designed to enhance inference efficiency while preserving semantic coherence. During prefilling, SentenceKV groups tokens based on sentence-level semantic similarity, compressing sentence representations into concise semantic vectors stored directly on the GPU, while individual KV pairs are offloaded to CPU. During decoding, SentenceKV generates tokens by selectively retrieving semantically relevant sentence-level KV entries, leveraging the semantic similarity between the prefilling-stage semantic vectors and decoding-stage queries. This ensures efficient and contextually accurate predictions, minimizing the loading of redundant or irrelevant data into GPU memory and significantly reducing memory overhead while maintaining stable inference latency, even for extremely long contexts. Extensive evaluations on benchmarks including PG-19, LongBench, and Needle-In-A-Haystack demonstrate that SentenceKV significantly outperforms state-of-the-art methods in both efficiency and memory usage, without compromising model accuracy.

长文本生成缓存优化语义压缩

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。