FlashAttention is an IO-aware exact-attention algorithm that computes the standard self-attention operation without approximation. It achieves significant speedups by minimizing reads and writes between the slow, high-capacity GPU High Bandwidth Memory (HBM) and the fast, on-chip SRAM. The core innovation is fusing the attention operation into a single CUDA kernel through tiling, processing the attention matrix in blocks that fit entirely within SRAM.
Glossary
FlashAttention

What is FlashAttention?
An exact-attention algorithm that minimizes high-bandwidth memory reads and writes between GPU HBM and SRAM by using tiling and recomputation, dramatically speeding up attention computation and reducing memory footprint for long sequences.
To avoid materializing the full N x N attention matrix in HBM, FlashAttention employs recomputation of the softmax normalization statistics during the backward pass. This trades increased FLOPs for a dramatic reduction in memory I/O, lowering the memory complexity from O(N²) to O(N). The result is a 2-4x wall-clock speedup over standard PyTorch attention and the ability to train models on sequence lengths previously impossible due to memory constraints.
Key Features of FlashAttention
FlashAttention is an algorithm that computes exact self-attention by optimizing data movement between GPU memory hierarchies, delivering significant speedups and memory savings for long sequences.
IO-Awareness: The Core Innovation
Standard attention implementations are memory-bound, spending most of their time reading and writing large intermediate matrices to GPU High Bandwidth Memory (HBM). FlashAttention is IO-aware, meaning it explicitly accounts for the speed hierarchy between slow HBM and fast on-chip SRAM. By minimizing HBM reads and writes, it shifts the bottleneck from memory bandwidth to compute utilization, achieving wall-clock speedups of 2-4x over optimized baselines like PyTorch's scaled_dot_product_attention.
Tiling: Block-by-Block Computation
To avoid materializing the full N x N attention matrix in HBM, FlashAttention uses tiling. The algorithm splits the input sequences (Q, K, V) into blocks that fit entirely within SRAM. Attention is computed incrementally block-by-block, with intermediate softmax statistics carefully tracked and rescaled. This allows exact attention computation without ever storing the full quadratic intermediate matrix, reducing peak memory from O(N²) to O(N).
Recomputation: Trading Compute for Memory
In the backward pass, standard attention saves the large attention matrix from the forward pass for gradient calculation. FlashAttention discards this matrix and instead recomputes it on-the-fly during the backward pass using the stored softmax normalization statistics. This trades a modest increase in FLOPs for a dramatic reduction in memory footprint, enabling training with 4-8x longer sequences on the same hardware without running out of memory.
Exact Attention, Not an Approximation
Unlike sparse or low-rank attention approximations (e.g., Longformer, Linformer), FlashAttention computes mathematically exact self-attention. The output is numerically identical to standard attention up to floating-point rounding errors. This means there is no accuracy trade-off—models trained with FlashAttention achieve identical perplexity and downstream task performance while benefiting from the speed and memory advantages.
FlashAttention-2: Parallelism & Work Partitioning
The second iteration, FlashAttention-2, significantly improves GPU utilization by redesigning the work partitioning strategy. It reduces non-matmul FLOPs, parallelizes over the sequence length dimension (previously parallelized only over batch and heads), and distributes work more evenly across thread blocks. This achieves 2x speedup over the original FlashAttention and pushes GPU utilization to near theoretical limits, reaching up to 73% of peak FLOPs on A100 GPUs.
FlashAttention-3: Hopper Architecture Optimization
FlashAttention-3 targets NVIDIA's Hopper GPU architecture (H100), exploiting new hardware features like WGMMA instructions for asynchronous Tensor Core operations and TMA (Tensor Memory Accelerator) for hardware-accelerated data movement. It introduces interleaved block-wise matmul and softmax scheduling to hide memory latency. On H100 GPUs, FlashAttention-3 achieves 1.5-2.0x speedup over FlashAttention-2 and reaches up to 740 TFLOPS, representing 75% of theoretical peak performance.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the FlashAttention algorithm, its mechanisms, and its impact on large language model training and inference.
FlashAttention is an exact-attention algorithm that computes the standard Transformer self-attention output identically to the conventional implementation but with dramatically reduced memory reads and writes between GPU high-bandwidth memory (HBM) and on-chip SRAM. It works by employing two key techniques: tiling, which decomposes the large attention matrix into smaller blocks that fit entirely within SRAM, and recomputation, which re-derives the softmax normalization statistics during the backward pass instead of storing the full intermediate attention matrix. By fusing the entire attention operation into a single CUDA kernel, FlashAttention avoids materializing the quadratic N x N attention matrix in HBM, reducing peak memory from O(N²) to O(N) and delivering 2-4x wall-clock speedups on long sequences. The algorithm is mathematically exact—it produces the same output and gradients as standard attention up to numerical precision—making it a drop-in replacement for existing attention implementations without any model retraining or architecture modification.
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
Key concepts and architectural components that interact with or are optimized by the FlashAttention algorithm in modern Transformer systems.
Attention Mechanism
The foundational Transformer component that FlashAttention accelerates. It computes a weighted relevance score for every token in a sequence relative to every other token, enabling the model to dynamically focus on salient information. Standard attention has O(n²) memory complexity due to materializing the full attention matrix, which FlashAttention avoids through tiling and recomputation.
KV-Cache
A memory buffer storing pre-computed key and value tensors from previous decoding steps. FlashAttention's memory efficiency directly reduces the footprint of the KV-Cache, enabling longer context lengths and larger batch sizes during autoregressive generation. Optimized KV-Cache management is critical for low-latency inference.
Grouped-Query Attention (GQA)
An attention optimization that shares a single key-value head across multiple query heads. When combined with FlashAttention, GQA further reduces the KV-Cache size and memory bandwidth requirements, enabling efficient serving of large models like Llama 2 70B and Mixtral on constrained hardware.
Self-Attention
The specific attention variant where a sequence computes a representation of itself by relating different positions within the same sequence. FlashAttention was originally designed to accelerate self-attention in Transformer encoders and decoders, making it the primary computational target for the algorithm's tiling and recomputation strategies.
Context Window
The maximum span of text, measured in tokens, that an LLM can process in a single inference request. FlashAttention's linear memory scaling with sequence length directly enables practical context windows of 128K tokens and beyond, as seen in models like GPT-4 Turbo and Claude 3, by eliminating the quadratic memory bottleneck.
Speculative Decoding
An inference acceleration technique where a small draft model generates candidate tokens and a larger target model verifies them in parallel. FlashAttention's speed improvements in the attention computation directly benefit the target model's verification step, reducing the latency overhead of processing multiple candidate sequences simultaneously.

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