FlashAttention-3 speeds up FP16 attention on NVIDIA H100 GPUs by 1.5x to 2.0x over FlashAttention-2, reaching 740 TFLOPs/s (75% of Hopper’s theoretical peak) while pushing FP8 attention near 1.2 PFLOPs/s with 2.6x lower numerical error than standard per-tensor FP8. In July 2024, Jay Shah, Ganesh Bikshandi (Colfax Research), Ying Zhang (Meta), Vijay Thakkar, Pradeep Ramani (NVIDIA), and Tri Dao (Princeton and Together AI) showed why FlashAttention-2 stalled at 35% utilization on Hopper despite reaching 73% on Ampere: synchronous kernel scheduling forced asynchronous Tensor Cores, memory engines, and exponential units to wait on one another.
On an H100 SXM5 (132 SMs at 1830 MHz), FP16 Tensor Core matmul delivers 989 TFLOPs/s, whereas special-function units computing softmax exp deliver just 3.9 TFLOPs/s. At head dimension 128, attention performs 512x more matmul FLOPs than exp ops, yet exp runs 256x slower per FLOP, meaning serialized softmax alone can burn half the execution time (and even more in FP8).
- 1.5x to 2.0x FP16 speedup: Forward passes reach up to 740 TFLOPs/s (and 756 TFLOPs/s non-causal at 2k sequence length, head dim 128), backward passes run 1.5x to 1.75x faster than FlashAttention-2, and long sequences (
seqlen >= 1k) beat closed-source cuDNN 9. - Near-1.2 PFLOPs/s FP8 throughput: Asynchronous FP8
WGMMAplus in-kernel shared-memoryVtransposes reach up to 1,171 TFLOPs/s (16k causal, head dim 256). - 2.6x lower FP8 outlier error: Block quantization paired with orthogonal Hadamard incoherent processing cuts synthetic outlier RMSE from 2.4e-2 to 9.1e-3 (
e4m3vs. FP64 reference). - Both overlap techniques are required: Disabling either warp-specialization (570 TFLOPs/s) or 2-stage GEMM-softmax pipelining (582 TFLOPs/s) erases most of the gain down from 661 TFLOPs/s on 8k non-causal attention.
How It Works
FlashAttention-3 redesigns the tiled kernel around three Hopper hardware mechanisms:
- Producer-consumer warp-specialization and pingpong scheduling: Thread blocks split warps into dedicated TMA producers (issuing asynchronous
HBMto shared-memory loads into a circular buffer) andWGMMAconsumers, using Hopper’ssetmaxnregto donate registers from idle producers to compute warps. Across two consumer warpgroups,bar.syncbarriers enforce pingpong scheduling so one warpgroup executes Tensor CoreWGMMAwhile the other computes softmaxexp, lifting 8k FP16 forward throughput from 570 to 620 to 640 TFLOPs/s. (In the backward pass, a dedicateddQ-writer warp overlaps global atomic accumulations.) - Intra-warpgroup 2-stage GEMM-softmax pipelining: Even inside one warpgroup, waiting for
S = QK^Tbefore softmax andO += PVserializes hardware units. By buffering an extra score tileS_nextin registers, the kernel executes the asynchronousPVWGMMAof iterationj - 1concurrently with softmax on iterationj. A 3-stage variant actually ran slower because NVCC did not overlap the secondWGMMAand extra register pressure shrank tile sizes. - In-kernel FP8 transposes and Hadamard incoherence: Hopper’s FP8
WGMMAdemandsk-majorshared-memory operands, clashing withV’s head-contiguous layout and FP32 accumulator registers. Rather than paying for a global memory transpose kernel, FlashAttention-3 performs a packed 8-bitLDSM/STSMtranspose ofVinside shared memory hidden behind priorWGMMAwork, paired with register byte permutations. To tame 3-bit-mantissae4m3quantization outliers, it combines per-block scaling with incoherent processing, multiplyingQandKby a random diagonal ±1 Hadamard matrixMinO(d log d)time (fusable with RoPE). BecauseMis orthogonal (M M^T = I),(QM)(KM)^T = QK^Tpreserves exact dot products while spreading outlier spikes across channels.
Key Findings
Benchmarked on an H100 80GB SXM5 with 16k tokens per batch (sequence lengths 512 to 16k, hidden dim 2048, head dims 64, 128, 256), FlashAttention-3 FP16 delivers 1.5x to 2.0x higher forward throughput than FlashAttention-2, 1.5x over Triton, and 3x to 16x over standard PyTorch attention. At sequences of 1k and longer, FP16 FlashAttention-3 surpasses NVIDIA’s closed-source cuDNN 9 library.
In FP16, both FlashAttention-2 and FlashAttention-3 match at 1.9e-4 RMSE against FP64, 1.7x lower than standard PyTorch attention (3.2e-4) because intermediate softmax statistics stay in FP32. In FP8, the Table 3 ablation confirms that Hadamard incoherent processing does almost all the heavy lifting against activation outliers, cutting error 2.6x even before adding per-block scaling. Like FlashAttention-2, the kernel natively supports multi-query and grouped-query attention without duplicating K and V in HBM.
Caveats and Builder Takeaway
- Hopper-only primitives and FP8 gaps: The kernel relies on Hopper
TMA,WGMMA, andsetmaxnreg, offering no direct speedup on Ampere A100 GPUs. Furthermore, the paper’s FP8 kernel lacks the persistent scheduling and causal load-balancing strategy built into FP16 FlashAttention-3, so FP8 lags cuDNN 9 on short sequences and causal masks at head dimensions128and256(ahead at head dim64). - Prefill and training focus, not single-token decode: Benchmarks evaluate long-sequence compute-bound passes (
512to16kquery tokens). Memory-bandwidth-bound autoregressive decode steps (query_len = 1) still depend on PagedAttention or split-KV decode kernels for utilization. - FP8 training stability untested: The paper evaluates FP8 kernel RMSE on synthetic outliers rather than end-to-end large-scale pretraining runs.
Builder takeaway: On H100 clusters running long-context training or high-throughput prefill, upgrading from FlashAttention-2 to FlashAttention-3 FP16 is a drop-in 1.5x to 2.0x attention speedup with identical numerical accuracy; hold off on FP8 attention for causal 128/256 head dimensions until persistent causal load balancing closes the gap with cuDNN 9.


