FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving
FlashPrefill V2通过引入均值校正项、优化稀疏注意力算子和支持分页KV缓存与连续批处理,显著提高了长上下文LLM服务的效率和准确性。
更新于 2026-10-07。作者:Qihang Fan、Huaibo Huang、Zhiying Wu、Bingning Wang、Ran He。
中文摘要
长上下文建模是大型语言模型的关键能力,然而注意力机制的二次复杂性仍然是一个关键的瓶颈,尤其是在计算密集型的预填充阶段。我们之前的工作,FlashPrefill,通过即时模式发现和基于最大值的动态阈值来减轻这种成本;然而,它仍然是一个算法原型,距离实际部署还有很长的路要走。在这篇论文中,我们介绍了FlashPrefill V2,它从原型向实用长上下文服务发展,从三个维度进行了演进。首先,我们引入了一个均值校正项,它有效地抑制了近似误差,即使在极端稀疏水平下也能使性能下降可控。其次,我们重新设计了稀疏注意力算子,采用PackGQA内存访问、warp专业化以及pingpong流水线,完全与最新的FlashAttention-3/4实现相一致,并支持FP8推理以满足实际的量化需求。第三,FlashPrefill V2原生支持分页KV缓存和连续批处理,允许其作为注意力后端在现代推理框架如SGLang中集成。在NVIDIA H20 GPU(最广泛部署的推理加速器之一)上的广泛评估表明,FlashPrefill V2在FP8和BF16精度下,在128K上下文长度下分别比FlashAttention-2快47.26倍和27.19倍,在FP8下,相较于与FA3/4对齐的密集基线,仍实现了30.49倍的速度提升。
英文摘要
Long-context modeling is a pivotal capability for Large Language Models, yet the quadratic complexity of attention remains a critical bottleneck, particularly during the compute-intensive prefilling phase. Our previous work, FlashPrefill, mitigates this cost through instantaneous pattern discovery and max-based dynamic thresholding; however, it remains an algorithmic prototype that is still distant from production deployment. In this paper, we present FlashPrefill V2, which evolves FlashPrefill from a prototype toward practical long-context serving along three dimensions. First, we introduce a mean correction term that effectively suppresses the approximation error, keeping performance degradation manageable even at extreme sparsity levels. Second, we redesign the sparse attention operator with PackGQA memory access, warp specialization, and pingpong pipelining, fully aligning with the latest FlashAttention-3/4 implementations and supporting FP8 inference to meet practical quantization requirements. Third, FlashPrefill V2 natively supports paged KV cache and continuous batching, allowing integration as an attention backend in modern inference frameworks such as SGLang. Extensive evaluations on NVIDIA H20 GPUs---among the most widely deployed inference accelerators---demonstrate that FlashPrefill V2 delivers up to 47.26x and 27.19x speedups over FlashAttention-2 at 128K context length under FP8 and BF16 precision, respectively, and, in FP8, still achieves a 30.49x speedup against an FA3/4-aligned dense baseline.
解读
一句话总结
FlashPrefill V2通过引入均值校正项、优化稀疏注意力算子和支持分页KV缓存与连续批处理,显著提高了长上下文LLM服务的效率和准确性。
问题1:这篇论文想要解决什么具体问题?
- 问题背景:长上下文建模对大型语言模型至关重要,但自注意力的高二次复杂性在计算密集型的预填充阶段成为一个瓶颈。
- 现有方案不足:现有的稀疏注意力机制在极端稀疏度下准确性下降不可控,且与最新密集实现相比效率较低,且不兼容现代服务框架。
- 研究目标:提出FlashPrefill V2,以实现高效的、可部署的长上下文LLM服务。
问题2:论文的核心创新点是什么?
- 技术创新:引入均值校正项以抑制近似误差,并优化稀疏注意力算子以支持FP8推理。
- 方法改进:重新设计稀疏注意力算子以支持PackGQA内存访问、warp专用和pingpong流水线,并与SGLang等现代服务框架兼容。
- 优势:提高准确性并实现显著的性能提升,尤其是在长上下文场景中。
问题3:实验结果如何验证了方法的有效性?
- 关键实验:在NVIDIA H20 GPU上进行的广泛评估。
- 性能提升:在128K上下文长度下,FP8和BF16精度分别实现47.26倍和27.19倍的速度提升。
- 对比结果:与FlashAttention-2相比,FP8和BF16精度分别实现47.26倍和27.19倍的速度提升,与FA3/4对齐的密集基线相比,FP8实现30.49倍的速度提升。
问题4:这个研究的实际应用价值是什么?
- 应用场景:长上下文LLM服务,如问答、文本摘要和代码生成。
- 实施建议:作为SGLang等现代服务框架的注意力后端。
- 局限与展望:进一步优化算法以支持更广泛的硬件和模型架构。