Verified Lifting of Deep learning Operators

Qi Zhan, Xing Hu, Xin Xia, Shanping Li · DOI

Abstract

Deep learning operators are fundamental components of modern deep learning frameworks. With the growing demand for customized operators, it has become increasingly common for developers to create their own. However, designing and implementing operators is complex and error-prone, due to hardware-specific optimizations and the need for numerical stability. There is a pressing need for tools that can summarize the functionality of both existing and user-defined operators. To address this gap, this work introduces a novel framework for the verified lifting of deep learning operators, which synthesizes high-level mathematical formulas from low-level implementations. Our approach combines symbolic execution, syntax-guided synthesis, and SMT-based verification to produce readable and formally verified mathematical formulas. In synthesis, we employ a combination of top-down and bottom-up strategies to explore the vast search space efficiently; In verification, we design invariant synthesis patterns and leverage SMT solvers to validate the correctness of the derived summaries; In simplification, we use egraph-based techniques with custom rules to restore complex formulas to their natural, intuitive forms. Evaluated on a dataset of deep learning operators implemented in Triton from the real world, our method demonstrates the effectiveness of synthesis and verification compared to existing techniques. This framework bridges the gap between low-level implementations and high-level abstractions, improving understanding and reliability in deep learning operator development.

Introduction

Deep learning (DL) operators—the fundamental building blocks like Softmax, ReLU, or Attention—are increasingly being customized by developers to maximize hardware performance. However, these implementations are notoriously difficult to read and verify. To achieve high performance and numerical stability, GPU experts employ complex techniques such as tiling, operator fusion, and specialized mathematical tricks (e.g., subtracting the maximum value in a Softmax to prevent overflow).

The result is a significant "semantic gap": the low-level code looks nothing like the textbook math it represents. This makes it incredibly difficult for developers to verify if a new, optimized operator is actually doing what it’s supposed to do. Existing tools mostly focus on finding bugs via black-box testing rather than formally proving that the code matches a high-level mathematical specification. This paper introduces a framework to bridge this gap by "lifting" low-level code into verified mathematical formulas.

Methodology

The proposed framework utilizes a three-phase pipeline to transform low-level code into clean, verified mathematical summaries.

The three-phase pipeline for verified lifting: Synthesis, Verification, and Simplification.

1. Synthesis

The framework first uses symbolic execution on a small, bounded version of the operator to extract a specification. It then employs a "divide-and-conquer" synthesis strategy. It uses a top-down search to break the problem into smaller sub-problems based on the structure of the symbolic output, and a bottom-up search with pruning to fill in the gaps. This structure-aware approach prevents the search space from becoming unmanageable.

2. Verification

To prove the formula works for tensors of any size (unbounded), the framework uses Hoare logic and SMT solvers (Z3). The core innovation here is a set of invariant synthesis patterns. Since many DL operators follow a pattern where different threads perform the same task on different data chunks, the authors designed templates to help the SMT solver find loop invariants much faster.

3. Simplification

Highly optimized code often contains "noise" added for numerical stability. The framework uses e-graphs (specifically the egglog tool) and equality saturation to apply rewrite rules. This effectively "de-optimizes" the formula back into its most intuitive, readable form. For example, it can turn a stable Softmax implementation back into the standard textbook equation by applying algebraic identities.

An example of formula simplification using equality saturation to recover the standard Softmax form.

Evaluation

The framework was evaluated on a benchmark of 33 real-world DL operators collected from Triton tutorials, FlagGems (a library of high-performance operators), and Liger-Kernel (optimized kernels for LLM training). The operators span three categories: Activation functions (like GeLU and Sigmoid), Fused kernels (like Flash Attention), and Foundation kernels (like Matrix Multiplication).

Key Results

  • Superior Coverage: The framework successfully synthesized 32 out of 33 operators and formally verified 28 of them. In contrast, the baseline tool (Tenspiler) could only synthesize 13.
  • Efficiency: For the operators both tools could handle, the proposed framework was consistently faster.
  • Ablation Success: The study showed that the top-down synthesis strategy was critical, improving the synthesis success rate by 88%. The specialized verification patterns improved the verification success rate by 75%.
  • Real-World Utility: The tool successfully recovered the standard mathematical forms for complex operators like GeLU and LogSoftmax, even when the source code was heavily optimized for stability.

Discussion and Limitations

While the framework represents a significant step forward, several limitations remain. The current version requires some manual annotations for argument types and tensor shapes to facilitate symbolic execution. Furthermore, the tool currently excludes operators involving complex indexing, masking, or embedding, which are harder to describe with pure mathematical formulas.

Future work will focus on extending the framework to support backward passes (gradient calculations) for full training pipeline support and addressing SMT bottlenecks for extremely complex kernels like Matrix Multiplication and Flash Attention, where generated invariants can still overwhelm current solvers.

Summary updated

Abstract

Deep learning operators are fundamental components of modern deep learning frameworks. With the growing demand for customized operators, it has become increasingly common for developers to create their own. However, designing and implementing operators is complex and error-prone, due to hardware-specific optimizations and the need for numerical stability. There is a pressing need for tools that can summarize the functionality of both existing and user-defined operators. To address this gap, this work introduces a novel framework for the verified lifting of deep learning operators, which synthesizes high-level mathematical formulas from low-level implementations. Our approach combines symbolic execution, syntax-guided synthesis, and SMT-based verification to produce readable and formally verified mathematical formulas. In synthesis, we employ a combination of top-down and bottom-up strategies to explore the vast search space efficiently; In verification, we design invariant synthesis patterns and leverage SMT solvers to validate the correctness of the derived summaries; In simplification, we use egraph-based techniques with custom rules to restore complex formulas to their natural, intuitive forms. Evaluated on a dataset of deep learning operators implemented in Triton from the real world, our method demonstrates the effectiveness of synthesis and verification compared to existing techniques. This framework bridges the gap between low-level implementations and high-level abstractions, improving understanding and reliability in deep learning operator development.
BibTeX
@misc{zhan2024verified,
  author = {Qi Zhan and Xing Hu and Xin Xia and Shanping Li},
  title = {{Verified Lifting of Deep learning Operators}},
  year = {2024},
  eprint = {2412.20992},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.20992},
}
Figure