FlashAttention-4:异构硬件扩展下的算法与内核流水线协同设计
FlashAttention-4: Algorithm and Kernel Pipelining Co-Design for Asymmetric Hardware Scaling
AI总结:
FlashAttention-4通过异构硬件扩展下的算法与内核流水线协同设计,提升B200 GPU上的注意力计算效率。
摘要:
注意力机制作为Transformer架构的核心层,是大语言模型和长上下文应用的瓶颈。虽然FlashAttention-3通过异步执行和 warp 特化优化了Hopper GPU上的注意力计算,但主要针对H100架构。随着AI行业迅速转向部署基于Blackwell的系统,如B200和GB200,由于硬件扩展的不对称性,tensor核心吞吐量翻倍,而其他功能单元(共享内存带宽、指数单元)的扩展速度更慢或保持不变。我们开发了几种技术来解决这些变化的瓶颈:(1)重新设计的流水线利用完全异步的MMA操作和更大的瓷砖大小;(2)软件模拟的指数和条件softmax重新缩放,减少非矩阵乘法操作;(3)利用张量内存和2-CTA MMA模式,减少反向传播过程中的共享内存流量和原子加法。我们证明,我们的方法FlashAttention-4在B200 GPU上使用BF16时,相比cuDNN 9.13实现了高达1.3倍的加速,相比Triton实现了2.7倍的加速,达到最高1613 TFLOPs/s(71%利用率)。除了算法创新外,我们完全使用CuTe-DSL嵌入Python实现FlashAttention-4,相比传统的C++模板方法,编译时间快20-30倍,同时保持完整的表达能力。
英文摘要:
Attention, as a core layer of the ubiquitous Transformer architecture, is the bottleneck for large language models and long-context applications. While FlashAttention-3 optimized attention for Hopper GPUs through asynchronous execution and warp specialization, it primarily targets the H100 architecture. The AI industry has rapidly transitioned to deploying Blackwell-based systems such as the B200 and GB200, which exhibit fundamentally different performance characteristics due to asymmetric hardware scaling: tensor core throughput doubles while other functional units (shared memory bandwidth, exponential units) scale more slowly or remain unchanged. We develop several techniques to address these shifting bottlenecks on Blackwell GPUs: (1) redesigned pipelines that exploit fully asynchronous MMA operations and larger tile sizes, (2) software-emulated exponential and conditional softmax rescaling that reduces non-matmul operations, and (3) leveraging tensor memory and the 2-CTA MMA mode to reduce shared memory traffic and atomic adds in the backward pass. We demonstrate that our method, FlashAttention-4, achieves up to 1.3$\times$ speedup over cuDNN 9.13 and 2.7$\times$ over Triton on B200 GPUs with BF16, reaching up to 1613 TFLOPs/s (71% utilization). Beyond algorithmic innovations, we implement FlashAttention-4 entirely in CuTe-DSL embedded in Python, achieving 20-30$\times$ faster compile times compared to traditional C++ template-based approaches while maintaining full expressivity.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。