Is a faster AI kernel still correct?
We built TensorLean with researchers at @CertiK and
@ColumbiaCompSci, the first framework to formally verify production GPU kernels with complex optimizations.
149 GPU kernel instances verified
38 bugs in total
2 in @deepseek_ai’s DeepGEMM
23 in FlashAttention
All proofs are developed in Lean and are machine-checkable. 👉 https://t.co/QmWpqR4u9o
The numbers can be a little confusing. We checked 149 production GPU kernel instances. Of those, 83 passed verification and met their Lean specs. We traced the issues in the other 66 instances to 38 distinct bugs across 6 libraries. A single bug can affect several kernel instances.
Is a faster AI kernel still correct?
We built TensorLean with researchers at @CertiK and
@ColumbiaCompSci, the first framework to formally verify production GPU kernels with complex optimizations.
149 GPU kernel instances verified
38 bugs in total
2 in @deepseek_ai’s DeepGEMM
23 in FlashAttention
All proofs are developed in Lean and are machine-checkable. 👉 https://t.co/QmWpqR4u9o
Data races depend on thread scheduling, and a test run only sees the schedules that happened to occur. TensorLean proves race freedom for all runtime shapes, inputs, and thread schedules, which is how it found a race in FlashAttention-4 that 17,760 test runs never hit.
A data race in FlashAttention-4 never showed up in 17,760 runs of its own tests. TensorLean found it with a proof instead.
They checked 149 production GPU kernel instances at the PTX level, proved 83 correct, and found 38 bugs the kernels' tests had missed.
@jus_eng_njainam Exactly. 19 of the 23 FlashAttention bugs only show up under specific combinations of shapes and features, so checking one configuration at a time misses them. TensorLean reasons symbolically about shapes and launch configurations, so one proof covers all of them.
I agree. A kernel rewrite can pass the same end-to-end evals even as its error bound grows for some inputs. We set the tolerance using the source library’s config and tests, then use TensorLean to check whether each version stays within it for all inputs.
A machine-checked proof of a GPU kernel only ties the code to whatever its specification allows, so the tolerance its authors chose carries the result. TensorLean ran formal verification over 100+ production GPU kernels and found 2 bugs in DeepSeek kernels and 23 in FlashAttention.
Those 23 say where I would look first. FlashAttention ships in constant flux, rewrite after rewrite, and a kernel can stay numerically close enough to pass an end-to-end eval while its error bounds drift. A spec that permits a loose bound leaves the drift invisible. Every proof ships in Lean and stays machine-checkable, so the tolerance argument continues in public.
Thanks for the questions, @yyw2000.
We chose PTX because it’s the lowest level in NVIDIA’s toolchain for which we have both published instruction semantics and a memory consistency model (PTX ISA §8). NVIDIA’s SASS reference lists instructions by architecture, but it doesn’t give us a comparable specification of their encodings, semantics, memory ordering, or hazard rules such as compiler-set stall counts. You are right that one way to extend the guarantee to SASS would be to validate each translation produced by ptxas.
On concurrency, our semantics models TMA, bulk async copies and reductions, cp.async, and mbarrier transaction counts. It also models tensor-core instructions such as mma.sync, wgmma, and tcgen05, as well as the warp specialization used in production kernels.
We build a happens-before graph that captures the ordering from named barriers, mbarriers, async-copy completion, and proxy fences. We prove in Lean that the graph construction is sound. For each kernel we verify successfully, we then prove race freedom and termination within our PTX model. Conflicting accesses are ordered, loops are bounded, and each wait receives the arrivals it needs without a cycle of waits. We also prove that the kernel meets its mathematical specification within the stated numerical tolerance. Note that we don’t yet model the ordering established by atomic flags.
Just two thoughts:
1. There’s still a gap between PTX and SASS. ptxas can restructure control flow and reorder instructions during optimization. These transformations should preserve semantics, but a PTX-level proof still relies on that compiler guarantee unless the lowering itself is verified or translation-validated.
2. The fidelity of the execution model matters. Lean checks the proof against the formalized semantics. How comprehensively do those semantics capture GPU weak memory ordering, asynchronous copies, and warp specialization? I’d be interested in which synchronization and forward-progress properties are proved, and which remain assumptions.
We chose PTX because it’s the lowest level in NVIDIA’s toolchain for which we have both published instruction semantics and a memory consistency model (PTX ISA §8). NVIDIA’s SASS reference lists instructions by architecture, but it doesn’t give us a comparable specification of their encodings, semantics, memory ordering, or hazard rules such as compiler-set stall counts. You are right that one way to extend the guarantee to SASS would be to validate each translation produced by ptxas.
On concurrency, our semantics models TMA, bulk async copies and reductions, cp.async, and mbarrier transaction counts. It also models tensor-core instructions such as mma.sync, wgmma, and tcgen05, as well as the warp specialization used in production kernels.
We build a happens-before graph that captures the ordering from named barriers, mbarriers, async-copy completion, and proxy fences. We prove in Lean that the graph construction is sound. For each kernel we verify successfully, we then prove race freedom and termination within our PTX model. Conflicting accesses are ordered, loops are bounded, and each wait receives the arrivals it needs without a cycle of waits. We also prove that the kernel meets its mathematical specification within the stated numerical tolerance. Note that we don’t yet model the ordering established by atomic flags.
✨ Faster AI still needs correct calculations.
@CertiK and @Columbia researchers report finding 25 bugs in @deepseek_ai and FlashAttention kernels. Their TensorLean system uses mathematical proofs to check the code behind AI.
https://t.co/tXbzySKwwY
@nearlypi I’d love to see this become part of everyday kernel development. Once you’ve written down the math a kernel should compute, you can reuse that spec to check the next optimization.
The part people will skip: it proves the compiled PTX, not the source, so it covers the code the GPU actually runs. And kernel bugs rarely crash anything. The job keeps going and quietly hands you wrong numbers, which is worse.
@ethanorbe@dravenip Good question! Of the 149 kernel instances we checked, 83 met their specs. The other 66 were affected by 38 distinct bugs. A single bug can show up in several kernel instances.
Introducing TensorLean: formal verification of production GPU kernels.
We verified the PTX of 149 kernel instances, including all kernels of FlashAttention-2, -3, -4, DeepGEMM, and more: 83 are proved correct, and the rest led us to 38 correctness bugs.
https://t.co/BPY29L7N1j 🧵
@senthazalravi@CertiK@ColumbiaCompSci@deepseek_ai We write the spec using PyTorch-style operations and can reuse it across kernels with different memory layouts. Overall, we wrote about 1 line of spec per 15 lines of kernel code.