std :: ml::attention
Function std::flash_attention_forward
&FloatTensor flash_attention_forward(
const &FloatTensor Q,
const &FloatTensor K,
const &FloatTensor V,
unsigned long kvBlockSize,
)Tiled, online-softmax attention (Dao et al.): processes K/V in blocks of 'kvBlockSize' rows, maintaining a running max/sum/weighted-output per query row and rescaling as each block's contribution arrives, so the full [seqLen,kvLen] score matrix is never materialized. Produces the same result as attention_forward() (up to floating-point rounding) — the point is the memory-access pattern, not a different answer. Q: [seqLen,headDim], K/V: [kvLen,headDim] -> result: [seqLen,headDim]. When it records gradients, or on a GPU, it is the fused attention op (one row per thread with an online softmax: also never the full score matrix), whose backward recomputes the scores from each row's log-sum-exp.