FlashPrefill V2:面向长上下文LLM服务的块稀疏预填充注意力

·

研究论文 · 2026/08/21

长上下文建模是大语言模型的关键能力,但注意力机制的二次复杂度仍是关键瓶颈,尤其在计算密集的预填充阶段。我们之前的工作 FlashPrefill 通过即时模式发现和基于最大值的动态阈值来缓解这一成本,但它仍是一个算法原型,距离生产部署尚远。本文提出 FlashPrefill V2,从三个维度将 FlashPrefill 从原型推向实用的长上下文服务。首先,引入均值修正项有效抑制近似误差,即使在极端稀疏度下也能保持性能下降可控。其次,通过 PackGQA 内存访问、warp 专用化和乒乓流水线重新设计稀疏注意力算子,完全对齐最新的 FlashAttention-3/4 实现,并支持 FP8 推理以满足实际量化需求。第三,FlashPrefill V2 原生支持分页 KV 缓存和连续批处理,可作为现代推理框架(如 SGLang)中的注意力后端集成。在 NVIDIA H20 GPU(最广泛部署的推理加速器之一)上的大量评估表明,FlashPrefill V2 在 128K 上下文长度下,FP8 和 BF16 精度下分别比 FlashAttention-2 实现高达 47.26 倍和 27.19 倍的加速,且在 FP8 下,与 FA3/4 对齐的密集基线相比仍实现 30.49 倍加速。

该论文将稀疏注意力从原型推进到生产级实现,解决了长上下文 LLM 服务中的关键性能瓶颈,提供了显著的加速比,并支持现代推理框架集成,对实际部署具有重要价值。

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.

阅读原文

参与讨论