Papers › FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness

FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness

27 May 2022arXiv:2205.14135archive 2025-07-28

Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, Christopher Ré

Transformers are slow and memory-hungry on long sequences, since the time and memory complexity of self-attention are quadratic in sequence length. Approximate attention methods have attempted to address this problem by trading off model quality to reduce the compute complexity, but often do not achieve wall-clock speedup. We argue that a missing principle is making attention algorithms IO-aware -- accounting for reads and writes between levels of GPU memory. We propose FlashAttention, an IO-aware exact attention algorithm that uses tiling to reduce the number of memory reads/writes between GPU high bandwidth memory (HBM) and GPU on-chip SRAM. We analyze the IO complexity of FlashAttention, showing that it requires fewer HBM accesses than standard attention, and is optimal for a range of SRAM sizes. We also extend FlashAttention to block-sparse attention, yielding an approximate attention algorithm that is faster than any existing approximate attention method. FlashAttention trains Transformers faster than existing baselines: 15% end-to-end wall-clock speedup on BERT-large (seq. length 512) compared to the MLPerf 1.1 training speed record, 3× speedup on GPT-2 (seq. length 1K), and 2.4× speedup on long-range arena (seq. length 1K-4K). FlashAttention and block-sparse FlashAttention enable longer context in Transformers, yielding higher quality models (0.7 better perplexity on GPT-2 and 6.4 points of lift on long-document classification) and entirely new capabilities: the first Transformers to achieve better-than-chance performance on the Path-X challenge (seq. length 16K, 61.4% accuracy) and Path-256 (seq. length 64K, 63.1% accuracy).

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2205.14135")

Code

Syntology Ran 9 of 30 code samples harvested from 5 repositories linked to this paper; 21 have no recorded run. Of those that ran: 1 ran · violated contract; 5 ran · our draft was wrong; 1 ran · fixture could not drive it; 2 ran with no contract checked.

By repository: community (archive-listed): 21 samples from 4 repositories, 9 ran; found in paper text by Syntology: 9 samples from 1 repository, 0 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

13 repositories listed; official and paper-mentioned ones first.

dao-ailab/flash-attention officialmentioned on GitHubpytorchBSD-3-Clause report
hazyresearch/flash-attention mentioned in papermentioned on GitHubpytorchBSD-3-Clause report
ROCm/flash-attention mentioned on GitHubpytorchBSD-3-Clause report
alibaba/megatron-llama mentioned on GitHubpytorch report
answerdotai/modernbert mentioned on GitHubpytorchApache-2.0 report
csguoh/fastvar mentioned on GitHubpytorchMIT report
latkins/trifast mentioned on GitHubjaxMIT report
lucidrains/flash-cosine-sim-attention mentioned on GitHubpytorch report
microsoft/chunk-attention mentioned on GitHubpytorch report
softmax1/flash-attention-softmax-n mentioned on GitHubpytorchGPL-3.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

30 samples harvested; 9 ran; 0 honoured the contract we drafted; 21 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · violated contract
5ran · our draft was wrong
1ran · fixture could not drive it
2ran
21unverified

Licence: 1 of the 30 samples is pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 5 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

FlashCosineSimAttention lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) ran MIT (permissive) · 836e169269626b2d · report
FlashSelfAttention alibaba/megatron-llama/megatron/model/transformer.py community (archive-listed) ran licence not identified · pointer only · 3a48757821245a9c · report
and_reduce lucidrains/block-recurrent-transformer-pytorch/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py community (archive-listed) ran · violated contract MIT (permissive) · 5e1eae834b42ab87 · report
flash_cosine_sim_attention lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) ran · fixture could not drive it MIT (permissive) · 445b382660c20892 · report
grouped_l2norm lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) ran · our draft was wrong fingerprinted MIT (permissive) · bf71ddb7b6318152 · report
l2norm lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) ran · our draft was wrong fingerprinted MIT (permissive) · ebc7297040578822 · report
l2norm_cpu lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) ran · our draft was wrong fingerprinted MIT (permissive) · ccb62a80e7c1e0af · report
once lucidrains/block-recurrent-transformer-pytorch/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py community (archive-listed) ran · our draft was wrong MIT (permissive) · 2ae574072ec6f776 · report
unpack_one lucidrains/block-recurrent-transformer-pytorch/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py community (archive-listed) ran · our draft was wrong MIT (permissive) · a0902e24bf5299e7 · report
Attend lucidrains/block-recurrent-transformer-pytorch/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py community (archive-listed) unverified MIT (permissive) · a91304b317adcfe6 · report
attention_reference latkins/trifast/src/trifast/equiv.py community (archive-listed) unverified MIT (permissive) · 7ec53192aa7f5504 · report
disable_tf32 latkins/trifast/src/trifast/utils.py community (archive-listed) unverified MIT (permissive) · e70a5be792d21381 · report
enable_tf32 latkins/trifast/src/trifast/utils.py community (archive-listed) unverified MIT (permissive) · 8c357c18a7a5df9f · report
flash_cosine_sim_attention_cpu lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) unverified MIT (permissive) · 69095fe94801bb6a · report
gen_tensors latkins/trifast/src/trifast/utils.py community (archive-listed) unverified MIT (permissive) · f6a5967228c7a9d2 · report
l2norm_tensors lucidrains/flash-cosine-sim-attention/flash_cosine_sim_attention/flash_cosine_sim_attention.py community (archive-listed) unverified MIT (permissive) · 518990c8ea44ffc6 · report
neg_inf latkins/trifast/src/trifast/equiv.py community (archive-listed) unverified MIT (permissive) · dfce9c8c32b2f721 · report
pack_one lucidrains/block-recurrent-transformer-pytorch/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py community (archive-listed) unverified MIT (permissive) · 86ca4a3f9ab20a35 · report
parse_int_list latkins/trifast/src/trifast/tune.py community (archive-listed) unverified MIT (permissive) · 405da6c9ec4f68dd · report
triangle_attention_simple latkins/trifast/src/trifast/equiv.py community (archive-listed) unverified MIT (permissive) · 1b603b0ef7263401 · report
valid_dtypes latkins/trifast/src/trifast/tune.py community (archive-listed) unverified MIT (permissive) · 7f47b6e7368cff8b · report
create_band_mask_from_inputs google-research/long-range-arena/lra_benchmarks/models/bigbird/bigbird_attention.py found in paper text by Syntology unverified Apache-2.0 (permissive) · e370fc6ece6221ed · report
create_rand_mask_from_inputs google-research/long-range-arena/lra_benchmarks/models/bigbird/bigbird_attention.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 5aedb376f0772dfe · report
get_block_rand_mask google-research/long-range-arena/lra_benchmarks/models/bigbird/bigbird_attention.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 5e965cd1402c118a · report
get_tsv_dataset google-research/long-range-arena/lra_benchmarks/matching/build_vocab.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 0d78a4ebde5b96c9 · report
get_tsv_dataset google-research/long-range-arena/lra_benchmarks/matching/input_pipeline.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 64a65eaa8e65ea8c · report
preprocess_dataset google-research/long-range-arena/lra_benchmarks/listops/input_pipeline.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 59e4e06672a6c268 · report
rename_close_brackets google-research/long-range-arena/lra_benchmarks/listops/input_pipeline.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 1affbc4020c2fc7b · report
sinusoidal_init google-research/long-range-arena/lra_benchmarks/models/layers/common_layers.py found in paper text by Syntology unverified Apache-2.0 (permissive) · 60bb0fb77bbdfb3e · report
whitespace_tokenize google-research/long-range-arena/lra_benchmarks/matching/build_vocab.py found in paper text by Syntology unverified Apache-2.0 (permissive) · fbeafd410f521a6f · report

Tasks

16k4kDocument ClassificationImage ClassificationLanguage Modelling

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionAttention DropoutCosine AnnealingDense ConnectionsDiscriminative Fine-TuningDropoutFeedforward NetworkGPT-2Grouped-query attentionLayer NormalizationLinear LayerLinear Warmup With Cosine AnnealingMulti-Head AttentionMulti-Query AttentionResidual ConnectionRotary EmbeddingsSPEEDSoftmaxWeight Decay

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections