FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
- Publication
- NeurIPS 2024Conference
- First submitted to arXiv
- arXiv:2407.08608
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{transformersflashattention32024,
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},
url = {https://arxiv.org/abs/2407.08608}
}
FlashAttention-2 gave every SM on the GPU something to do and pushed attention to around 70% of theoretical peak on the A100. The previous note ended with a question. If everyone looks busy, does that mean the whole production line is efficient?
On the H100, the answer came quickly. FlashAttention-2 uses only 35% of the H100's compute, while a well-tuned matrix multiplication on the same card reaches 80% to 90%.
The H100 (Hopper architecture) has a few things the A100 lacks: dedicated hardware for moving data, Tensor Cores that can compute asynchronously on their own, and FP8 support. FlashAttention-2's algorithm was designed around a synchronous model, "finish one step, then start the next", and uses none of these new features.
This paper, by Jay Shah and Ganesh Bikshandi of Colfax Research, Ying Zhang of Meta, Vijay Thakkar and Pradeep Ramani of NVIDIA, and Tri Dao of the FlashAttention series, redesigns the algorithm specifically for Hopper.
Defining the problem
The exponential costs more than you'd think
The attention forward pass is mostly two matrix multiplications with a softmax in between. First compute , apply softmax to each row to get , then compute .
People usually keep their eyes on the matmuls, and the exponential inside softmax looks like a minor supporting role. A quick calculation on the H100 says otherwise.
The H100 SXM5 does FP16 matrix multiplication at 989 TFLOPS, while the units for special functions such as the exponential manage only 3.9 TFLOPS, a gap of about 256×.
With head dimension , each element of the score matrix takes operations for and another for , matmul operations in all, for a single exponential.
The work differs by 512×, the speed by 256×, so the exponential takes half as long as the matmuls. In FP8, the matmuls get twice as fast while the exponential stays the same, and the two take equally long.
If the two take turns, the Tensor Cores spend nearly a third of their time waiting for the exponentials to finish.
What Hopper can do
The good news is that the exponential and the matmuls use different hardware units, so they could run at the same time all along. The H100 provides the tools to make them do so:
- TMA (Tensor Memory Accelerator): dedicated hardware for moving data between HBM and shared memory. Once the instruction is issued, you can forget about it; it signals when the transfer is done.
- WGMMA: a Tensor Core instruction issued per warpgroup (4 warps, 128 threads). It can read operands directly from shared memory, and it is asynchronous, so after issuing it the threads can go do something else first.
- setmaxnreg: reallocates registers dynamically between warpgroups, giving more to the ones that compute more.
- FP8 Tensor Core: twice the throughput of FP16.
The hard part is that softmax has to wait for the result of the first matmul, and the second matmul has to wait for the result of softmax. How to run dependent work at the same time is what this paper is about.
Solving the problem
Some load, some compute
The first technique is warp specialization. The warps in a thread block are split into two roles.
The producer warpgroup only issues TMA instructions, moving , and from HBM into shared memory. Issuing instructions takes only one thread, so it gives up most of its registers.
The consumer warpgroup only computes, doing the matmuls with WGMMA and the softmax itself, and it gets the larger share of registers.
Between them sits a circular buffer with stages. The producer notifies the consumer each time it fills a stage, and the consumer hands the stage back when it is done with it. Data movement and computation each go their own way, with no need for both to stop and wait.
Playing ping-pong

With two consumer warpgroups, you can stagger them. A barrier forces warpgroup 1's matmuls (this iteration's and the next iteration's ) to be scheduled before warpgroup 2's, so while warpgroup 1 does softmax, the Tensor Cores are busy with warpgroup 2's matmuls. In the next time slice the two swap.
The authors admit that the real schedule is not as tidy as the figure, but for the FP16 forward pass with and sequence length 8192, speed goes from 570 to 620–640 TFLOPS.
Overlap inside one warpgroup

Even within a single warpgroup, work can overlap across iterations. The key is not to line up the three tasks of the same iteration one behind another.
In iteration , first issue without waiting for it to finish; then issue the previous iteration's , again without waiting. Then wait for to come back and immediately run softmax on it. At this point the Tensor Cores are still computing the previous iteration's , and the softmax hides underneath it.
The price is registers. To span iterations, an extra copy of has to be kept, more floats per thread block. Large tiles are already competing for registers, so one more pipeline stage means a smaller tile, and the trade-off between the two has to be settled by measurement.
In the appendix, the authors also tried a three-stage version, hoping to hide softmax under both the preceding and the following matmul, and it ended up slower than two stages. The compiler overlapped softmax with only one of the matmuls, and registers got even tighter, forcing a smaller tile.
Another headache is the compiler. NVCC reorders instructions on its own and can scramble a carefully arranged order. The authors read the assembly (SASS) to confirm that the overlap really happens.
To see how much each technique contributes, the authors measured non-causal FP16 attention with batch 4, sequence length 8448, 16 heads and :
| Setting | Time (ms) | TFLOPs/s |
|---|---|---|
| FlashAttention-3 | 3.538 | 661 |
| No two-stage pipeline | 4.021 | 582 |
| No warp specialization | 4.105 | 570 |
Compiled from Table 2 of the paper.
Remove either technique and it gets more than 12% slower.
The backward pass uses the same division of labor, with one extra role. The computed by each thread block must eventually be added into the same in HBM, and with many blocks competing to write the same locations, they easily get in each other's way. FlashAttention-3 assigns a separate warp just to write back, so the other warps don't wait for it and can move straight on to the next matmul.
FP8: layout and precision
FP8 can make the matmuls twice as fast again, but it brings two headaches.
The first is data layout. FP8 WGMMA only accepts k-major operands, meaning contiguous along the inner-product dimension. For the second matmul, , the inner-product dimension is the sequence length, but is usually contiguous along the head dimension. TMA can't transpose data while moving it, so you have to transpose it yourself.
The authors weighed three options. Transposing as part of the previous step (rotary embedding, for example) is hard to turn into a general-purpose library; running a separate transpose kernel is too wasteful when inference is already bound by memory bandwidth. They settled on transposing inside the kernel, with the producer warpgroup doing it en route using LDSM and STSM instructions. From the second iteration on, the transpose hides within the time of the two WGMMAs.
In addition, the FP32 accumulator that an FP8 matmul produces is laid out in registers differently from the input layout the next matmul expects. The authors rearrange it with byte permute instructions and have the transpose write out the matching order, so the two sides line up.
The second headache is precision. FP8 (e4m3) has only 3 mantissa bits, and the activations of large models often contain a few unusually large outliers. The usual approach shares one scaling factor across the whole tensor, so a single outlier squeezes every other value into a tiny range. The authors use two techniques:
- Block quantization: split , and into blocks of the same size as the ones FlashAttention computes on, each with its own scaling factor.
- Incoherent processing: before quantization, multiply both and by the same random orthogonal matrix . Since , and the attention result is unchanged; but every element becomes a random sum of many original elements, which flattens out the outliers. is a random ±1 diagonal matrix times a Hadamard matrix, costs , and can be done together with rotary embedding.
For the test, the authors simulated activations with outliers by adding extra noise with a standard deviation of 10 to 0.1% of the elements, then compared the root-mean-square error against a result computed in FP64:
| Method | Error (RMSE) |
|---|---|
| Standard implementation, FP16 | 3.2e-4 |
| FlashAttention-2, FP16 | 1.9e-4 |
| FlashAttention-3, FP16 | 1.9e-4 |
| Standard implementation, FP8 | 2.4e-2 |
| FlashAttention-3, FP8 | 9.1e-3 |
| No block quantization | 9.3e-3 |
| No incoherent processing | 2.4e-2 |
Compiled from Table 3 of the paper.
The FP8 version's error is 2.6 times lower than the standard approach's. Look closely at the last two rows, though. Removing block quantization makes almost no difference, while removing incoherent processing falls straight back to the standard approach's level. That 2.6× is almost entirely the random orthogonal matrix's doing.
In FP16, FlashAttention-2 and -3 are both more accurate than the standard implementation, because softmax's intermediate results stay in FP32.
Discussion
Speed

In FP16, the forward pass is 1.5 to 2.0 times faster than FlashAttention-2, and the backward pass 1.5 to 1.75 times faster. The fastest setting (, sequence length 16k) reaches 756 TFLOPs/s, about three quarters of the H100's FP16 theoretical peak of 989.
Against NVIDIA's own cuDNN, the two trade wins at sequence lengths around 1k; a little longer, and FlashAttention-3 leads all the way.
The FP8 forward pass gets close to 1.2 PFLOPs/s. Against cuDNN's FP8, though, it leads only at ; at of 128 and 256 it ties without a causal mask and falls behind with one. The authors' explanation is that the FP8 version doesn't have a persistent kernel and load balancing yet, while the FP16 version does.
All these speeds are converted with a formula, counting operations for the forward pass, half that for causal, and 2.5 times as many for the backward pass.
Limitations and where it stands
The authors list three limitations. LLM inference hasn't been specially optimized yet, FP8 has no persistent kernel yet, and the effect of low-precision attention on large-scale training is still unclear.
The code is in the hopper directory of flash-attention, released under BSD-3-Clause. It has to be installed separately as flash_attn_3 and supports only the H100 and H800. As of November 2026, the official README still carries the heading "FlashAttention-3 beta release" and describes it as a version for testing before it is integrated into the main repository, and FP8 is still forward-only. (Over two years in beta. Call it long-term support)
Not that nobody is looking after it. As of November 2026, the hopper directory is still getting bug fixes.
Conclusion
Attention on the H100 was slow not because anyone was slacking, but because everyone was waiting for whoever came before them. FlashAttention-3 gives the hardware that moves data, multiplies matrices and computes exponentials each its own task, then staggers their work with scheduling.
In the FP8 part, the precision trick is of more practical use than the speed. If you want low-precision attention in your own inference pipeline, multiplying by a random orthogonal matrix costs very little, yet almost all of the error reduction comes from it.
On Blackwell, the Tensor Cores got a lot faster again, while the exponential and memory did not keep up. The next note, [26.03] FlashAttention-4: Fixing the Weakest Link, picks up from there.