FlashAttention is a way of computing attention that reduces reads and writes to GPU memory to make it faster, without changing the result. Dao et al. at Stanford University proposed it in 2022 in the paper "FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness." PyTorch's F.scaled_dot_product_attention also automatically uses an implementation from this family (FlashAttention-2) when conditions allow.
A GPU has a large but slow memory (HBM) and a small but fast memory (SRAM). According to the paper, an A100 GPU has the following.
| Memory | Size | Bandwidth |
|---|---|---|
| HBM (the GPU's main memory) | 40–80 GB | 1.5–2.0 TB/s |
| SRAM (on-chip memory) | 192 KB (for each of the 108 streaming multiprocessors) | about 19 TB/s |
A standard attention implementation writes , the result of , and , the result after softmax (both ), to HBM and reads them back for the next computation. Because GPU compute has become faster than memory, for operations with little computation such as softmax, reading and writing HBM takes more time than the computation itself.
FlashAttention splits into small blocks, loads them into SRAM, computes everything from the matrix product through softmax to the product with inside SRAM in one go, and writes only the output back to HBM. The matrix is never written to HBM. In cooking terms, instead of carrying ingredients to and from the warehouse (HBM) one dish at a time, it brings over only what fits on the countertop at hand (SRAM) and does the cutting, frying, and plating there.
The right side of the figure at the top of the article shows the order of computation. Like standard attention, it computes every pair of the attention matrix, but it computes one tile at a time and discards each tile once it is done.

