FlashAttention defined
Attention compares every token with every other token. Standard implementations build a score matrix of size sequence length by sequence length, write it to GPU memory, apply softmax, write it again, then multiply by the values. The paper that introduced the method notes that the time and memory of self-attention are quadratic in sequence length, and for long inputs that matrix becomes the bottleneck.
Tri Dao and colleagues’ 2022 paper called the fix IO-aware: it uses tiling to reduce the number of memory reads and writes between GPU high bandwidth memory and on-chip SRAM. The math is unchanged, so it is exact attention, not an approximation. They reported a 15% end-to-end speedup on BERT-large at sequence length 512 against the MLPerf 1.1 record, and 3x on GPT-2 at length 1K.
In practice you rarely call it directly. PyTorch, vLLM, Hugging Face and most training stacks select it, or a close relative, automatically when your GPU supports it.
References: FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness (arXiv)
How it works: tiles, SRAM and an online softmax
A GPU has two kinds of memory that matter here. HBM is large, tens of gigabytes, but relatively slow to reach. SRAM on each streaming multiprocessor is tiny but much faster. Standard attention is limited by HBM traffic, not by math.
The kernel loads a block of queries and a block of keys and values into SRAM, computes their partial scores, and keeps a running maximum and running sum for the softmax. As it moves to the next key block it rescales what it has so far. When all blocks are done, the result equals the full softmax, and the big score matrix never existed in HBM. In the backward pass it recomputes the scores from the saved inputs rather than storing them.
Worked example: one sequence of 8,192 tokens has a score matrix of 8,192 x 8,192, about 67 million entries per head. In FP16 that is roughly 134 MB per head, or about 4.3 GB for 32 heads in one layer. Tiling avoids writing those gigabytes, which is where both the speed and the memory saving come from.
References: FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness (arXiv)

Versions and GPU support
The project README lists four generations. Version 2 runs on Ampere, Ada and Hopper GPUs such as the A100, RTX 3090, RTX 4090 and H100, supports FP16 and BF16, and handles head dimensions up to 256. Turing cards such as the T4 are served by a separate repository. Version 3, in beta, is optimized for Hopper and adds FP8 for the forward pass. Version 4 is written in CuTeDSL for Hopper and Blackwell, including the B200.
AMD GPUs are covered by ROCm builds of version 2: a Composable Kernel backend for MI200x, MI250x, MI300x and MI355x, and a Triton backend. Requirements in the README include CUDA 12.0 or newer for version 2, CUDA 12.3 or newer for version 3 (12.8 recommended), PyTorch 2.2 or newer, and Linux.
| Version | NVIDIA GPUs | Data types | Notes |
|---|---|---|---|
| FA2 | Ampere, Ada, Hopper (A100, RTX 4090, L40S, H100) | FP16, BF16 | Head dim up to 256; ROCm builds for AMD |
| FA3 (beta) | Hopper (H100, H200) | FP16, BF16; FP8 forward | CUDA 12.3+, 12.8 recommended |
| FA4 | Hopper and Blackwell (H100, B200) | See project README | Written in CuTeDSL |
| Turing (T4) | Separate repository | FP16 | Not in the main package |
References: Dao-AILab flash-attention repository README
Framework support: PyTorch, vLLM and others
PyTorch’s scaled_dot_product_attention lists three implementations: a FlashAttention-2 kernel, a memory-efficient attention kernel and a math fallback. If your inputs and GPU qualify, the call uses the fast kernel with no extra package to install.
vLLM picks an attention backend automatically, trying options in priority order. You can force one with --attention-backend FLASH_ATTN and choose the version with --attention-config.flash_attn_version. Its docs state the default is version 4 on Blackwell (SM100 and up), version 3 on Hopper (SM90), and version 2 otherwise. FlashInfer and Triton backends are alternatives. Our guide to deploy vLLM on a cloud GPU covers serving flags.
References: PyTorch scaled_dot_product_attention documentation · vLLM attention backends documentation · Dao-AILab flash-attention repository README
What it changes for cost on rented GPUs
The main win is memory headroom on long sequences, which turns into larger batches or longer context on the same GPU. For training, that can mean fewer GPUs or less activation checkpointing. For inference, the saved memory goes to the KV cache, which sets how many requests you can serve at once.
Illustrative example with assumed numbers: a fine-tuning job at 8K context needs 4 GPUs with standard attention because activations overflow, but fits on 2 with tiled attention. At an assumed $2 per GPU-hour and 10 hours, that is $80 against $40. Your real saving depends on the model and sequence length, so measure step time and memory both ways.
Check the GPU generation before you plan around a version. An A100 or L40S gets version 2; an H100 or H200 can use version 3; a B200 gets version 4 in vLLM by default. How to choose a GPU for AI covers the wider trade-offs.
References: Dao-AILab flash-attention repository README · vLLM attention backends documentation
Common misconceptions
It is approximate attention. No. It returns the same result as standard attention, up to floating-point rounding, which is why it replaced the standard path in most stacks.
It reduces the KV cache. Not by itself. It avoids the score matrix, but the stored keys and values are the same size. PagedAttention and KV cache quantization address cache memory.
It speeds up everything. Gains are largest on long sequences. For short prompts the attention step is a small share of runtime, so end-to-end gains are smaller.
References: FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness (arXiv)
Related terms
PagedAttention manages KV cache memory in fixed-size blocks. HBM is the GPU memory the kernel avoids hammering. Scaled dot product attention is PyTorch’s attention entry point. Tensor cores do the matrix math inside each tile. Memory bandwidth decides how much standard attention suffers.
Checklist and next step
Confirm your GPU generation and the version it supports. Use PyTorch SDPA or your serving engine’s default backend before installing anything. Use BF16 or FP16 inputs. Compare memory and step time with and without the fast kernel on your real sequence length.
Then size the rental. NeuraMesh rents H100, H200, A100, L40S and more by the hour: choose on rent GPUs and receive a confirmed quotation before you pay, or ask the compute advisor which GPU fits your context length.
NeuraMesh prices for these GPUs
| GPU | Memory | Data center | Value |
|---|---|---|---|
| RTX 4090 | 24 GB | $0.46 | $0.40 |
| L40S | 48 GB | $1.26 | $0.54 |
| A100 | 80 GB | $1.56 | $0.98 |
| H100 | 80 GB | $2.88 | $2.00 |
Every order is confirmed in a quotation before you pay. See all GPU prices.
Questions readers ask
What does FlashAttention do?
It computes exact attention in small tiles in on-chip memory, so the full score matrix is never written to GPU memory. That cuts memory traffic, which makes attention faster and lighter on long sequences.
Does my GPU support flash attention 2?
Version 2 supports NVIDIA Ampere, Ada and Hopper GPUs, such as the A100, RTX 3090, RTX 4090, L40S and H100, plus AMD Instinct GPUs through ROCm builds. Turing cards such as the T4 need a separate repository.
Is version 3 better than version 2?
On Hopper GPUs it is optimized for that architecture and adds FP8 for the forward pass. It is still marked beta, and it does not run on Ampere or Ada cards.
Do I need to install the package to use it in PyTorch?
Not for basic use. PyTorch’s scaled_dot_product_attention includes a version 2 kernel and picks it automatically when inputs qualify.
Does it change model outputs?
No beyond normal floating-point rounding. It is exact attention computed in a different order, not an approximation.
Sources and editorial notes
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness (arXiv)
- Dao-AILab flash-attention repository README
- PyTorch scaled_dot_product_attention documentation
- vLLM attention backends documentation
Primary documentation reviewed November 24, 2026. Provider descriptions reflect published documentation. Recommendations are our analysis; worked figures are illustrative unless explicitly stated otherwise. No independent provider benchmark or uptime ranking is claimed.
Need this GPU? Rent it from NeuraMesh: choose a GPU and plan, get a confirmed quotation, and pay only when you approve. See pricing.
