FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision

Jay Shah, Ganesh Bikshandi, Ying Zhang, Vijay Thakkar, Pradeep Ramani +1 more
7/11/2024
cs.LGcs.AI

No official code found. Best implementation: Dao-AILab/flash-attention (25,131 stars, BSD-3-Clause, last commit 2026-04-29).

Abstract

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$\times$ 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$\times$ lower numerical error than a baseline FP8 attention.

View on arXivView PDF

Code Implementations(1)

BSD-3-Clause

Fast and memory-efficient exact attention

25,1313,152C, C++May 19, 20225 months agoBSD-3-Clause

Similar Papers

Cite this paper

@article{shah2024flashattention,
  title  = {FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision},
  author = {Jay Shah and Ganesh Bikshandi and Ying Zhang and Vijay Thakkar and Pradeep Ramani and Tri Dao},
  year   = {2024},
  eprint = {2407.08608},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2407.08608},
  url    = {http://arxiv.org/abs/2407.08608v2},
  journal = {NEURIPS 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2407.08608.svg)](https://codeofpaper.com/paper/2407.08608)

Discussion