What is FlashAttention?
A fast attention implementation that tiles the computation in on-chip memory and never writes the large intermediate table to HBM. Its results match standard attention.
Japanese name: FlashAttention
A fast attention implementation that tiles the computation in on-chip memory and never writes the large intermediate table to HBM. Its results match standard attention.
Japanese name: FlashAttention
Attention builds an n × n table from the dot products of queries and keys. A straightforward implementation writes this table out to the GPU's memory (HBM). It then reads the table back for the softmax, and reads it once more for the product with the values. The table grows with the square of the sequence length. As a result, reading and writing memory tends to take more time than the arithmetic itself.
FlashAttention splits the queries, keys and values into small blocks (tiles). The blocks are made small enough to fit in the fast on-chip memory and are loaded one after another. There the dot products, the softmax and the product with the values are computed in one go. What is written to HBM is mainly the final output, and the n × n table is not written out. The number of dot products is unchanged, while memory traffic falls. Because no intermediate table is kept, the memory needed grows only roughly in proportion to the sequence length.
A softmax normally uses the sum over a whole row of the table. FlashAttention updates the running maximum and the running sum each time it finishes a block, and uses them to correct the partial result as it goes. Once every block has been processed, the value is that of the same formula computed over the whole row. It is not an approximation, so the results agree apart from small differences due to the order of rounding. In training, the parts of the table needed for backpropagation are recomputed rather than stored.
Answer: A. Splitting computation into tiles processed in on-chip memory and never writing the large n × n intermediate table to HBM, reducing memory traffic
A naive implementation writes the n × n table to HBM, reads it back for the softmax and again for the product with the values, so memory traffic dominates. FlashAttention splits queries, keys and values into blocks loaded into shared memory and carries the computation through in one pass, updating the softmax incrementally, never writing the table to HBM. The forward-pass computation is the same (the backward pass in training adds some recomputation), but memory traffic falls sharply and it runs faster.
No. It is an implementation that changes the order of computation and the way memory is used, and it computes the same formula as standard attention. Methods that cut computation by skipping some token pairs are a different idea.
Yes, the number of dot products still grows with the square of the length. What falls is the traffic to and from HBM and the memory for the intermediate table. Like operator fusion, it reduces data movement rather than arithmetic.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.