Bring the mental model from Efficient Attention at Scale: KV Cache, GQA & FlashAttention; this page will reuse it instead of restarting from zero.
Attention & Transformers
FlashAttention: IO-Aware Attention
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.

Concept Structure
FlashAttention: IO-Aware Attention
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
FlashAttention: IO-Aware AttentionConceptual Bridge
What should feel connected as you move through this page.
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.
The next edge should feel earned: use the demo prediction here before following LLM Serving at Scale: Prefill, Decode & Continuous Batching.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Standard attention is conceptually simple but computationally awkward on GPUs:
- Compute the score matrix .
- Apply a row-wise softmax to get attention weights .
- Multiply by values: .
The problem is step (1): materializing a matrix is huge, and moving it to and from GPU memory (HBM) is slow. For long sequences, attention is often memory-bandwidth bound rather than FLOPs bound.
FlashAttention is the idea: keep computations in fast on-chip SRAM by tiling, and compute the softmax in a streaming way so you never need to store the full matrix.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Standard attention (and the issue)
For one head, with :
The attention weights matrix is . If you store it explicitly, memory scales like .
Online softmax (streaming trick)
For a single row of scores , the softmax uses:
You can compute this in blocks without ever storing all scores at once by maintaining a running max and a running normalizer .
For a block of scores with:
you can merge block statistics with the running state via:
At the end, the attention output for that row is:
This is the core idea: you can compute without ever materializing .
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
def softmax(x):
m = float(x.max())
e = np.exp(x - m)
return e / e.sum()
def attn_out_stream(scores, values, block=2):
m, l, o = -np.inf, 0.0, 0.0
for i in range(0, len(scores), block):
sb = scores[i:i+block]
vb = values[i:i+block]
mb = float(sb.max())
eb = np.exp(sb - mb)
lb = float(eb.sum())
ob = float((eb * vb).sum())
m_new = max(m, mb)
l = np.exp(m - m_new) * l + np.exp(mb - m_new) * lb
o = np.exp(m - m_new) * o + np.exp(mb - m_new) * ob
m = m_new
return o / l
s = np.array([2.0, 1.0, -1.0, 0.5, 3.2, -0.3])
v = np.array([0.1, 0.2, -0.4, 0.0, 0.7, 0.3])
out_full = float((softmax(s) * v).sum())
out_stream = float(attn_out_stream(s, v, block=2))
print("full:", round(out_full, 6), "stream:", round(out_stream, 6), "diff:", round(abs(out_full - out_stream), 9))
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
The demo below asks you to predict the memory bottleneck first, then reveal how the online softmax state is merged across tiles. The key invariant is that FlashAttention computes exact attention while avoiding a stored probability matrix.
Live Concept Demo
Explore FlashAttention: IO-Aware Attention
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what FlashAttention: IO-Aware Attention should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change FlashAttention: IO-Aware Attention should make visible.
Visual Inquiry
Make the image answer a mathematical question
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.
Which visible object should carry the first intuition?
Pick the cue that should make FlashAttention: IO-Aware Attention easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Primary source for the dense FlashAttention mechanism: IO-aware HBM/SRAM tiling plus block-wise/incremental softmax statistics reduce HBM reads/writes and avoid materializing the full N x N attention matrix.
Open sourceClaim Review
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.
Claims without a substantive review badge still need exact source-support review.
dao-2022-flashattention
Use equation, code, and demo objects to check whether the source support is operational.
Dao et al. frame FlashAttention as IO-aware exact attention using HBM/SRAM tiling; Algorithm 1 updates block softmax statistics and returns O=softmax(QK^T)V while avoiding reads/writes of the full N x N attention matrix to HBM.
Sources: FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness"Online softmax" means the paper's block-wise/incremental softmax statistics. This checks the dense FlashAttention mechanism, not block-sparse variants, CUDA numeric equivalence, backward-pass implementation, or universal speedups.A bounded review summary is present; still check caveats and exact source scope.Checked Dao et al. against the exact claim: the paper presents FlashAttention as exact attention, uses HBM/SRAM tiling, maintains block softmax statistics (m,l,O) to compute the same softmax(QK^T)V result, and avoids reading/writing the full N x N attention matrix to HBM; local math/code/demo illustrate the same finite-row invariant.
Reviewer: codex+oracle; reviewed 2026-05-07Practice Loop
Try the idea before it explains itself
A fused, tiled attention implementation that avoids materializing the full T x T matrix by using an online softmax, reducing memory traffic and speeding up long-context training/inference.
Before touching the demo, predict one visible change that should happen in FlashAttention: IO-Aware Attention.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
FlashAttention: IO-Aware Attention
What is the smallest example that makes FlashAttention: IO-Aware Attention click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:attention-transformers/flash-attention.
- Source ids to inspect: dao-2022-flashattention
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - FlashAttention: IO-Aware Attention Object key: concept:attention-transformers/flash-attention Context: Attention & Transformers Anchor id: concept/concept-notebook/attention-transformers/flash-attention Open question: What is the smallest example that makes FlashAttention: IO-Aware Attention click without losing the math? Evidence to inspect: - Source ids to inspect: dao-2022-flashattention - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/attention-transformers/flash-attention
concept:attention-transformers/flash-attention