inference-efficiency · 2026-12-05 · Tier 1

TensorLean: proving production GPU kernels correct

TensorLean: proving production GPU kernels correct

TL;DR. TensorLean formally verifies production GPU kernels from compiled PTX against tensor-level specifications: data-race freedom and termination first, then SMT proofs of memory updates over reals, then floating-point round-off bounds, with semantics in Lean 4. On 2,078 instances of all 143 kernels in FlashAttention-2/3/4, DeepGEMM and Liger Kernel it proves 1,180 correct and finds 66 unique previously unknown bugs.

Check the compiled code against the math it claims to do
Ruling out races first turns a parallel program into a sequential one.
flowchart LR
  P["Compiled PTX<br/><small>GPU assembly</small>"] --> G["Ordering graph<br/><small>all schedules at once</small>"]
  S["Tensor spec<br/><small>the intended math</small>"] --> M
  G --> R["Race check<br/><small>plus termination</small>"]
  R --> M["Solver proof<br/><small>memory matches spec</small>"]
  M --> E["Rounding bound<br/><small>real floating point</small>"]
  E --> OK["Proved<br/><small>1,180 instances</small>"]
  M --> B["Bugs<br/><small>66 unique found</small>"]
  classDef input fill:#d0ebff,stroke:#1971c2,color:#1b1b1b,stroke-width:2px
  classDef core fill:#e5dbff,stroke:#6741d9,color:#1b1b1b,stroke-width:2px
  classDef loop fill:#fff3bf,stroke:#f08c00,color:#1b1b1b,stroke-width:2px
  classDef exit fill:#d3f9d8,stroke:#2f9e44,color:#1b1b1b,stroke-width:2px
  classDef err fill:#ffe3e3,stroke:#e03131,color:#1b1b1b,stroke-width:2px
  class P,S input
  class G,M core
  class R,E loop
  class OK exit
  class B err
  linkStyle 5 stroke:#2f9e44,stroke-width:2px
  linkStyle 6 stroke:#e03131,stroke-width:2px
Blue is the code and its spec, purple is reasoning, amber is safety checks, green is proved, red is broken.

Of the kernels behind FlashAttention and DeepGEMM that could not be proved, the tool turned up 66 distinct bugs nobody had reported.

What is it about? A GPU kernel is a small program that does the heavy math. TensorLean tries to prove that it is correct for every input.

What problem does it solve? Tests cover only some inputs and some thread timings. A wrong kernel can silently corrupt a model.

What's the core novelty? It works on PTX (the compiled GPU assembly), not the source. It first proves there are no data races and the kernel finishes. Then it checks the memory writes against a tensor-level description of the intended math, and bounds floating-point rounding error. The semantics are written in Lean 4, a proof language.

Key takeaways

  • Evaluated on 2,078 kernel instances covering all 143 kernels in FlashAttention-2, 3 and 4, DeepSeek DeepGEMM and LinkedIn Liger.
  • 1,180 instances proved correct.
  • 66 unique, previously unknown correctness bugs across the rest, all reported to developers.
  • One specification can be shared across many instances of a kernel.

Gaps in the study A large share of instances is neither proved nor shown broken. The abstract does not rank bug severity or say how many maintainers confirmed.

Industrial implication Agents now write kernels. On 12-04 Hedra reported agent-written fused kernels on AMD, and the KernelShift study (11-25) found agents fail on new tile programming models. A proof step in kernel CI is the natural counterweight. A feed post describing GPU assembly being checked in Lean is circulating, though its link was not resolved.

Relation to prior wiki pages

  • First formal-verification result on the kernel page; counterweight to agent-written kernels (serving shorts 12-04).
  • Complements KernelShift (11-25, agents fail on new tile programming models): correctness is the other half of that problem.

Links: Paper Concepts: gpu-kernels Raw source: raw/huggingface/2026-12-04-tensorlean-formal-verification-of-production-gpu-kernels.md