Researchers from Columbia University and CertiK have introduced TensorLean, a formal verification framework designed for compute kernels running on graphics processing units (GPUs), at the PTX level, meaning the code produced after compilation. Applied to 149 kernel instances, the tool proved 83 of them correct and led to the identification of 38 bugs.
How TensorLean Works
TensorLean is a verifier based on Lean, a mathematical proof assistant. It starts from unmodified source code: the developer writes a specification at the tensor level, then the tool proves four properties, namely the absence of data races, program termination, a correct result within a given tolerance, and the absence of memory modification outside the intended area.
The process involves seven steps: compilation to PTX, construction of a so-called “happens-before” graph to verify data races and termination, symbolic execution to obtain the final memory state, then proofs discharged to the Lean kernel, and to Z3 and cvc5, two automated solvers. Specifications rely on the Mathlib library, and tensor operators reuse PyTorch names, so the @ symbol corresponds to torch.matmul.
Several techniques allow scaling, according to the source. Proofs of race-freedom symbolically cover all blocks, threads, and loop iterations. Loop invariants, used for example for online softmax, require only one SMT query per loop. Developers can also add assertions in the code, which are proved once and then reused.
The source indicates that the tool runs on a 16-core workstation and verifies PTX compiled for A100, H100, and B200 architectures. The specifications total 10,278 lines, for 151,285 lines of kernel code, a ratio close to 15 to 1. The PTX parser comprises 1.8K lines.
The Identified Bugs
According to the GitHub repository README, all 38 bugs were reported upstream to the relevant project maintainers. FlashAttention accounts for 23, Liger Kernel 7, TileOPs 3, TileLang 2, DeepGEMM 2, and Triton 1. Out of 102 FlashAttention instances, 56 passed all four properties, while the other 46 failed on a proof goal related to a bug in the source code.
The project website classifies these bugs into 19 memory access errors, 13 numerical bugs, 7 data races, 5 reads of uninitialized memory, 5 undefined behaviors, 3 algorithm errors, 2 miscompilations, and 1 deadlock. A single bug can appear in multiple categories. According to the source, TensorLean also detected a data race in FlashAttention-4 that did not appear in any of the 17,760 test runs.
A Comparison with Other Tools
The source compares TensorLean to other GPU kernel verifiers, including Volta, ProofWright, and PTX in Lean. According to TensorLean, the main difference with Volta lies in configuration coverage: equivalence verifiers unroll loops for one concrete configuration at a time, whereas TensorLean uses symbolic parameters. The project website also reports a median verification time of about 10 minutes and a maximum of 50 minutes.
