# 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.

- URL: https://dmxsf.com/en/blog/flashattention-2-faster-attention-with-better-parallelism-and-work-partitioning/
- [DMXSF](https://dmxsf.com/en/about/)
- Published: 2023-07-27
- Updated: 2026-11-13
- Paper notes
- Paper: [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691) (Tri Dao · ICLR 2024, 2023)

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.

```python
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)
```

```text
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

- [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691)
- [FlashAttention](https://dmxsf.com/en/blog/flashattention-fast-and-memory-efficient-exact-attention/)
- [FlashAttention-3](https://dmxsf.com/en/blog/flashattention-3-fast-and-accurate-attention-with-asynchrony-and-low-precision/)

## 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.
