What Is FlashAttention?
What FlashAttention is, why its first two versions give the same answer as normal attention but run faster on long inputs, and how GPU memory explains it, for your AI interview.
In short
FlashAttention is a way to run a Transformer's attention step that moves far less data in GPU memory. It works in small tiles held in fast on-chip memory, and its first two versions give the same result as the usual method.
11 min readAdvancedCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
FlashAttention is a faster way to run attention, the step where a Transformer weighs every token against every other. For its first two versions, the result is the same, so it is exact. The trick is memory. Standard attention writes a huge table of scores to big, slow GPU memory and reads it back. FlashAttention works in small tiles inside fast memory on the chip, so the table never gets written out. Long inputs fit and run faster.
Attention is the step where a Transformer lets each token look at every other token to decide what matters. The maths itself is simple. The memory traffic is the hard part. On a GPU, the big memory sits far from the chip's fast working memory. Standard attention builds a table of every token-to-token score, writes it to the big memory, and reads it back. On long inputs that table grows with the square of the length, so it gets huge.
The first FlashAttention does the same maths in small tiles. It loads one block of queries, keys and values into the fast on-chip memory, scores that block there, and keeps a running total so the softmax stays correct across blocks. The finished output goes back to the big memory. The paper calls this IO-aware, meaning it counts the reads and writes between the two memories. For its first two versions, it is exact, so the answers match standard attention up to small rounding differences.
The gain shows up on long documents. In a made-up example, a contract bundle of 40,000 tokens would need a score table of about 3.2 GB per head per layer the standard way. With tiles, only one block of about 33 KB sits on the chip at a time. FlashAttention-2 changes how the work is split across the GPU, and FlashAttention-3 targets newer Hopper GPUs, such as the H100.
So my answer: it is a memory-aware way to run attention, exact in its first two versions, and a big help for long inputs. I would also check that the model's weights still fit on the GPU, because they take memory too.
What is FlashAttention, in plain words?
Attention is the step where a Transformer, the design behind today's large language models, lets every token weigh how much every other token matters to it. FlashAttention is a faster way to run that same step on a GPU, the chip that does the heavy maths.
On a GPU, the slow part is often moving data in and out of the big memory. A GPU has a big memory that sits away from the calculating units, and a small, very fast memory right on the chip. Standard attention writes a huge table of token-to-token scores to the big memory, then reads it back. FlashAttention cuts the work into small tiles and finishes each one on the chip, so the big table is never written out.
Think of a legal team checking a stack of contracts. The slow way walks to the archive for every page and walks back. The better way brings one small stack to the desk, checks it fully there, and only then fetches the next stack. The answer is the same, and most of the walking is gone.
Key words
- Attention
- The step where each token decides how much to look at every other token.
- HBM
- GPU high bandwidth memory: the large main memory, slower to reach.
- SRAM
- Small memory on the chip itself: very quick to reach, but tiny.
- Tile
- A small block of the input, handled in one go before the next block.
- Exact attention
- The same result as standard attention. Every score is still computed.
How does FlashAttention work?
Attention is the main bottleneck on long inputs, because its runtime and memory both grow with the square of the length. The 2022 paper says Transformers are slow and memory-hungry on long sequences, since the time and memory complexity of self-attention are quadratic in sequence length.
Two ways to run the same attention step
Queries, keys, values
the model's inputs for one layer
Standard
Full score table
every token against every token
Big, slow GPU memory
table written out, then read back
FlashAttention
One small tile
a block of scores at a time
Fast on-chip memory
the block stays on the chip
Same answer
exact in versions 1 and 2
- 1The inputs for one layer go to the standard method.
- 2The full score table is written to the big, slow memory.
- 3The table is read back to produce the output.
- 4The same inputs are cut into small tiles.
- 5Each tile is scored and finished on the chip.
- 6The finished output leaves for the answer.
- 1
Cut the inputs into tiles
Split the queries, keys and values into blocks small enough for the fast on-chip memory.
- 2
Score one tile on the chip
Work out that block's scores there, without writing the full table to the big memory.
- 3
Keep a running total
Track a running maximum and sum, so the softmax (the step that turns scores into weights) stays correct across blocks.
- 4
Write the result
After the last tile, write out the finished output. The big table never existed in slow memory.
What does it save on a long contract bundle?
Take a made-up bundle of 40,000 tokens, sent to a model that compares clauses across contracts. Here is the memory for the score table in the standard way, and for one tile. The numbers are simplified, but the scale is the point.
# A simplified memory check for one long contract bundle (made-up size).
# Standard attention keeps every token-to-token score in big GPU memory.
BYTES_PER_SCORE = 2 # a 16-bit number takes 2 bytes
TILE = 128 # side of a square tile of scores held on the chip at once (made-up)
BUNDLE = 40_000 # tokens in one contract bundle (made-up)
def full_grid_gb(tokens):
return tokens * tokens * BYTES_PER_SCORE / 1e9
def one_tile_kb():
return TILE * TILE * BYTES_PER_SCORE / 1e3
print(f"Full score grid: {full_grid_gb(BUNDLE):.1f} GB per head, per layer")
print(f"One tile on chip: {one_tile_kb():.0f} KB, at any length")
print(f"Half the bundle: {full_grid_gb(BUNDLE // 2):.1f} GB, a quarter of the grid")Output
Full score grid: 3.2 GB per head, per layer One tile on chip: 33 KB, at any length Half the bundle: 0.8 GB, a quarter of the grid
The full table grows with the square of the length, so doubling the bundle makes it four times bigger. A tile stays the same size whatever the length. That is the gap FlashAttention is built to close. It does not remove the quadratic work, though: the number of calculations still grows with the square of the length. What it removes is the big table, so the memory need grows in a straight line.
Does FlashAttention change the answer?
For the first two versions, the answer is no. FlashAttention-1 and FlashAttention-2 run the same attention maths and skip no scores. FlashAttention-3 adds a low-precision FP8 mode for speed. In that mode, its results can differ slightly from standard attention. The first paper's title and abstract call the method exact, and the second version says it has no approximation.
“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.”
FlashAttention paper, 2022
“FlashAttention exploits the asymmetric GPU memory hierarchy to bring significant memory saving (linear instead of quadratic)”
FlashAttention-2 paper, 2023
So for the first two versions, an answer that says FlashAttention makes the model worse, or skips parts of attention, has it wrong. The model's output is the same, up to small rounding differences from the arithmetic.
What changed in FlashAttention-2 and FlashAttention-3?
The second version keeps the same idea and splits the work across the GPU in a better way. The third version targets newer Hopper GPUs (NVIDIA's Hopper line, such as the H100), and it says the older version was not using the chip well.
“However, it has yet to take advantage of new capabilities present in recent hardware, with FlashAttention-2 achieving only 35% utilization on the H100 GPU.”
FlashAttention-3 paper, 2024
How would you fit a long bundle on a GPU that runs out of memory?
- Standard method
The table does not fit
The score table grows with the square of the length, so the job fails or slows right down.
- Tiled method
Scores stay on the chip
Scores are worked out in tiles and the table is never written out. Then check the model's weights still fit.
What does the interviewer want to hear?
A strong answer covers
- A plain definition: attention maths run in tiles, so less data moves in GPU memory.
- Why moving data is often the slow part.
- That the first two versions are exact: the output matches standard attention.
- Tiles and on-chip memory, each in one sentence.
- It changes speed and memory. The model and its weights stay the same.
- The versions: FlashAttention-2 and FlashAttention-3, and what each one added.
Common traps
Trap"FlashAttention is a smaller model that runs faster."
BetterIt runs attention in a different way. The model and its weights stay the same size.
Trap"It skips some scores to save time."
BetterIt keeps every score, so the first two versions are exact. The change is where the work happens: in tiles on the chip.
Trap"Faster means more accurate."
BetterSame output in the first two versions, less memory traffic. The gain is speed and memory only.
Can you spot the wrong claim?
Spot the wrong claim
Which claim about FlashAttention would fail a senior review?
Quick check
A contract team's long bundles run out of GPU memory during attention. Which change is the most direct fix?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q056Why is attention quadratic in sequence length?11 min
- Q055What is the KV cache, and why does it speed up generation?12 min
- Q058Multi-query vs grouped-query attention?10 min
- Q059Sliding-window and sparse attention?Coming soon
Last updated on 26 November 2026
Running long documents through a model and hitting GPU limits?
I design and build AI products and agents, including the system behind them. Book a short call and say what your documents and hardware look like.