LazyAttention: 高效检索增强生成中的延迟位置编码
LazyAttention: Efficient Retrieval-Augmented Generation with Deferred Positional Encoding
AI总结:
针对检索增强生成中KV缓存位置编码复用性差的问题,提出LazyAttention机制,通过核化延迟位置编码实现零拷贝、位置无关的KV重用,显著降低首令牌延迟并提升推理吞吐量。
摘要:
键值(KV)缓存通过重用已生成令牌的过去计算来加速大型语言模型(LLM)的推理。在长上下文应用(如检索增强生成(RAG)和上下文学习(ICL))中,其重要性更加凸显。然而,传统的KV缓存将位置信息直接嵌入缓存中,限制了其可重用性。现有解决方案要么将重用限制为前缀,要么需要昂贵的内存物化来进行位置重新编码。我们引入了LazyAttention,一种新颖的注意力机制,它通过核化延迟位置编码来实现零拷贝、位置无关的KV重用。通过在注意力内核中动态调整位置编码,LazyAttention解决了物化瓶颈,使得单个物理KV副本能够服务于任意位置的多个逻辑请求。利用为预填充和解码定制的注意力内核,我们的系统实现了显著的效率提升:在偏斜的文档分布下,与最先进的Block-Attention相比,首令牌延迟(TTFT)降低了1.37倍,推理吞吐量提高了1.40倍,同时保持了可比的输出质量。
英文摘要:
Key-value (KV) caching accelerates inference of large language models (LLMs) by reusing past computations for generated tokens. Its importance becomes even greater in long-context applications such as retrieval-augmented generation (RAG) and in-context learning (ICL). However, conventional KV caching embeds positional information directly into the cache, limiting its reusability. Existing solutions either restrict reuse to prefixes or require expensive memory materialization for positional re-encoding. We introduce LazyAttention, a novel attention mechanism that kernelizes deferred positional encoding to enable zero-copy, position-agnostic KV reuse. By adjusting positional encoding within attention kernels on-the-fly, LazyAttention resolves the materialization bottleneck, allowing a single physical KV copy to serve multiple logical requests at arbitrary positions. Leveraging attention kernels tailored for prefilling and decoding, our system achieves significant efficiency improvements: under skewed document distributions, it reduces time-to-first-token (TTFT) by 1.37$\times$ and increases inference throughput by 1.40$\times$ compared to the state-of-the-art Block-Attention, while maintaining comparable output quality.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。