[论文解读] FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
FlashAttention-3 通过利用异步和 FP8 低精度,在 Hopper GPU 上加速注意力,相对 FlashAttention-2 实现 1.5–2.0x 的 FP16 加速,并接近 1.2 PFLOPs/s 的 FP8 性能,同时精度有所提升。
Attention, as a core layer of the ubiquitous Transformer architecture, is the bottleneck for large language models and long-context applications. FlashAttention elaborated an approach to speed up attention on GPUs through minimizing memory reads/writes. However, it has yet to take advantage of new capabilities present in recent hardware, with FlashAttention-2 achieving only 35% utilization on the H100 GPU. We develop three main techniques to speed up attention on Hopper GPUs: exploiting asynchrony of the Tensor Cores and TMA to (1) overlap overall computation and data movement via warp-specialization and (2) interleave block-wise matmul and softmax operations, and (3) block quantization and incoherent processing that leverages hardware support for FP8 low-precision. We demonstrate that our method, FlashAttention-3, achieves speedup on H100 GPUs by 1.5-2.0$ imes$ with FP16 reaching up to 740 TFLOPs/s (75% utilization), and with FP8 reaching close to 1.2 PFLOPs/s. We validate that FP8 FlashAttention-3 achieves 2.6$ imes$ lower numerical error than a baseline FP8 attention.
研究动机与目标
- 为长上下文变换器和新模态激发更快的注意力。
- 利用 Hopper GPU 的特性(异步性和 FP8)来重新设计注意力。
- 在控制低精度数值误差的同时实现更高吞吐量。
提出的方法
- 引入带有 warp 专门化的生产者-消费者异步,以隐藏内存和计算延迟。
- 通过基于 WGMMA 的 GEMM 的 2 阶段(以及 3 阶段)流水线,将 GEMM 与 softmax 重叠。
- 使用硬件加速的 FP8 GEMM,结合分块量化和不一致处理以降低量化误差。
- 在内核中对 V tile 进行转置以及布局调整,以满足 FP8 WGMMA 的约束。
- 在 H100 上,对 FP16/FP8 下的 FlashAttention-2 与 cuDNN 进行基准测试,报告 TFLOPs/s 和加速比。
- 开源实现并计划与 PyTorch 和 Hugging Face 集成。

实验结果
研究问题
- RQ1如何利用异步性和低精度硬件特性来加速现代 GPU 上的注意力?
- RQ2warp 专门化和 GEMM-softmax 重叠对前向/反向吞吐量的影响是什么?
- RQ3基于 FP8 的注意力在提供更高吞吐量的同时能否实现有竞争力的精度?
- RQ4在注意力中使用 FP8 WGMMA 时,实际的布局/精度约束是什么?
- RQ5FlashAttention-3 与现有在 Hopper GPUs 上的 GPU 优化注意力实现相比如何?
主要发现
- FP16 FlashAttention-3 在前向传播上比 FlashAttention-2 提高 1.5–2.0x,在反向传播上提高 1.5–1.75x。
- FlashAttention-3 在 H100 上 FP16 最高达到 740 TFLOPs/s(75% 利用率),FP8 接近 1.2 PFLOPs/s。
- 在具有离群特征的情况下,带有分块量化和不一致处理的 FP8 FlashAttention-3 比逐张量量化的标准注意力准确性高 2.6x。
- 2 阶段 GEMM-softmax 流水线和 warp-specialization 贡献了显著的加速(消融实验中如 570→661 TFLOPs)。
- FP16 保持与 FlashAttention-2 的数值一致性,因为中间结果仍然是 FP32;而 FP8 相对于使用分块技术的基线 FP8 可以减少误差。
- FlashAttention-3 已开源,目标是与 PyTorch 和 Hugging Face 集成。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。