Tiled Attention with Online Softmax

hard
Unit 27 · Quantization0/0 to milestone

Standard attention builds the full n×nn \times n score matrix, which is huge for long contexts. FlashAttention never materialises it. Instead it processes keys in blocks, keeping a running max mm, a running normaliser ℓ\ell and a running output oo for each query, and rescaling them as each new block arrives:

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
How LLMs Work· 13 of 19
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Tiled Attention with Online Softmax · TechGradify