Graph-based Fuzz Testing for Deep Learning Inference Engines

Weisi Luo, Dong Chai, Xiaoyue Run, Jiang Wang, Chunrong Fang, Zhenyu Chen · DOI

TL;DR

This paper introduces a novel graph-based fuzz testing framework to improve the quality of deep learning (DL) inference engines, which are crucial for deploying DL models efficiently. By treating DL models as graphs and employing a new operator-level coverage metric, their method effectively generates diverse test cases to uncover bugs in these engines.

What Problem Does This Paper Address?

Deep learning (DL) systems are increasingly prevalent, but ensuring the quality of the underlying inference engines (frameworks and libraries that run DL models) is challenging. Existing testing methods often focus on the DL models themselves, not the engines that execute them. These engines are complex, interacting with diverse hardware and software platforms, and bugs within them can lead to crashes, incorrect predictions, and security vulnerabilities. The challenge lies in systematically generating a wide variety of DL models that can effectively probe the diverse functionalities and potential failure points of these inference engines.

Methods

The core of this work is a graph-based fuzz testing framework for DL inference engines. Key components include:

  • Graph Representation: DL models are represented as directed graphs (digraphs), where nodes are operators and edges represent data flow.
  • Operator-Level Coverage: A novel coverage criterion is introduced to measure how well the inference engine's logic is exercised. This criterion considers operator types, input/output degrees, tensor shapes, and parameters, moving beyond traditional code or neuron coverage.
  • Monte Carlo Tree Search (MCTS): MCTS is employed to guide the generation of diversified DL models. It intelligently explores the search space of model structures and parameters, prioritizing those that are more likely to increase coverage or uncover new exceptions.
  • Mutation Strategies: A set of six mutation operators are defined to generate diverse DL models. These include:
  • Model-level mutations: Graph edge addition/removal, block node addition/removal.
  • Source-level mutations: Tensor shape mutation and parameter mutation.
  • Block Corpus: A collection of predefined DL operators and subgraphs (reusable structural components) forms the building blocks for generating new models.
  • Framework Workflow: The framework iteratively selects blocks, applies mutations, generates DL models, runs them through the inference engine, and uses the coverage feedback to guide subsequent model generation.

Datasets

Not explicitly discussed in the paper. The authors use TensorFlow to generate input DL models and MNN as the target DL inference engine for their experiments.

Key Insights and Ideas

  • Shifting Focus to Inference Engines: The paper highlights the critical need to test inference engines directly, not just the DL models they execute.
  • Graph Structure as a Testing Basis: Leveraging the inherent graph structure of DL models provides a natural and effective way to generate diverse test inputs (DL models).
  • Operator-Level Coverage is Key: Traditional coverage metrics are insufficient for inference engine testing. The proposed operator-level coverage, considering various aspects of operators, proves effective in guiding the fuzzing process.
  • MCTS for Intelligent Exploration: MCTS significantly outperforms random search in boosting operator-level coverage and discovering exceptions, demonstrating its value in navigating the complex search space.
  • Mutation Strategies are Crucial: The combination of model-level and source-level mutations effectively generates diversified DL models, leading to higher coverage and more detected exceptions.

Key Results

  • The proposed graph-based fuzz testing method discovered over 40 different exceptions across three categories: model conversion failure, inference failure, and output comparison failure.
  • MCTS-based search achieved 6.7% more operator-level coverage and found 9.7 more exceptions on average compared to random search.
  • The mutation strategies resulted in 8.2% more operator-level coverage and detected 8.6 more exceptions on average.
  • The framework demonstrated effectiveness in uncovering issues like segmentation faults, conversion aborts, and data comparison failures in the MNN inference engine.

Limitations and Future Work

  • Limitations:
    • The effectiveness of the approach is evaluated on a specific DL inference engine (MNN) and DL models generated from TensorFlow. Generalizability to other engines and model formats might require further validation.
  • The paper acknowledges that generating models of specific structures can be challenging, and subgraphs help but don't fully solve this.
  • Future Work:
    • The authors suggest that further research could explore more sophisticated mutation strategies and coverage criteria.
  • Investigating the application of this framework to other DL inference engines and different types of DL models is a natural next step.
  • The paper mentions that the approach has been used internally at Huawei for several months, implying ongoing development and potential for real-world impact.

Summary updated

BibTeX
@inproceedings{luo2021graph,
  author = {Weisi Luo and Dong Chai and Xiaoyue Run and Jiang Wang and Chunrong Fang and Zhenyu Chen},
  title = {{Graph-based Fuzz Testing for Deep Learning Inference Engines}},
  booktitle = {ICSE},
  year = {2021},
  doi = {10.1109/icse43902.2021.00037},
}
Figure