arXiv:2505.13109cs.LGcs.AI2025-05被引 14

通过算法系统协同优化,显著提升大模型长文本推理时的键值缓存检索效率。

FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference

  • 采用推测性检索将选择过程移出关键路径,配合细粒度修正保准确率。
  • 在多个模型和场景下实现近无损精度,最高提速13倍。
  • 适合追求高并发、低延迟长文本推理的部署场景。

大语言模型(LLMs)正广泛部署于日益增长的上下文窗口以支持复杂应用。然而,长上下文带来显著部署挑战,主要源于随上下文长度线性增长的键值缓存(KV cache)。现有压缩方法受限,丢弃法导致显著精度损失,检索法存在严重效率瓶颈。本文提出FreeKV,一种无需训练的算法-系统协同优化框架,在保持精度前提下提升KV检索效率。算法层面,引入推测性检索将键值选择与召回过程移出关键路径,并结合细粒度修正确保准确性;系统层面,采用跨CPU/GPU的混合键值布局消除碎片化数据传输,并利用双缓冲流式召回机制进一步提升效率,实现计算与召回的高效重叠、完全延迟隐藏,从而获得实际加速效果。实验表明,FreeKV在多种模型与场景下均实现近无损精度,相比当前最优检索方法最高提速13倍。代码已开源:https://github.com/sjtu-zhao-lab/FreeKV。

原文摘要 · Abstract (English)

Large language models (LLMs) are widely deployed with rapidly expanding context windows to support increasingly demanding applications. However, long contexts pose significant deployment challenges, primarily due to the KV cache whose size grows proportionally with context length. While KV cache compression methods have been proposed to address this issue, KV dropping methods incur considerable accuracy loss, and KV retrieval methods suffer from significant efficiency bottlenecks. We propose FreeKV, a training-free algorithm-system co-optimization framework to enhance KV retrieval efficiency while preserving accuracy. On the algorithm side, FreeKV introduces speculative retrieval to shift the KV selection and recall processes out of the critical path, combined with fine-grained correction to ensure accuracy. On the system side, FreeKV employs hybrid KV layouts across CPU and GPU memory to eliminate fragmented data transfers, and leverages double-buffered streamed recall to further improve efficiency, enabling effective overlap with computation, full latency hiding, and practical speedups from speculative recall. Experiments demonstrate that FreeKV achieves near-lossless accuracy across various scenarios and models, delivering up to a 13$\times$ speedup compared to SOTA KV retrieval methods. Code is available at https://github.com/sjtu-zhao-lab/FreeKV.

大模型推理键值缓存高效检索系统优化

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