Inferensys

Glossary

FlashAttention

An IO-aware exact attention algorithm that minimizes reads and writes between GPU high-bandwidth memory (HBM) and on-chip SRAM, significantly accelerating the transformer attention mechanism.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
IO-AWARE EXACT ATTENTION

What is FlashAttention?

FlashAttention is an input/output-aware exact attention algorithm that dramatically accelerates the transformer self-attention mechanism by minimizing data movement between GPU high-bandwidth memory (HBM) and on-chip SRAM.

FlashAttention is an IO-aware exact attention algorithm that computes the standard attention function without approximation while significantly reducing reads and writes between GPU high-bandwidth memory (HBM) and faster on-chip SRAM. By fusing operations and tiling the computation into blocks that fit entirely within SRAM, it avoids materializing the full N×N attention matrix in HBM, which is the primary bottleneck in standard implementations. This yields wall-clock speedups of 2-4x and reduces memory consumption from quadratic to linear in sequence length.

The algorithm employs two key techniques: tiling to decompose the softmax computation into smaller blocks processed incrementally, and recomputation of the attention matrix during the backward pass rather than storing it from the forward pass. This trades additional FLOPs for drastically reduced I/O, aligning with the reality that modern GPU compute is abundant while memory bandwidth is the binding constraint. FlashAttention-2 and FlashAttention-3 further optimize this by improving work partitioning across thread blocks and exploiting newer hardware features like Hopper architecture TMA and FP8 support.

IO-AWARE EXACT ATTENTION

Key Features of FlashAttention

FlashAttention is an algorithm that accelerates the transformer attention mechanism by minimizing data movement between GPU high-bandwidth memory (HBM) and on-chip SRAM. It computes exact attention, not an approximation, while achieving significant speed and memory efficiency gains.

01

IO-Aware Tiling

The core innovation of FlashAttention is decomposing the attention computation into small tiles that fit entirely into on-chip SRAM. By fusing the softmax reduction across these tiles using a numerically stable online algorithm, the method avoids materializing the full N×N attention matrix in HBM. This reduces the number of high-latency HBM reads and writes from quadratic O(N²) to sub-quadratic, directly addressing the memory bottleneck that plagues standard attention implementations on long sequences.

O(N²)
Standard HBM Access
Sub-Quadratic
FlashAttention HBM Access
02

Exact Computation, Not Approximation

Unlike sparse or low-rank attention approximations that trade accuracy for speed, FlashAttention computes mathematically exact attention scores. The tiling and online softmax algorithm is numerically equivalent to the standard implementation, producing identical outputs up to floating-point precision. This guarantees no degradation in model quality or perplexity, making it a drop-in replacement that accelerates training and inference without requiring architectural changes or retuning hyperparameters.

Exact
Numerical Accuracy
03

Memory Footprint Reduction

Standard attention stores the intermediate N×N attention matrix for the backward pass, causing memory consumption to scale quadratically with sequence length. FlashAttention employs recomputation in the backward pass: it recalculates attention scores on-the-fly from the stored softmax normalization statistics rather than reading the full matrix from HBM. This reduces peak memory usage from O(N²) to O(N), enabling training with sequence lengths up to 8K or 16K tokens on hardware that would otherwise run out of memory.

O(N)
FlashAttention Memory
O(N²)
Standard Memory
04

Kernel Fusion for GPU Efficiency

FlashAttention is implemented as a single, highly optimized CUDA kernel that fuses multiple operations—matrix multiply, softmax, dropout, and masking—into one GPU pass. This eliminates the overhead of launching separate kernels and storing intermediate results in global memory. The fused kernel maximizes occupancy and arithmetic intensity by keeping data in registers and shared memory, achieving up to 7.6x speedup over standard PyTorch attention and approaching the theoretical peak throughput of modern NVIDIA GPUs.

7.6x
Max Speedup vs. Standard
05

FlashAttention-2: Parallelism Optimizations

The second iteration, FlashAttention-2, introduces critical work partitioning improvements. It parallelizes over the sequence length dimension rather than the batch and head dimensions, achieving higher GPU occupancy. It also reduces non-matmul FLOPs by optimizing the rescaling logic within the online softmax loop. These changes bring utilization closer to theoretical peak and deliver approximately 2x speedup over FlashAttention-1 on modern architectures like the H100 GPU, particularly for the forward pass.

~2x
Speedup over v1
06

FlashAttention-3: Hopper Architecture Exploitation

FlashAttention-3 is purpose-built for the NVIDIA Hopper GPU architecture (H100/H200). It leverages new hardware features such as WGMMA (Warp Group Matrix Multiply-Accumulate) instructions for asynchronous tensor core operations and TMA (Tensor Memory Accelerator) for hardware-accelerated data copying between global and shared memory. By overlapping computation with data movement using Hopper's asynchronous execution model, FlashAttention-3 achieves up to 1.5-2.0x speedup over FlashAttention-2 and reaches 740 TFLOPS on H100 GPUs, representing 75% of theoretical peak FP16 performance.

740 TFLOPS
H100 Throughput
75%
Theoretical Peak Utilization
FLASHATTENTION EXPLAINED

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the IO-aware exact attention algorithm that transformed transformer efficiency.

FlashAttention is an IO-aware exact attention algorithm that computes the standard transformer self-attention mechanism without approximation while dramatically reducing reads and writes between GPU high-bandwidth memory (HBM) and on-chip SRAM. It works by tiling the attention computation into blocks that fit entirely within SRAM, computing the softmax in a numerically stable incremental fashion using a running maximum and rescaling technique. Instead of materializing the full N×N attention matrix in HBM—which is quadratic in sequence length—FlashAttention fuses the entire attention operation into a single CUDA kernel, performing all computations on-chip before writing only the final output back to HBM. This reduces HBM access from O(N²) to O(N), yielding 2-4× wall-clock speedups and enabling training on sequences up to 64K tokens without approximation.

Prasad Kumkar

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.