FlashAttention is an exact-attention algorithm that minimizes high-bandwidth memory (HBM) reads and writes between GPU HBM and on-chip SRAM. It achieves this by fusing operations in a tiled, IO-aware manner, dramatically accelerating both training and inference of Transformer models without any approximation of the attention mechanism.
Glossary
FlashAttention

What is FlashAttention?
FlashAttention is an algorithm that computes exact self-attention with significantly reduced memory reads and writes by fusing operations in a tiled, IO-aware manner.
By restructuring the computation to keep intermediate matrices in fast SRAM, FlashAttention reduces the memory footprint from quadratic to linear in sequence length. This enables training on longer context windows and delivers significant wall-clock speedups, making it a foundational optimization in modern large language model implementations.
Key Features of FlashAttention
FlashAttention is an algorithm that accelerates the exact attention computation by minimizing slow, high-bandwidth memory (HBM) reads and writes. It achieves this by fusing operations in a tiled, IO-aware manner, keeping data in fast on-chip SRAM.
IO-Awareness: Tiling for SRAM
The core innovation is tiling the attention computation to fit into the limited, high-bandwidth GPU SRAM. Instead of materializing the full N x N attention matrix in slow HBM, FlashAttention loads blocks of Query (Q), Key (K), and Value (V) matrices from HBM to SRAM, computes attention on the block, and writes only the final output back. This drastically reduces HBM read/write operations, the primary bottleneck in standard attention.
Exact Attention with No Approximation
Unlike sparse attention or low-rank approximation methods, FlashAttention computes mathematically identical results to standard attention. It uses a numerically stable online softmax algorithm, known as tiled softmax or online normalizer calculation, to correctly rescale block statistics without needing the full row of attention scores. This guarantees no loss in model quality while achieving significant speedups.
Recomputation Over Storage for Backward Pass
To remain memory-efficient during training, FlashAttention avoids storing the large intermediate attention matrix for the backward pass. Instead, it recomputes the attention scores and softmax statistics during the backward pass by reloading the Q, K, V blocks from HBM. This recomputation strategy trades extra FLOPs for a massive reduction in memory footprint, enabling training with longer sequences.
Algorithmic Fusion of Operations
FlashAttention implements kernel fusion by combining multiple CUDA kernels into a single, highly optimized kernel. Operations like the matrix multiply, softmax scaling, dropout masking, and the final output accumulation are all performed in a single pass over the data while it resides in SRAM. This eliminates the overhead of launching multiple kernels and the associated round-trips to HBM.
Massive Memory Footprint Reduction
Standard attention has a memory complexity of O(N²) with sequence length N, which quickly exhausts GPU HBM for long sequences. FlashAttention reduces the memory footprint to O(N) by never materializing the full attention matrix. This allows training Transformers on sequence lengths of 8k, 16k, or even 64k tokens, which was previously infeasible without model parallelism or approximation.
Wall-Clock Speedup for Training and Inference
By shifting the bottleneck from memory bandwidth to compute speed, FlashAttention delivers 2-4x wall-clock speedups for the attention layer. This translates to significant end-to-end training time reductions for models like GPT and BERT. For inference, FlashAttention accelerates the prefill phase and, in its FlashDecoding variant, optimizes the generation phase by parallelizing the attention computation across the sequence length dimension.
FlashAttention vs. Standard Attention vs. Sparse Attention
A technical comparison of exact, IO-aware attention against standard exact attention and approximate sparse attention methods, focusing on memory access patterns, computational complexity, and implementation characteristics.
| Feature | FlashAttention | Standard Attention | Sparse Attention |
|---|---|---|---|
Exact Attention Computation | |||
IO-Aware Tiling Strategy | |||
Memory Complexity (Sequence Length n) | O(n) | O(n²) | O(n) to O(n√n) |
Primary Memory Working Set | GPU SRAM (on-chip) | GPU HBM (off-chip) | GPU HBM (off-chip) |
HBM Read/Write Operations | Minimal (fused kernel) | High (materializes full matrix) | Reduced (partial matrix) |
Backward Pass Recomputation | |||
Attention Pattern | Full (exact, tiled) | Full (exact, dense) | Predefined mask (local, strided, global) |
Training Speedup vs. Standard (GPT-2 scale) | 2-4x | 1x (baseline) | 1.5-3x |
Frequently Asked Questions
Clear answers to common questions about the IO-aware exact attention algorithm that is accelerating large language model training and inference.
FlashAttention is an exact-attention algorithm that computes the standard self-attention operation without approximation, but with significantly faster wall-clock speed and lower memory usage. It works by minimizing high-bandwidth memory (HBM) reads and writes between GPU DRAM and on-chip SRAM. Instead of materializing the full quadratic N x N attention score matrix in slow HBM, FlashAttention uses tiling to load blocks of the Query, Key, and Value matrices into fast SRAM, computes the softmax attention on-chip block-by-block, and writes only the final output back to HBM. This IO-aware design is implemented in custom CUDA kernels that fuse the entire attention operation—matrix multiply, softmax, and weighted sum—into a single kernel, eliminating redundant memory transfers. The algorithm achieves up to 7.6x speedup on long sequences while using memory linear in sequence length, enabling training of models with 8K+ context windows without model parallelism.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the ecosystem of algorithms and techniques that surround FlashAttention, from the memory bottlenecks it solves to the attention variants it accelerates.
IO-Awareness
The core design principle behind FlashAttention. Traditional attention is memory-bound, not compute-bound. The algorithm minimizes reads/writes between slow High Bandwidth Memory (HBM) and fast Static Random-Access Memory (SRAM) on the GPU.
- Tiling: Splits the Q, K, V matrices into blocks that fit entirely in SRAM.
- Recomputation: Recalculates the attention matrix in the backward pass instead of storing it, trading FLOPs for memory savings.
- Kernel Fusion: Combines multiple operations (matmul, softmax, dropout) into a single CUDA kernel.
GPU Memory Hierarchy
Understanding the hardware FlashAttention optimizes for is essential. Modern GPUs have a deep memory hierarchy with vastly different bandwidths.
- HBM (High Bandwidth Memory): Large capacity (80GB on A100) but high latency. Standard attention stores the full N x N attention matrix here.
- SRAM (Static RAM): Small (192KB per streaming multiprocessor on A100) but ~10x faster than HBM. FlashAttention keeps all working data here.
- Bandwidth Gap: The key insight is that attention is bottlenecked by HBM bandwidth, not compute throughput.
KV Cache Optimization
FlashAttention is critical for optimizing the Key-Value (KV) cache during autoregressive decoding. The KV cache stores previous keys and values to avoid recomputation, but its size grows linearly with sequence length.
- Memory Pressure: Long sequences cause the KV cache to exceed HBM capacity, making memory bandwidth the primary bottleneck.
- FlashDecoding: An extension of FlashAttention that parallelizes the attention computation over the long KV sequence dimension during inference.
- Works synergistically with Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) to further reduce cache size.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us