Inferensys

Glossary

FlashAttention

An IO-aware exact attention algorithm that minimizes high-bandwidth memory reads and writes by fusing operations in a single CUDA kernel, enabling efficient training of genomic models on extremely long DNA sequences.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
I/O-AWARE EXACT ATTENTION

What is FlashAttention?

An algorithm that computes exact self-attention with reduced memory I/O by tiling the computation and fusing operations into a single GPU kernel, enabling efficient training of genomic models on extremely long DNA sequences.

FlashAttention is an I/O-aware exact attention algorithm that computes the standard Transformer self-attention mechanism without approximation while significantly reducing reads and writes to GPU high-bandwidth memory (HBM). By tiling the attention matrix into blocks that fit in faster on-chip SRAM and recomputing the softmax normalization rather than storing the full intermediate matrix, it achieves substantial speedups and memory savings. This enables genomic language models to process long-range dependencies across hundreds of thousands of nucleotides without the quadratic memory bottleneck of standard attention implementations.

For genomic sequence analysis, FlashAttention directly addresses the challenge of modeling distal regulatory elements such as enhancer-promoter interactions that span vast genomic distances. The algorithm's fused CUDA kernel design minimizes data movement between memory hierarchies, making it practical to train DNA language models on sequences approaching megabase scale. When combined with architectures like the HyenaDNA model or integrated into Enformer-style genomic Transformers, FlashAttention provides the computational efficiency necessary to capture whole-gene and intergenic regulatory context that standard attention implementations cannot accommodate within typical GPU memory constraints.

IO-AWARE EXACT ATTENTION

Key Features of FlashAttention

An algorithm that accelerates the core self-attention mechanism by minimizing data movement between GPU memory hierarchies, making it essential for training genomic foundation models on extremely long DNA sequences.

01

IO-Awareness: Tiling the Computation

FlashAttention restructures the standard attention computation to minimize reads and writes to High Bandwidth Memory (HBM). Instead of materializing the full N×N attention matrix in slow HBM, the algorithm:

  • Tiles the Query, Key, and Value matrices into blocks that fit entirely within fast on-chip SRAM.
  • Computes softmax attention incrementally within each block.
  • Writes only the final output back to HBM, never storing the intermediate attention matrix.

This tiling strategy reduces HBM access by a factor proportional to the SRAM size, directly addressing the memory bottleneck that plagues long-sequence genomic modeling.

7.6x
Speedup over standard attention
02

Online Softmax with Rescaling

Standard softmax requires two passes over the data: one to find the maximum value for numerical stability, and another to compute the exponential sum. FlashAttention fuses these into a single pass using an online softmax algorithm:

  • Maintains running statistics (current max and sum) in SRAM as each block is processed.
  • When a new maximum is encountered, rescales the previously accumulated partial sum using a correction factor.
  • This ensures exact mathematical equivalence to the standard softmax while avoiding redundant HBM reads.

The result is a numerically stable, input-output exact attention computation that produces identical outputs to the naive implementation, but with dramatically lower memory footprint.

03

CUDA Kernel Fusion

Rather than launching separate GPU kernels for each operation (matrix multiply, softmax, dropout, masking), FlashAttention fuses the entire attention computation into a single CUDA kernel. This fusion:

  • Eliminates the overhead of launching multiple kernels and synchronizing between them.
  • Keeps intermediate data in registers and shared memory, never writing partial results to global memory.
  • Enables compiler optimizations that are impossible across separate kernel boundaries.

For genomic models processing sequences of 100,000+ nucleotides, this kernel fusion is the difference between out-of-memory failures and successful training runs on available GPU hardware.

04

Memory Complexity: O(N) Instead of O(N²)

The defining advantage of FlashAttention for genomic applications is its memory footprint. Standard attention allocates memory proportional to the square of sequence length (O(N²)), which becomes prohibitive for long DNA sequences. FlashAttention reduces this to linear O(N) by never storing the full attention matrix.

Practical implications for genomics:

  • Enformer-style models can process 200kb+ sequences without memory blowup.
  • Enables training on megabase-scale genomic contexts that capture distal enhancer-promoter interactions.
  • Makes whole-chromosome context feasible on a single GPU, unlocking regulatory grammar that spans vast genomic distances.
O(N)
Memory complexity
O(N²)
Standard attention complexity
05

Backward Pass Recomputation

During training, the backward pass typically requires the attention matrix to compute gradients. FlashAttention avoids storing this large matrix by recomputing it on-the-fly during the backward pass:

  • The forward pass stores only the softmax normalization statistics (a vector of size N), not the full N×N matrix.
  • During backpropagation, the attention matrix is recomputed block-by-block from the Q, K, V inputs.
  • This trades a modest increase in computation for a massive reduction in memory, enabling larger batch sizes and longer sequences.

This recomputation strategy is critical for genomic foundation models where sequence length, not model width, is the primary scaling axis.

06

FlashAttention-2: Parallelism and Work Partitioning

The second iteration of the algorithm introduced significant improvements in GPU utilization by addressing parallelism bottlenecks:

  • Reduced non-matmul FLOPs by restructuring the online softmax computation to better utilize Tensor Cores.
  • Improved work partitioning across thread blocks, distributing the computation more evenly along the sequence length dimension rather than the batch and head dimensions.
  • Forward pass speedup of approximately 2x over the original FlashAttention, bringing training throughput closer to the theoretical peak of the hardware.

For genomic models with many attention heads processing long sequences, FlashAttention-2's improved parallelism translates directly to faster epoch times and reduced training costs.

~2x
Speedup over FlashAttention v1
FLASHATTENTION EXPLAINED

Frequently Asked Questions

Core questions about the I/O-aware exact attention algorithm that enables efficient training of genomic foundation models on extremely long DNA sequences by minimizing high-bandwidth memory reads and writes.

FlashAttention is an I/O-aware exact attention algorithm that computes the standard attention mechanism without approximation while dramatically reducing the number of 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 reduction incrementally using a numerically stable online algorithm. The key insight is that the attention matrix is never fully materialized in HBM—instead, the query, key, and value blocks are loaded once, all intermediate computations (QK^T, softmax, weighted sum) are fused in a single CUDA kernel, and only the final output is written back. This kernel fusion eliminates redundant HBM accesses, reducing the memory footprint from O(N²) to O(N) in terms of HBM reads, where N is the sequence length. For genomic models processing 100,000-nucleotide sequences, this translates to training speed improvements of 2-4x and memory savings that enable processing sequences 8-16x longer than standard attention implementations.

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.