The Gist of It Logo
🧠 LLMs & ML ★ Impact 9.6/10 arXiv:2612.05654v1 • December 4, 2026 • 1 min read
📄 arXiv Preprint • Not Peer-Reviewed ✓ Full-Text Verified

How AI Gets Its First Proofreader for High-Speed GPU Code

Original paper: TensorLean: Formal Verification of Production GPU Kernels

Authors: Wei Qiang, Ganxiang Yang, Yi Rong, Ronghui Gu

TensorLean is a new formal verification framework that catches hidden bugs in high-performance GPU AI code before they silently corrupt models.
Figure 2: How Figure 1 ’s buggy apply_K_contiguous rotates and copies the (left,right) chunks from k_smem to k_cache , with r=D=80 and kHeadDim=96 . Green marks a correctly rotated pair with col=8 . Red marks the corrupting write into k_cache[head+1]...
Figure from paper: Figure 2: How Figure 1 ’s buggy apply_K_contiguous rotates and copies the (left,right) chunks from k_smem to k_cache , with r=D=80 and kHeadDim=96 . Green marks a correctly rotated pair with col=8 . Red marks the corrupting write into k_cache[head+1]...

"Just like an automated pressure-testing lab that floods a plumbing network with every possible combination of water surges to find hidden leaks before the pipes are installed, TensorLean builds a mathematical blueprint of a GPU kernel to simulate every possible thread schedule and input combination. It checks the entire system for data collisions and memory overflows, ensuring the code behaves perfectly under maximum load."

As trillion-parameter AI models demand massive compute clusters, a single silent bug in a GPU kernel can subtly corrupt training runs over weeks or quietly ruin inference accuracy in production. By mathematically proving code correctness across thousands of variations, TensorLean protects multi-million-dollar AI training clusters from invisible corruptions.

  • First framework to formally verify production GPU kernels.
  • Uncovered 66 unique unknown bugs across FlashAttention and DeepSeek.
  • Uses Lean 4 and SMT solvers to prove functional correctness.

How AI Gets Its First Proofreader for High-Speed GPU Code

▶ Watch on YouTube Shorts ↗

TensorLean: Formal Verification and Soundness Proofs for Production GPU Kernels

Key Contribution Over Prior Work

TensorLean bridges the gap between theoretical formal verification and production GPU software by decoupling tensor-level computations from PTX-level memory layouts. Unlike prior verifiers restricted to concurrency analysis alone or exact real equivalence for fixed shapes, TensorLean builds a symbolic happens-before graph over formalized PTX semantics to verify data-race freedom, termination, and floating-point round-off bounds across arbitrary inputs and schedules.

Core Methodology

TensorLean translates compiled PTX instructions via a formalized small-step operational semantics in Lean 4 covering 108 instruction families. It constructs a symbolic happens-before graph to verify data-race freedom and termination, uses a push/pull model to compute symbolic memory updates over exact reals $\mathbb{R}$ via SMT solvers (cvc5 and Z3), and inductively infers round-off error bounds to guarantee functional correctness within user-specified floating-point tolerances.

Theoretical Assumptions

The framework assumes that the formalized PTX semantics faithfully mirrors NVIDIA's PTX ISA specification, and it trusts the soundness of the Lean 4 proof assistant along with the cvc5 and Z3 SMT solvers. Furthermore, it assumes that the host-side environment satisfies specified precondition predicates ($ ext{requires}$) at launch and that developers provide accurate tensor-level specifications and assertion hints where automated inference times out.

Empirical Evaluation

Evaluated on 2,078 kernel instances covering all 143 kernels from FlashAttention-2, -3, and -4, DeepSeek DeepGEMM, and LinkedIn Liger Kernel, TensorLean successfully proved 1,180 instances correct. It uncovered 66 unique, previously unknown correctness bugs across 888 of the remaining instances within a prototype implementation comprising 80.7K lines of Lean 4 code.

Limitations & Edge Cases

Computational bottlenecks arise from SMT solver queries, managed via a 5-second per-query timeout, beyond which manual user-provided assertion hints are required. The trusted computing base (TCB) includes the ptxas compiler, hardware realization of the PTX ISA, and underlying solver implementations, leaving potential vulnerabilities outside the verified Lean 4 scope.

📑 Original arXiv Technical Abstract

GPU kernels are the computational core of modern AI, yet a single correctness bug can silently corrupt frontier models and ML frameworks, putting training and inference at risk. Formal verification promises correctness across all inputs, launch configurations, and schedules, but it has never reached production GPU kernels. We present TensorLean, the first framework to formally verify production GPU kernels. To reduce manual effort, TensorLean verifies the kernel's compiled PTX against tensor-level specifications that can be shared across kernels and their thousands of instances. Given the kernel's PTX, TensorLean builds a symbolic happens-before graph over formalized PTX semantics to capture all valid inputs, launch configurations, and concurrent schedules in a single run. On this graph, it first verifies data-race freedom and termination, thereby reducing concurrent executions to finite, sequential ones. It then uses a push/pull model to compute PTX memory updates and proves their functional correctness against the specification over reals with SMT solvers. Finally, TensorLean extends the correctness guarantee to the kernel's actual floating-point PTX via inductive round-off bound inference. For scalability, TensorLean further automatically infers tile-loop invariants and decomposes proof goals via user-provided assertion hints. We mechanize the PTX semantics and soundness proofs in Lean 4 and evaluate TensorLean on 2,078 kernel instances covering all 143 kernels in FlashAttention-2, -3, and -4, DeepSeek DeepGEMM, and LinkedIn Liger Kernel. It proves 1,180 instances correct and uncovers 66 unique, previously unknown correctness bugs in 888 of the remaining instances, all reported to developers.

✍️ Are you an author of this paper? Add code/demo links or a note

Help readers explore your work — share your official GitHub repo, Hugging Face weights, affiliation, or a clarification note for our editorial review queue.

𝕏 Share Your Paper's Gist on X

📬 Get daily LLMs & ML breakthroughs in your inbox

We scan hundreds of daily arXiv preprints across 6 frontier fields and send the top breakthroughs in plain English—with everyday analogies and 1-click PhD briefs. Free forever.

More Curated Breakthroughs

Hand-picked from the December 4, 2026 edition.