arXiv:2512.15550cs.CL2025-12

通过分两阶段检索提升长文本大模型推理效率

CTkvr: KV Cache Retrieval for Long-Context LLMs via Centroid then Token Indexing

  • 先用聚类中心粗筛,再精确定位关键激活值
  • 96K上下文下比基线快3~4倍,精度损失低于1%
  • 适合需要高效长文本处理的部署场景

大语言模型在多轮对话等长上下文场景中应用日益广泛,但长上下文带来显著的推理效率挑战,包括键值缓存(KV cache)内存开销大和过多内存访问导致的延迟增加。现有动态KV选择方法存在权衡:块级索引会因检索无关条目降低准确性,而令牌级索引则因低效检索机制引入高延迟。本文提出CTKVR,一种基于聚类中心后令牌索引的新型键值缓存检索方案。该方法基于一个关键观察:经过旋转位置编码(RoPE)后,位置相邻的查询向量具有高度相似性,并共享大部分前k个最高权重的KV缓存条目。CTKVR采用两阶段检索策略:在预填充阶段预先计算轻量级聚类中心用于粗粒度索引,随后进行令牌级细化以实现精确的KV检索。该方法兼顾了检索效率与准确性。为进一步提升性能,我们设计了基于CPU-GPU协同执行的优化系统,用于索引构建与搜索。实验表明,CTKVR在多个基准测试中表现优异,精度损失不足1%;在96K上下文长度下,对Llama-3-8B和Yi-9B分别实现3倍和4倍的吞吐量加速,适用于多种GPU硬件。

原文摘要 · Abstract (English)

Large language models (LLMs) are increasingly applied in long-context scenarios such as multi-turn conversations. However, long contexts pose significant challenges for inference efficiency, including high memory overhead from Key-Value (KV) cache and increased latency due to excessive memory accesses. Recent methods for dynamic KV selection struggle with trade-offs: block-level indexing degrades accuracy by retrieving irrelevant KV entries, while token-level indexing incurs high latency from inefficient retrieval mechanisms. In this paper, we propose CTKVR, a novel centroid-then-token KV retrieval scheme that addresses these limitations. CTKVR leverages a key observation: query vectors adjacent in position exhibit high similarity after Rotary Position Embedding (RoPE) and share most of their top-k KV cache entries. Based on this insight, CTKVR employs a two-stage retrieval strategy: lightweight centroids are precomputed during prefilling for centroid-grained indexing, followed by token-level refinement for precise KV retrieval. This approach balances retrieval efficiency and accuracy. To further enhance performance, we implement an optimized system for indexing construction and search using CPU-GPU co-execution. Experimentally, CTKVR achieves superior performance across multiple benchmarks with less than 1% accuracy degradation. Meanwhile, CTKVR delivers 3 times and 4 times throughput speedups on Llama-3-8B and Yi-9B at 96K context length across diverse GPU hardware.

长文本生成推理优化缓存检索

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