← ml-viz FlashAttention paper

FlashAttention Tiling

Attention needs a softmax over each row of an N by N score matrix, which looks like it forces you to build the whole matrix. FlashAttention does not. It walks over small tiles, keeps a running maximum and running sum per row, and fixes earlier work with a rescale factor whenever the maximum grows. The tab below runs the real arithmetic on random data and checks the answer against the naive method. Everything here is computed live in your browser, nothing is measured on a GPU.

Score matrix S = QKᵀ

rows are queries, columns are keys

What this tile does