LServe: Efficient Long-sequence LLM Serving with Unified Sparse Attention
LServe通过统一稀疏注意力机制,有效加速了长序列LLM的服务,同时保持了长上下文准确性。
更新于 2026-11-29。作者:Shang Yang、Junxian Guo、Haotian Tang、Qinghao Hu、Guangxuan Xiao、Jiaming Tang、Yujun Lin、Zhijian Liu、Yao Lu、Song Han。
中文摘要
大型语言模型(LLMs)在处理长序列方面展现出惊人的潜力,然而,由于预填充阶段注意力的二次计算复杂性和解码阶段KV缓存的巨大内存占用,高效地服务于这些长上下文模型仍然具有挑战性。为了解决这些问题,我们引入了LServe,这是一个高效的系统,通过混合稀疏注意力加速长序列LLMs的服务。这种方法将预填充和解码注意力中的不同硬件友好型、结构化稀疏模式统一到一个框架中,通过块级跳过对不太重要的标记的计算。LServe展示了静态和动态稀疏在长上下文LLM注意力中的兼容性。这种设计通过结合这些优化实现了乘法加速。具体来说,我们在预填充和解码阶段将一半的注意力头转换为近乎免费的流式头部。此外,我们发现无论上下文长度如何,只需要常数个KV页面即可保留长上下文能力。然后,我们设计了一个分层KV页面选择策略,根据查询中心相似性动态修剪KV页面。平均而言,LServe将LLM预填充加速了高达2.9倍,解码加速了1.3-2.1倍,同时保持了长上下文的准确性。代码已发布在https://github.com/mit-han-lab/omniserve。
英文摘要
Large language models (LLMs) have shown remarkable potential in processing long sequences, yet efficiently serving these long-context models remains challenging due to the quadratic computational complexity of attention in the prefilling stage and the large memory footprint of the KV cache in the decoding stage. To address these issues, we introduce LServe, an efficient system that accelerates long-sequence LLM serving via hybrid sparse attention. This method unifies different hardware-friendly, structured sparsity patterns for both prefilling and decoding attention into a single framework, where computations on less important tokens are skipped block-wise. LServe demonstrates the compatibility of static and dynamic sparsity in long-context LLM attention. This design enables multiplicative speedups by combining these optimizations. Specifically, we convert half of the attention heads to nearly free streaming heads in both the prefilling and decoding stages. Additionally, we find that only a constant number of KV pages is required to preserve long-context capabilities, irrespective of context length. We then design a hierarchical KV page selection policy that dynamically prunes KV pages based on query-centric similarity. On average, LServe accelerates LLM prefilling by up to 2.9x and decoding by 1.3-2.1x over vLLM, maintaining long-context accuracy. Code is released at https://github.com/mit-han-lab/omniserve.
解读
一句话总结
LServe通过统一稀疏注意力机制,有效加速了长序列LLM的服务,同时保持了长上下文准确性。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:长序列LLM在处理长上下文时,由于注意力机制的二次计算复杂性和解码阶段的KV缓存大内存占用,导致服务效率低下。
- 现有方案不足:现有的解决方案主要集中在KV缓存量化和近似稀疏注意力,但它们要么没有降低计算量,要么在长上下文中牺牲了准确性,或者没有同时解决prefilling和decoding阶段的效率问题。
- 研究目标:提出LServe,一个高效的系统,通过混合稀疏注意力加速长序列LLM的服务。
问题2:论文的核心创新点是什么?
- 技术创新:引入了统一块稀疏注意力框架,结合了静态和动态稀疏性,以及KV缓存量化。
- 方法改进:通过将注意力头分为密集头和流式头,以及动态页选择策略,优化了prefilling和decoding阶段的效率。
- 优势:实现了prefilling速度提高2.9倍,decoding速度提高1.3-2.1倍,同时保持了长上下文准确性。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在Llama-3-8B、Minitron-4B和Llama-2-7B模型上,对长序列LLM进行基准测试。
- 性能提升:LServe在prefilling阶段速度提高了2.9倍,在decoding阶段速度提高了1.3-2.1倍。
- 对比结果:与vLLM、QServe、MInference和DuoAttention等基线方法相比,LServe在prefilling和decoding阶段都取得了显著的性能提升。
问题4:这个研究的实际应用价值是什么?
- 应用场景:适用于多轮对话、长文档分析、多模态理解和代码补全等长序列应用。
- 实施建议:将LServe集成到现有的LLM服务系统中,以优化长序列LLM的服务效率。
- 局限与展望:LServe在长上下文模型中展示了静态和动态稀疏性的兼容性,未来可以进一步探索更复杂的稀疏模式和优化策略。