TensorLean Finds 38 GPU Kernel Bugs Through PTX Verification
A data race in FlashAttention-4 went undetected in 17,760 test runs. TensorLean later exposed it through formal verification. The method checks kernel behavior against a mathematical specification rather than relying on test coverage alone. The framework analyzes NVIDIA PTX, the intermediate representation generated during compilation, to check whether the compiled kernel meets its specification.
Researchers from Columbia University and CertiK built TensorLean to verify GPU kernels at the PTX level. Across 149 open-source kernel instances, it proved 83 correct. The evaluation included 102 FlashAttention kernels, along with kernels from other production libraries. It covered every kernel in FlashAttention-2, as well as FlashAttention-3, FlashAttention-4, and DeepGEMM. The project's TensorLean repository describes proofs of data-race freedom and termination, plus functional correctness within floating-point tolerance.
What the verifier checks
TensorLean starts with unmodified source code and a developer-written tensor specification in Lean. It checks four properties: freedom from data races, termination, output correctness within a stated tolerance, and protection of memory outside the intended output. The specification separates the mathematical operation from the kernel's memory layout and uses Lean's Mathlib. The proof applies to inputs that meet the specification's preconditions and to executions covered by the framework's model.
The framework parses PTX with a 1.8K-line parser, then uses a happens-before graph to reason about concurrency. Its race-freedom proofs symbolically cover every CTA and thread, across all loop iterations. For accumulating loops such as online softmax, loop invariants over semirings let the verifier use one SMT query per loop. Lean's kernel handles proofs alongside queries to Z3 and cvc5. The verification challenge also includes optimized operations, such as overlapping data transfers with computation and using lower-precision arithmetic.
Specifications total 10,278 lines, compared with 151,285 lines of kernel source, about 15 times less. TensorLean runs on a 16-core workstation and checks PTX compiled for A100, H100, and B200 kernels. The project reports a median check time of about 10 minutes. The maximum is 50 minutes.
What the evaluation found
FlashAttention accounted for 23 of the 38 reported bugs. The other projects were Liger Kernel with seven, TileOPs with three, TileLang with two, DeepGEMM with two, and Triton with one. The GitHub README says all 38 were reported upstream. A separate CertiK announcement highlighted findings from more than 100 production kernels, reporting two bugs in DeepSeek kernels and 23 in FlashAttention.
The project site classifies 19 bugs as memory access errors and 13 as numerical bugs. It also lists seven data races and five uninitialized memory reads. Undefined behavior accounts for five more. The counts overlap because a bug can fit multiple categories. Among 102 FlashAttention instances, 56 passed all four properties. Each of the other 46 failed a proof goal tied to a source bug. Listed FlashAttention issues include illegal memory accesses on NVIDIA's SM90 architecture involving paged key-value caches, as well as a FlashAttention-3 split-KV cross-CTA race associated with incorrect output and incorrect softmax_lse.
TensorLean's authors say symbolic parameters address a configuration-coverage gap with equivalence checkers such as Volta, which unroll loops for one concrete setup at a time. Formal verification has also been applied to software libraries. NerdsMagazine's coverage of library proofs described a separate effort using Claude and Rocq to check open-source code.