Compute attention in tiles that fit in SRAM. Keep a running maximum and denominator per row, and rescale previous accumulators when a new tile has a larger maximum. The algebra is unchanged; only the order of operations and memory placement change.
1. Standard attention
S=QK⊤/d, A=softmax(S), O=AV. The memory cost is O(n2) for S and A.
2. Softmax is stable with a running max
For two blocks with maxima m1,m2 and unnormalized sums ℓ1,ℓ2, the combined maximum is m=max(m1,m2) and the combined denominator is ℓ=em1−mℓ1+em2−mℓ2.
3. Online accumulator
Maintain Oi per row. When a new block arrives, set Oi←Oiemold−mnew+eSblock−mnewVblock, then divide by the final ℓi.
4. IO complexity
Let d be head dimension and M SRAM size. Standard attention writes O(n2) elements to HBM; tiled attention writes O(n2d2/M) HBM elements, a large reduction when M≫d.
5. Exactness
Because only associativity and the max-rescaling identity are used, the output equals standard softmax attention up to floating-point order. Verify against a PyTorch reference with a strict tolerance.
Reference lessons are written for this topic specifically. Generated lessons elsewhere on the platform are labelled with a quality score and review status; do not treat them as equivalent.