Formal Verification of Production AI Operators: Techniques and Engineering Practice

    This article explains why correctness issues in high-performance AI operators often appear as plausible but wrong outputs rather than crashes, and why traditional testing cannot cover the combinatorial space created by parallel execution, asynchronous data movement, and floating-point behavior. It walks through three key techniques—verifying at the compiled intermediate representation, modeling task mapping and asynchronous transfers, and proving floating-point error bounds—along with evaluation findings across compiled kernel instances and operator libraries. A practical framework for specifications, pipeline integration, defect closure, observability, and cloud support is also provided.

    1. Where the Problem Starts: How a Performance Optimization Produced Corrupted Output

    After a runtime speed optimization at a cloud provider, some inference services began behaving abnormally: answers to English questions contained fragments in other languages, and generated code contained syntax errors. The postmortem showed that the optimization had changed the underlying computation path, abnormally amplifying some extremely low-probability candidate tokens. The probability distribution was perturbed, and the output went out of control.

    This case highlights a key point: in high-performance AI systems, correctness problems often do not show up as crashes. They show up as “errors that look normal.” In conversational and code-generation scenarios, the result is a degraded user experience. If the same kind of distortion occurred in safety-critical settings such as autonomous driving or industrial control, a single incorrect probability value could invalidate a decision.

    2. Why Traditional Testing Is Not Enough

    Correctness of GPU kernels depends on three layers of complexity stacking together:

    • Parallel execution: the scheduling order of thread blocks and threads is not fixed, so race conditions and synchronization defects appear only under specific interleavings.
    • Asynchronous data movement: computation overlaps with transfers, making buffer lifetimes and dependencies hard to cover with sample inputs.
    • Floating-point arithmetic: non-associativity means summation order affects results, and errors require bounds rather than single-point comparison.

    Testing can only enumerate a finite set of inputs and a finite set of schedules, while the defect space above grows combinatorially. The value of formal verification is to replace exhaustive enumeration with mathematical proof, turning “probably fine” into “guaranteed to hold under a given specification.”

    3. Three Levels of Technical Progress

    3.1 Moving the Verification Target Down to the Compiled Intermediate Representation

    A kernel goes through multiple stages from source code to execution, so source-level verification can hardly reflect actual optimization behavior. Placing verification at the compiled intermediate representation layer directly covers the instruction sequence that is actually deployed, avoiding the blind spot of “correct in source, distorted after compilation.”

    3.2 Modeling Both Dynamic Task Assignment and Asynchronous Transfers

    The verification specification must explicitly describe the task mapping of threads and blocks, synchronization points, and the dependencies of asynchronous copies. Only then can it prove the absence of race conditions and out-of-bounds access, and prove that data is ready before computation begins.

    3.3 Providing Provable Bounds on Floating-Point Error

    The goal is not bit-for-bit equality. Instead, error upper bounds are provided for patterns such as reductions and matrix multiplication, proving that results fall within an acceptable range. This allows performance optimization and numerical reliability to hold at the same time.

    Illustrative specification structure (pseudocode):

    1. -- For each compiled instance, prove: correct synchronization + no out-of-bounds + bounded error
    2. theorem kernel_correct (x : Tensor) :
    3. (NoRace schedule) ∧
    4. (InBounds indices) ∧
    5. (‖ result x - reference x ‖ ≤ ε) := by
    6. sorry -- to be filled with a machine-checked proof

    4. What the Evaluation Results Show

    Researchers evaluated 149 compiled kernel instances across GPU architectures of different generations. 83 instances passed their corresponding specifications on the first attempt, while 66 were found to have defects, accounting for about 44.3% of the sample. Across 6 operator libraries, 38 correctness issues were discovered, covering widely used implementations such as high-performance matrix multiplication and attention computation. A single defect could affect multiple compiled instances.

    The engineering implication of this data is that the proportion of latent correctness issues in high-performance operators is not low, and defects are reproducible across instances. A point fix is not enough to cover them; continuous, specification-centered verification is needed.

    5. A Practical Framework

    1. Build specification assets: accumulate reusable specification templates for patterns such as reductions, matrix multiplication, and attention.
    2. Integrate into the pipeline: compiled artifacts automatically trigger verification, and a failure blocks the release.
    3. Close the defect loop: attribute issues to three categories—synchronization, bounds, and error—and after fixing, regress all affected instances.
    4. Add observability as a fallback: combine logging services with monitoring and alerting, and set online sentinels for probability distribution drift.
    5. Cloud support: use container platforms and object storage to manage verification tasks and proof artifacts, achieving elasticity and reproducibility.

    6. Conclusion

    Formal verification moves AI’s underlying computation from “test-driven” to “proof-driven.” For developers, introducing specifications and error bounds at the compiled level as early as possible is a key step toward building highly trustworthy, high-performance operators.