Lean verifier finds 38 bugs in FlashAttention and DeepGEMM GPU kernels

Columbia University and CertiK built TensorLean, a Lean-based proof system that checked 149 GPU kernel instances and proved 83 of them correct.

AIVIO News Desk 2 min read
AIVIO News cover illustration for: Lean verifier finds 38 bugs in FlashAttention and DeepGEMM GPU kernels

Researchers from Columbia University and CertiK have built TensorLean, a tool that formally verifies GPU kernels at the PTX level, the low-level assembly code that Nvidia GPUs actually run. The team used it to check 149 kernel instances, covering every version of FlashAttention-2, -3 and -4 along with DeepGEMM. It proved 83 of those instances correct and turned up 38 correctness bugs in the rest.

TensorLean works from unmodified source code. A developer writes a math specification in Lean, a proof assistant, using operator names borrowed from PyTorch so that @ stands for matrix multiplication. The system then tries to prove four things about the compiled kernel: that no data race can occur, that the kernel terminates, that its output matches the spec within a stated tolerance, and that memory outside its target region is left untouched.

To check for races, TensorLean builds what the researchers call a happens-before graph covering every thread block, thread and loop iteration at once, rather than testing specific schedules. To check output correctness, it symbolically executes the kernel to compute a final memory state, then proves that state matches the spec regardless of how threads were scheduled. Proofs are discharged using Lean’s own proof checker alongside the SMT solvers Z3 and cvc5. Loops that accumulate results across tiles, such as the online softmax calculation inside FlashAttention, are handled with closed-form loop invariants that need only one solver query apiece.

The whole setup runs on a 16-core workstation and handles kernels compiled for A100, H100 and B200 GPUs. The specifications the team wrote came to roughly 10,000 lines, against roughly 150,000 lines of kernel source being checked, a specification far smaller than the code it verifies.

Of the 38 bugs, FlashAttention accounted for 23, Liger Kernel for 7, TileOPs for 3, TileLang for 2, DeepGEMM for 2 and Triton for 1, all reported upstream according to the project’s GitHub page. The bugs span memory access errors, numerical errors, data races, uninitialized memory reads, undefined behavior, algorithm errors, miscompilations and one deadlock, with some bugs falling into more than one category. Among 102 FlashAttention instances tested, 56 passed every proof and 46 failed on an underlying source bug. The team highlights one case in FlashAttention-4 where TensorLean caught a data race that had never surfaced across 17,760 test runs. The project also compares itself against other PTX-checking tools, including Volta and ProofWright, saying its main advantage is proving properties across symbolic kernel configurations rather than one fixed setup at a time.

What this means

The FlashAttention and DeepGEMM kernels checked here sit underneath a large share of current transformer training and inference, so bugs that survive thousands of test runs can persist unnoticed in widely deployed code. TensorLean’s results suggest formal proof can surface failure modes, like the uncaught FlashAttention-4 race, that conventional testing at scale does not reach.

What the source material does not establish is whether the 38 reported bugs have since been fixed in the upstream projects, or how the approach performs on kernels and GPU architectures beyond those tested. The comparison table lists check times from around 10 minutes at the median up to 50 minutes at the maximum, leaving open how the method would hold up against larger or more varied kernel codebases.

Sources

MarkTechPost