使用 Span Queries 优化缓存与注意力局部性
Using Span Queries to Optimize for Cache and Attention Locality
AI总结:
本文提出 span query 接口以泛化非聊天推理工作负载,通过自动优化改善 KV 缓存与注意力局部性,仅需修改 vLLM 492 行代码即可将 TTFT 降低 10-20 倍,并显著提升模型准确率。
摘要:
客户端正在超越聊天补全,现在包含了各种创新的推理时扩展和深度推理技术。与此同时,推理服务器仍然针对聊天补全进行了高度优化。先前的工作表明,如果推理服务器向这些非聊天用例演进,KV 缓存命中率可能会有大幅提升。然而,它们提供的解决方案同样仅针对单一用例 RAG 进行了优化。在本文中,我们引入了 span query 来泛化推理服务器的接口。我们证明了聊天、RAG、推理时扩展和智能体工作负载都可以表示为 span queries。我们展示了先前工作所假设的关键区别在于输入的顺序是否重要——即它们是否满足交换律?在聊天中,不满足。在 RAG 中,通常满足。本文引入了 span queries,它们是推理调用的表达式树,通过交换律约束链接在一起。我们描述了 span query 的语法和语义。我们展示了如何对它们进行自动优化以改善 KV 缓存局部性。我们展示了对 vLLM 的微小更改(仅影响 492 行代码)如何实现 span queries 的高性能执行。使用这一技术栈,我们证明了对于两种不同的非聊天用例,span queries 可以将 TTFT 降低 10 到 20 倍。最后,我们表明 span queries 也可以被优化以改善注意力局部性,从而避免所谓的“中间丢失”问题。我们证明了在 2b 参数模型上经过注意力优化的 span query 远超使用 8b 模型的普通推理服务器的准确率。
英文摘要:
Clients are evolving beyond chat completion, and now include a variety of innovative inference-time scaling and deep reasoning techniques. At the same time, inference servers remain heavily optimized for chat completion. Prior work has shown that large improvements to KV cache hit rate are possible if inference servers evolve towards these non-chat use cases. However, they offer solutions that are also optimized for a single use case, RAG. In this paper, we introduce the span query to generalize the interface to the inference server. We demonstrate that chat, RAG, inference-time scaling, and agentic workloads can all be expressed as span queries. We show how the critical distinction that had been assumed by prior work lies in whether the order of the inputs matter -- do they commute? In chat, they do not. In RAG, they often do. This paper introduces span queries, which are expression trees of inference calls, linked together with commutativity constraints. We describe span query syntax and semantics. We show how they can be automatically optimized to improve KV cache locality. We show how a small change to vLLM (affecting only 492 lines) can enable high-performance execution of span queries. Using this stack, we demonstrate that span queries can achieve 10-20x reductions in TTFT for two distinct non-chat use cases. Finally, we show that span queries can also be optimized to improve attention locality, so as to avoid the so-called lost-in-the-middle problem. We demonstrate that an attention-optimized span query on a 2b parameter model vastly outperforms the accuracy of a stock inference server using an 8b model.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。