arXiv:2412.10319cs.CLcs.LG2024-12ICLR被引 60

聚焦KV缓存全生命周期,评估长文本模型推理效率

SCBench: A KV Cache-Centric Analysis of Long-Context Methods

  • 从缓存生成、压缩、检索、加载四环节构建新评测框架
  • 发现子线性内存方法在多轮对话中表现差,稀疏编码更稳定
  • 适合关注大模型推理优化的工程师与研究者

长上下文大模型虽推动诸多应用,却带来计算与内存效率挑战。现有优化集中于KV缓存,但传统基准多仅测试单请求场景,忽略缓存在真实部署中的完整生命周期。尤其值得关注的是,KV缓存复用已被vLLM、SGLang及OpenAI、微软、谷歌、Anthropic等广泛采用。为此,我们提出SCBench(SharedContextBench),一个基于KV缓存视角的综合性评测基准,涵盖四个核心环节:1)KV缓存生成,2)压缩,3)检索,4)加载。SCBench使用含共享上下文的测试样本,覆盖12项任务与两种共享模式,涵盖字符串检索、语义检索、全局信息、多任务四类长上下文能力。我们在8个长上下文大模型上评估了八类方法,包括门控线性RNN、Mamba-Attention混合架构,以及稀疏注意力、缓存丢弃、量化、检索、加载、提示压缩等高效策略。结果表明:子线性内存方法在多轮场景下表现不佳;而具有O(n)内存和子O(n²)预填充计算的稀疏编码表现稳健;动态稀疏性生成的缓存表达力优于静态模式;混合架构中层级稀疏可降低内存消耗且保持高性能。此外,我们识别出长文本生成中注意力分布偏移问题。

原文摘要 · Abstract (English)

Long-context LLMs have enabled numerous downstream applications but also introduced significant challenges related to computational and memory efficiency. To address these challenges, optimizations for long-context inference have been developed, centered around the KV cache. However, existing benchmarks often evaluate in single-request, neglecting the full lifecycle of the KV cache in real-world use. This oversight is particularly critical, as KV cache reuse has become widely adopted in LLMs inference frameworks, such as vLLM and SGLang, as well as by LLM providers, including OpenAI, Microsoft, Google, and Anthropic. To address this gap, we introduce SCBench(SharedContextBench), a comprehensive benchmark for evaluating long-context methods from a KV cachecentric perspective: 1) KV cache generation, 2) KV cache compression, 3) KV cache retrieval, 4) KV cache loading. Specifically, SCBench uses test examples with shared context, ranging 12 tasks with two shared context modes, covering four categories of long-context capabilities: string retrieval, semantic retrieval, global information, and multi-task. With it, we provide an extensive KV cache-centric analysis of eight categories long-context solutions, including Gated Linear RNNs, Mamba-Attention hybrids, and efficient methods such as sparse attention, KV cache dropping, quantization, retrieval, loading, and prompt compression. The evaluation is conducted on 8 long-context LLMs. Our findings show that sub-O(n) memory methods suffer in multi-turn scenarios, while sparse encoding with O(n) memory and sub-O(n^2) pre-filling computation perform robustly. Dynamic sparsity yields more expressive KV caches than static patterns, and layer-level sparsity in hybrid architectures reduces memory usage with strong performance. Additionally, we identify attention distribution shift issues in long-generation scenarios. https://aka.ms/SCBench.

大模型推理KV缓存长文本生成

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