首页文章详情

For the first time globally, multiple production-grade AI operators of DeepSeek and FlashAttention have obtained formal verification.

机器之心2026-11-23 09:56
A reliability breakthrough has been achieved in the underlying computing of large models, breaking the garbled text dilemma of Claude.

In August 2025, some Claude users encountered a strange anomaly.

Even when they asked questions in English, Thai text suddenly popped up in the responses; when they prompted it to write code, obvious syntax errors appeared in the generated programs. For affected users, the large language model seemed to suddenly go "out of control".

Anthropic later explained in its post-mortem that a runtime optimization intended to speed up operations affected some of its TPU servers.

The Claude API failure timeline released by Anthropic. The middle line marks the output anomaly described in the text: it emerged on August 25, and the relevant optimization was rolled back on September 2. Source: Anthropic, September 17, 2025.

A simple performance optimization accidentally introduced computational errors, disrupting the model's normal probability distribution. Some tokens that were almost impossible to be selected originally obtained abnormally high probabilities, making the model's output chaotic and unpredictable.

In scenarios of chatting and code writing, the consequence of underlying computational errors is garbled text output that undermines user experience. But what if we shift the scenario to autonomous driving systems? Once the same output distortion occurs at a critical moment, for example when the system should hit the brakes, an incorrect probability value could cause the system to fail and endanger safety.

When algorithms face a "trust crisis" and traditional testing methods cannot exhaust all possible errors, researchers naturally turn to a direction that has been developed for many years in the fields of mathematics and computer science — Formal Verification.

However, the difficulty of truly introducing this capability into the underlying computation of modern AI systems far exceeds imagination. GPU kernels involve complex parallel execution, floating-point arithmetic and hardware optimization. Large-scale formal verification of high-performance operators deployed in practice has long been a challenging problem.

Now, this long-standing problem has seen new breakthroughs.

On November 20, CertiK and researchers from Columbia University jointly announced TensorLean. This is the world's first attempt to perform mathematical proof and verification on production-level GPU code (PTX) compiled from AI operators, taking into account how tasks are dynamically allocated, how data is transmitted asynchronously, and how much error floating-point arithmetic produces, to verify whether the actual calculation meets expectations.

The research team evaluated 149 compiled GPU kernel instances, 83 of which passed the corresponding Lean specifications in the first verification. Defects were found in the remaining 66 instances, accounting for 44.3% of the evaluated samples.

This research covers GPU architectures of different generations, involving DeepSeek's DeepGEMM and the widely used FlashAttention operator library. The team discovered a total of 38 correctness issues across 6 libraries, 2 of which came from DeepSeek's DeepGEMM and 23 from FlashAttention. A single defect may affect multiple compiled instances.

Let's take a detailed look at TensorLean's breakthrough technical achievements.

Tensor-level Formalization

TensorLean's technical breakthroughs are concentrated in three dimensions.

First, verification is performed at the PTX code level.

A GPU kernel goes through multiple processes from development to execution. Developers first write source code in high-level languages such as CUDA C++, then compile it into an intermediate instruction called PTX (Parallel Thread Execution), which is finally converted by NVIDIA's assembler into machine code directly executed by GPU hardware.

In this process, the compiler performs a large number of "translation optimizations" on the source code: rearranging instruction order, merging duplicate calculations, adjusting data storage methods, etc. These optimizations usually make programs run faster, but they may also introduce errors during the translation process. That is to say, the source code written by the developer is correct, but the actual executable code generated after compilation may be wrong.

If traditional verification only checks the source code, it will miss problems introduced by the compiler. TensorLean chooses to directly verify the compiled PTX instructions.

To achieve this, the team built a complete PTX semantic model in the Lean theorem prover, accurately describing the GPU's floating-point arithmetic rules, Tensor Core operation rules, inter-thread memory synchronization mechanisms, asynchronous data copying and other behaviors in mathematical language, and implemented a parser with approximately 1,800 lines of code that automatically converts compiled PTX into a formal representation available for mathematical reasoning. The proof is completed in Lean and can be verified by machines.

Second, automatically handle the core difficulties in GPU execution.

The first difficulty is concurrency. A GPU kernel usually runs hundreds of threads at the same time, each performing part of the calculation, and also exchanging data and waiting for each other at specific moments. Directly reasoning about the behavior of all threads under all possible scheduling scenarios is almost infeasible. For example, in FlashAttention-4, two groups of threads take turns using the same temporary storage. Calculations can proceed normally only when the next group starts writing after the previous group finishes reading. If the next group writes a little earlier, the previous group may read overwritten data. The team ran a set of related tests 17,760 times on an H100, and never observed this error discovered by TensorLean even once.

TensorLean's processing method is "role-based classification and representative selection". In most kernels, threads only play a few types of roles, for example, some are responsible for moving data while others are responsible for calculation. TensorLean groups threads by their roles, and only analyzes one "representative thread" for each group, so that a single analysis covers the behaviors of all threads in the group.

What about the interactions between groups? TensorLean constructs a "precedence graph" to record which operations are guaranteed to complete before which other operations. TensorLean can automatically prove two points. First, two threads will not read and write the same memory block at the same time without synchronization protection, so there is no data conflict. Second, all threads can complete normally and no deadlock exists. Once these two properties are proven, the analysis results of each group can be safely combined.

The second difficulty is dynamicity. In production-level kernels, the number of loop executions and which data each thread processes are only determined at runtime, varying with the size of the input tensor and hardware configuration. If verification is only performed for a specific set of parameters, the scope of the proof will be too narrow.

TensorLean uses loop invariant technology to prove by mathematical induction that "no matter how many times the loop executes, a certain property always holds after each round", thus covering all possible parameter combinations at once. There is no need to run tests separately for each length and batch size.

The third difficulty is floating-point precision. Operations in mathematical formulas are precise, but floating-point calculations on GPUs have rounding errors. Worse still, floating-point addition does not satisfy the associative law. If you directly compare the floating-point output of the kernel with the mathematical formula, the computational complexity of verification will grow exponentially with the number of operations, which is completely infeasible.

TensorLean designed a two-step verification method. First, it introduces an "intermediate reference", which assumes that the GPU executes the same sequence of instructions using precise real numbers to obtain an ideal result. The first step is to prove that this ideal result is completely consistent with the mathematical specification, eliminating all errors at the algorithm level. The second step is to calculate the upper bound of accumulated rounding errors between the actual floating-point operation and the ideal result. Combining the two steps, it can be proven that the deviation between the actual output of the kernel and the mathematical specification is within the acceptable tolerance range.

Third, reduce the cost of writing verification specifications.

Formal verification has a long-standing historical problem: the cost of writing "specifications" is extremely high. Because it not only needs to describe the mathematical operation itself, but also needs to describe how data is stored in GPU memory. The seL4 microkernel only has about 8,700 lines of C code, but its verification took 20 person-years and 200,000 lines of proof.

TensorLean separates the mathematical calculation logic from the underlying memory layout, allowing researchers to write specifications at a higher abstraction level.

Specifically, the specification of a kernel is split into four independent parts:

  • spec_math: what the kernel should calculate, described with pure tensor operations
  • spec_machine: what changes the kernel leaves in GPU memory
  • Layout: how each tensor is stored in memory, that is, the mapping rule from elements to memory addresses
  • Constraints: additional constraint conditions for inputs and outputs

With mathematics and memory separated, researchers only need to focus on the mathematical logic at the tensor level when writing specifications, without worrying about the underlying byte layout. TensorLean automatically translates the tensor-level specification into a PTX-level specification.

This decoupling also brings reusability advantages. The mathematical logic of the same type of operations is mostly similar, and the differences mainly lie in the memory layout. The mathematical part can be reused, and only the description of the memory layout needs to be supplemented for each specific implementation.

The team wrote mathematical specifications for 72 open-source kernels. They total 151,285 lines of source code, corresponding to 10,278 lines of specifications, at a ratio of approximately 15:1.

Operator Verification for FlashAttention and DeepSeek

In practical verification, the team completed formal verification of 27 DeepSeek-related kernels. The team also inspected all 37 source code kernels from FlashAttention-2 to FlashAttention-4, totaling 102 compiled instances. One source code kernel can compile multiple instances under different configurations.

FlashAttention has gone through four generations of iterations over four years, spanning from the Ampere to the Blackwell architecture, and each generation represents the optimal implementation of the attention kernel at its time. As the de facto standard attention operator, FlashAttention has been widely deployed in mainstream frameworks such as PyTorch, vLLM, and SGLang, supporting the training and inference services of a large number of large language models.

This core status means that any correctness defect in FlashAttention may affect every model running on these systems.

These 37 source code kernels cover three generations of GPU architectures: Ampere, Hopper and Blackwell, totaling 55,910 lines of source code. The team used 6,242 lines of specifications to describe the calculation requirements they should meet.

Eight Categories of Correctness Defects

End-to-end formal verification, covering from mathematical specifications all the way to the compiled PTX instructions, enables TensorLean to capture a wide range of correctness defects. The research team classified the discovered defects into eight categories.

  • Algorithm implementation error. The kernel code deviates from the expected algorithm, such as wrong formulas, incorrect conditional judgments, and unhandled special cases. This type of problem has nothing to do with floating-point precision or memory access, and the algorithm logic implemented by the kernel itself is wrong.
  • Numerical defect. Insufficient precision or numerical range, or numerical instability. This type of kernel is correct under ideal real arithmetic, but will make mistakes under finite-precision floating-point arithmetic.
  • Uninitialized memory. The kernel reads the shared memory before initializing it, or some output locations are not written. This will lead to wrong calculation results or trigger non-deterministic control flows.
  • Memory access error. The memory layout or distributed layout of the tensor is incorrect, or boundary checks are missing, resulting in out-of-bounds access and memory corruption.
  • Data race. Two threads access the same global or shared memory address, at least one of which is a write operation, and there is no barrier or fence to order them. Such races can silently corrupt the output tensor without any error reports.
  • Deadlock. Threads form a circular wait. The consequence is that the kernel hangs and cannot complete the calculation.
  • Compilation error. Kernel compilers such as NVCC, Triton, or CuTe DSL compile correct source code into incorrect executable code. Since TensorLean performs verification at the PTX level, all errors introduced by the compiler are within the scope of inspection.
  • Undefined behavior. Certain operations exceed the scope specified by the language or instructions, so the running result of the program is not guaranteed.

The left chart compares the source code and specification lines of each kernel in FlashAttention-3, and the right chart summarizes the data of FlashAttention-2, -3 and -4. Source: Figure 6 on TensorLean's official website.

Some of these defects were exposed during the specification writing phase: when researchers tried to precisely define the expected behavior of the kernel in mathematical language, they found that there was a deviation between the actual implementation and the mathematical definition.

Other defects were discovered during the automated proof process — the prover could not complete the proof on some execution paths. After further investigation, researchers confirmed that the problem lay in the kernel implementation itself. At present, all discovered defects have been fixed and reported to relevant developers.

Even widely trusted and deployed kernel implementations may have various correctness hidden dangers that have not been fully detected.

Traditional testing can only verify the correctness of programs through limited input samples, and it is difficult to exhaust all boundary conditions and execution paths. Through formal verification, TensorLean provides mathematical-level correctness guarantees for all possible inputs within the scope defined by the specifications, elevating the reliability guarantee of kernels from empirical testing to the level of strict mathematical proof.

When Formal Verification Meets AI Computing

Formal verification is not a new technology.

As early as more than 20 years ago, Airbus introduced formal methods into flight control software development. In the chip design field, after experiencing the Pentium FDIV incident, Intel deeply embedded formal verification into its processor R&D process. In the operating system field, researchers completed the full functional correctness proof for the seL4 microkernel, which took about 20 person-years and remains a landmark case in the field of formal verification to this day.

These cases prove that formal verification has long demonstrated its value in fields that have extremely high requirements for correctness and reliability. For AI systems with increasingly larger scale, increasingly complex calculation processes, and underlying errors that may be amplified layer by layer, formal verification obviously has broader application space.

The investment in a cutting-edge large model training can be as high as hundreds of millions of dollars, and inference services support the daily use of hundreds of millions of users. At the bottom of these huge systems are tens of thousands of GPU kernels, responsible for executing basic operations such as matrix multiplication, attention calculation, and normalization.

To squeeze the ultimate performance of hardware, engineers need to highly optimize these computing kernels for different GPU architectures. Every link including data layout, thread scheduling, calculation precision, and memory access methods may undergo complex engineering modifications.

This also means that the code finally running on the GPU is separated from the familiar mathematical formulas by multiple layers of optimization and transformation. Any subtle error may be amplified in large-scale calculations.

Researchers at the University of Michigan once recorded a kilocaliber training accident. A vision-language model was trained for more than 3,000 steps before the monitoring indicators gave an alarm. Engineers conducted repeated experiments and replaced kernels, but failed to find the