arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2604.12798cs.LGcs.AI
收藏

VFA:通过全局最大值预计算缓解Flash Attention中的向量操作

VFA: Relieving Vector Operations in Flash Attention with Global Maximum Pre-computation

Huawei Technologies(华为技术)

Yupeng Sun, Yanzhao Li, Zhiqiang Zou, Bai Du, Zhiyuan Zhang, Hui Dong, Gaoyige Fan, Hui Wang

AI总结:

本文提出VFA,通过预计算全局最大值减少Flash Attention中的向量操作,提升计算效率。

摘要:

FlashAttention-style online softmax通过流式传输分数瓷砖并通过芯片内存实现线性内存的精确注意力计算,同时维护运行最大值和归一化器。然而,随着注意力内核接近现代加速器的峰值张量核心/立方体核心吞吐量,非矩阵乘法组件(尤其是每瓷砖行最大值和行求和缩减及重缩放链)可能成为向量或SIMD受限,并主导延迟。本文重新审视FlashAttention,提出Vector Relieved Flash Attention(VFA),一种硬件友好的方法,通过减少由行最大值驱动的运行最大值更新,同时保留在线softmax结构。VFA通过键块表示的廉价近似初始化运行最大值,重新排列键块遍历以优先考虑高影响的汇块和本地块,并冻结剩余块的最大值以避免重复缩减和重缩放。我们进一步将VFA与块稀疏跳过方法如BLASST结合,形成Vector Relieved Sparse Attention(VSA),从而减少块计数和每块开销。值得注意的是,VFA和VSA完全避免了FA4.0在更新阶段使用的条件重缩放操作。在MMLU和MATH500等基准测试以及注意力统计学的验证中,我们的设计得到了验证:(i)汇块和本地重新排列稳定了运行最大值早期;(ii)简单的Q和K块摘要由于块内异质性而失败;(iii)当最大值出现在中间块时需要m-initialization。总体而言,VFA和VSA在不损失性能的情况下有效缓解了在线softmax缩减瓶颈。与C16V32基线相比,C8V32、C4V32和C4V16在现代硬件上实现了近两倍的速度提升,同时击中向量瓶颈。随着未来架构改进,C4V16通过增强指数容量将实现六倍的速度提升。

英文摘要:

FlashAttention-style online softmax enables exact attention computation with linear memory by streaming score tiles through on-chip memory and maintaining a running maximum and normalizer. However, as attention kernels approach peak tensor-core/cube-core throughput on modern accelerators, non-matmul components of online softmax -- especially per-tile rowmax and rowsum reductions and rescale chains -- can become vector or SIMD limited and dominate latency. This paper revisits FlashAttention and proposes Vector Relieved Flash Attention (VFA), a hardware-friendly method that reduces rowmax-driven updates of the running maximum while retaining the online-softmax structure. VFA initializes the running maximum via a cheap approximation from key-block representations, reorders key-block traversal to prioritize high-impact sink and local blocks, and freezes the maximum for remaining blocks to avoid repeated reductions and rescaling. We further integrate VFA with block-sparse skipping methods such as BLASST to form Vector Relieved Sparse Attention (VSA), which reduces both block count and per-block overhead. Notably, VFA and VSA completely avoid the conditional rescale operation in the update stage used in FA4.0. Extensive evaluations on benchmarks including MMLU and MATH500, together with attention statistics, verify our design: (i) sink and local reordering stabilizes the running maximum early; (ii) simple Q and K block summaries fail due to intra-block heterogeneity; (iii) m-initialization is required when maxima appear in middle blocks. Overall, VFA and VSA efficiently alleviate online-softmax reduction bottlenecks without performance loss. Compared to the C16V32 baseline, C8V32, C4V32 and C4V16 achieve nearly two times speedup on modern hardware while hitting the vector bottleneck. With upcoming architecture improvements, C4V16 will deliver six times speedup by enhancing exponent capacity.

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

↑