AI Dojo Open on the typewriterThe typewriter

Explainer

FlashAttention

2 min read
Assumes: you know that attention compares each token with earlier ones, as in Attention: how a model uses the rest of your text.
First published 19 November 2026. Last edited 19 November 2026.

A faster way to compute exactly the same attention, by moving less data between the parts of a GPU's memory.

A GPU has a large main memory and a much smaller, faster memory on the chip itself. Standard attention writes the whole grid of token-to-token scores into the main memory, and Hugging Face notes that this creates “bottlenecks that slow down inference” (Hugging Face attention backends). FlashAttention, also written flash attention, works through the grid in tiles small enough to stay in the fast memory. Its authors call it an “exact attention algorithm” that reduces “the number of memory reads/writes” (FlashAttention paper).

Exact means the same tokens connect with the same weights, so it does not change what the model answers, apart from rounding (below). What changes is speed and memory use during the calculation, which makes longer inputs practical. In Hugging Face's words, “All attention implementations perform the same computation.” That separates FlashAttention from sliding-window and sparse attention, which change which tokens connect, and from PagedAttention, which manages how cache memory is allocated (vLLM in the serving guide). It does not shrink the KV cache either: the same keys and values are stored.

Going deeper

Within floating-point limits. Computers round every number, and adding the same numbers in a different order can change the last digits. PyTorch warns that its attention output “may be different depending on what backend kernel is chosen” (PyTorch documentation). Whether such a difference ever changes a generated word is something to test, not assume. Later versions, FlashAttention-2 and FlashAttention-3, appear as options such as flash_attention_2 in Hugging Face Transformers.

In the long read: names with attention in them. For kernels in general: Where CUDA and kernels fit.