Effective random test generation for deep learning compilers

Luyao Ren, Ziheng Wang, Li Zhang, Guoyue Jiang, Yingfei Xiong, Tao XieScience China Information Sciences 2023

TL;DR

Deep learning compilers are crucial for deploying AI models efficiently, but testing them is challenging due to the complexity of generating valid inputs. This paper introduces Isra, a novel approach that uses a domain-specific constraint solver to generate semantically valid deep learning models for testing, significantly outperforming existing methods and discovering numerous previously unknown bugs.

What Problem Does This Paper Address?

Deep learning (DL) models are becoming increasingly complex, necessitating specialized compilers to optimize their execution on diverse hardware like GPUs and TPUs. These DL compilers are critical for the performance and deployment of countless AI applications. However, testing these compilers is a significant challenge. A popular testing technique, random testing, struggles to generate inputs (DL models) that are not only syntactically correct but also semantically valid – meaning they adhere to the underlying mathematical and structural specifications of DL operations. Generating semantically valid inputs is difficult because DL models can be represented as complex computation graphs with intricate constraints on tensor shapes and operation attributes. Existing methods often generate simple models or have a low probability of producing valid complex ones, wasting significant testing resources.

Methods

The core of Isra is a novel domain-specific constraint solver designed to tackle the challenges of generating semantically valid DL models. Instead of treating semantic specifications as a black-box checker, Isra explicitly models them as logic constraints. The generation process is framed as finding solutions to these constraints.

Isra employs an instantiation-based constraint solving approach, which iteratively assigns values to variables within the constraints. Key to its effectiveness are two strategies:

  1. Graph-level constraint resolving: This strategy follows a topological order of operations within the computation graph. It instantiates operations one by one, focusing on their types and the number of incoming edges. Constraints are rewritten to express outputs as functions of inputs and attributes, simplifying the problem.
  2. Operation-level constraint resolving: For each operation, Isra instantiates its type, attributes, and input tensors. It uses a carefully designed instantiation order for variables related to tensor structures and attributes. This order is crucial for eliminating quantifiers and unknown functions, transforming complex first-order logic into decidable propositional logic.

A key insight is that by following a specific instantiation order, Isra can simplify constraints and resolve them without backtracking, ensuring both soundness (generated inputs are valid) and completeness (no loss in the probability of generating any valid model).

Datasets

The paper does not introduce new datasets for training. Instead, it uses existing popular real-world deep learning compilers as the subjects for its evaluation. The computation graphs are constructed based on the ONNX standard.

Key Insights and Ideas

  • Semantic specifications as constraints: Framing DL model semantics as explicit logic constraints is a powerful way to guide test generation, moving beyond simple syntactic validity.
  • Backtrack-free constraint solving: The designed instantiation order is critical for simplifying complex DL model constraints, enabling efficient, backtrack-free solving. This is a significant improvement over traditional CSP solvers that often rely on backtracking.
  • On-demand tensor instantiation: Isra intelligently reuses existing tensor structures or creates new ones as needed, contributing to the generation of diverse and complex models.
  • Practical bug detection: The effectiveness of Isra is not just theoretical; it has been proven by its ability to discover a substantial number of previously unknown bugs in widely used DL compilers.

Key Results

  • Effectiveness: Isra significantly outperforms five baselines (including state-of-the-art approaches like Muffin and NNSmith) in generating valid test inputs, particularly in terms of coverage metrics.
  • Efficiency: Isra is considerably more efficient, with much lower execution times compared to baselines that rely on external constraint solvers or extensive mutation.
  • Bug Detection: Isra successfully detected 33 unique bugs across TVM, Glow, and SophGo compilers.
  • Novel Bugs: A remarkable 24 of these detected bugs were previously unknown, with 19 confirmed and 16 already fixed by developers, highlighting the practical value and impact of Isra. Developer feedback indicates that the generated bugs were "excellent real bugs" and easy to replicate.

Limitations and Future Work

  • False Positives: While Isra aims for soundness, the paper acknowledges that differential testing (one of its oracles) can introduce false positives due to floating-point inaccuracies. However, they mitigate this by using a high relative error tolerance (10%), and their evaluation did not find false positives caused by this.
  • Future Work: The paper suggests that Isra's approach is scalable and could be beneficial for other scenarios, such as generating extreme test cases for stress testing. The authors also note that their approach is complementary to other techniques like mutation-based fuzzing and disruptive generation.

Summary updated

BibTeX
@article{ren2023effective,
  author = {Luyao Ren and Ziheng Wang and Li Zhang and Guoyue Jiang and Yingfei Xiong and Tao Xie},
  title = {{Effective random test generation for deep learning compilers}},
  journal = {Science China Information Sciences},
  year = {2023},
}
Figure