arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.07011cs.LGcs.CLcs.PF
收藏

块稀疏Flash注意力

Block Sparse Flash Attention

Technion -- Israel Institute of Technology, Haifa, Israel(技术离子-以色列理工学院, 海法, 以色列);Intel -- Habana Labs, Tel Aviv, Israel(英特尔 -- Habana实验室, 特拉维夫, 以色列)

Daniel Ohayon, Itay Lamprecht, Itay Hubara, Israel Cohen, Daniel Soudry, Noam Elata

AI总结:

块稀疏Flash注意力通过精确计算查询-键相似性,提升长上下文推理效率并保持高准确性。

摘要:

现代大型语言模型越来越多地需要长上下文来进行推理和多文档任务,但注意力的二次复杂度造成了严重的计算瓶颈。我们提出了块稀疏Flash注意力(BSFA),这是一种可直接替换的加速方法,能够在保持模型质量的同时加速长上下文推理。与在计算得分前预测重要性的方法不同,BSFA计算精确的查询-键相似性,以选择每个查询的最重要作用块。通过将每个块的最大分数与校准阈值进行比较,我们跳过了约50%的计算和内存传输,用于修剪的块。我们的无训练方法只需在小数据集上进行一次阈值校准即可学习每层和每头注意力分数分布。我们提供了一个CUDA内核实现,可以作为FlashAttention的直接替换。在Llama-3.1-8B上,BSFA在现实推理基准测试中实现了高达1.10倍的速度提升,在针尖在海中检索任务中实现了高达1.24倍的速度提升,同时保持超过99%的基线准确性,某些配置甚至通过聚焦最相关的内容提高了准确性,显著优于现有的稀疏注意力方法。实现可在https://github.com/Danielohayon/Block-Sparse-Flash-Attention上获得。

英文摘要:

Modern large language models increasingly require long contexts for reasoning and multi-document tasks, but attention's quadratic complexity creates a severe computational bottleneck. We present Block Sparse Flash Attention (BSFA), a drop-in replacement that accelerates long-context inference while preserving model quality. Unlike methods that predict importance before computing scores, BSFA computes exact query-key similarities to select the top-k most important value blocks for each query. By comparing per-block maximum scores against calibrated thresholds, we skip approximately 50% of the computation and memory transfers for pruned blocks. Our training-free approach requires only a one-time threshold calibration on a small dataset to learn the per-layer and per-head attention score distributions. We provide a CUDA kernel implementation that can be used as a drop-in replacement for FlashAttention. On Llama-3.1-8B, BSFA achieves up to 1.13x end-to-end speedup on LongBench with only a 1.1% accuracy drop, and up to 1.24x on Needle-in-a-Haystack retrieval at a 1% accuracy drop. The attention kernel itself accelerates by up to 1.38x. We compare BSFA against five recent sparse attention baselines (SpargeAttention, MInference, FlexPrefill, XAttention, and BLASST), and verify the method on Qwen2.5-7B and on A6000 and H100 GPUs. The implementation is available at https://github.com/Danielohayon/Block-Sparse-Flash-Attention.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑