Paper notes

FlashAttention-2: Better parallelism and work partitioning

FlashAttention-2 preserves exact attention while reducing non-matrix operations, increasing sequence parallelism and improving warp-level work partitioning for higher GPU utilization.

Published Updated 2 min read

On this page
  1. How it works
  2. What the evidence shows
  3. A reproducible check
  4. Limitations and common misreadings
  5. The key takeaway
  6. Further reading
  7. FAQ

FlashAttention-2 keeps the same attention mathematics and rewrites the CUDA execution. Fast matrix units can otherwise wait on elementwise operations and poor thread partitioning.

How it works

It reduces rescaling and other elementwise work, maintains only necessary online-softmax statistics, parallelizes across queries in addition to batches and heads, and partitions Q/K/V to reduce warp communication.

What the evidence shows

The paper reports around 230 TFLOP/s on A100 and roughly twice the first-generation speed in its settings. Results depend on hardware, head size, sequence and mask; this is not sparse attention.

A reproducible check

This snippet checks a public formula or configuration; it does not reproduce full training.

d, heads = 64, 32
print("model width represented =", d*heads)
for seq in (2048, 8192):
    q_blocks = seq//128
    print(seq, "128-row query blocks =", q_blocks)
model width represented = 2048
2048 128-row query blocks = 16
8192 128-row query blocks = 64

The arithmetic is reproducible, but model quality still depends on the full experiments in the paper.

Limitations and common misreadings

Gains require suitable kernels and GPUs, and short sequences may see launch overhead. Exact means no algorithmic approximation, though floating-point evaluation order can still differ slightly.

The key takeaway

The lesson is that asymptotic complexity is not enough: operation mix, work partitioning and latency hiding determine realized speed.

Further reading

FAQ

Does it change the attention equation?
No. It computes exact attention with different parallel execution.
Why reduce non-matrix work?
Matrix units have much higher throughput than elementwise operations, which can bottleneck execution.
Which new parallelism is emphasized?
More parallelism across the query sequence, beyond batch and heads.