COMET: Coverage-guided Model Generation For Deep Learning Library Testing

Meiziniu Li, Jialun Cao, Yongqiang Tian, Tsz On Li, Ming Wen, Shing-Chi CheungarXiv 2022 · DOI

TL;DR

COMET is a new coverage-guided testing framework designed to uncover bugs in deep learning (DL) libraries like TensorFlow and PyTorch. By prioritizing the diversity of layer API calls—specifically focusing on unique inputs, parameter values, and layer sequences—COMET discovered 32 new bugs in popular libraries, significantly outperforming existing state-of-the-art testing tools.

What Problem Does This Paper Address?

Deep learning applications are only as reliable as the libraries they are built upon. However, testing these libraries is notoriously difficult. Current state-of-the-art testers generate DL models and feed them into libraries to check for crashes or calculation inconsistencies.

The authors identified a major gap: existing tools are not diverse enough. They often focus on high-level graph structures but miss bugs triggered by specific, "corner-case" API calls. For instance, a library might crash only when a Dense layer is followed by a Dot layer with a specific zero-shape input. As shown in the paper's study, existing techniques cover less than 35% of possible layer inputs and only 15.6% of layer sequences, leaving a vast amount of library code unexercised and potentially buggy.

Fig. 2. A Crash Bug of ONNXRuntime

Methods

COMET introduces a three-step workflow to maximize testing effectiveness:

  1. Initial Model Synthesis: Large, popular models (like ResNet) are excellent sources of diverse API calls but are computationally expensive to run repeatedly during testing. COMET synthesizes "lightweight" versions of these models that retain the same diversity of layer calls but with significantly fewer weights (often reducing weight count by over 99%).
  2. Diverse Model Generation: COMET uses eight specialized mutation operators categorized into three levels:
  3. Input-level: Mutating datatypes (e.g., float32 to float16), dimensions, and shapes.
  4. Parameter-level: Changing layer-specific settings like kernel_size or activation.
  5. Structure-level: Inserting, merging, or connecting layers in new sequences.
  6. Coverage-guided Search: Instead of random mutations, COMET employs a Markov Chain Monte Carlo (MCMC) algorithm. It uses a fitness function to prioritize mutations that explore previously "uncovered" layer inputs, parameters, or sequences, as well as those that hit new branches in the library's source code.
Fig. 4. Overview of COMET

To ensure the generated models are actually runnable, COMET enforces "tensor constraints" (e.g., matching dimensions between connected layers) to avoid wasting time on invalid models that the library would reject immediately.

Datasets

The researchers evaluated COMET using 10 popular DL models as seeds, including AlexNet, LeNet, ResNet50, InceptionV3, and MobileNetV2. These models cover various domains like image classification and sequential data processing.

The testing targeted eight widely-used DL libraries: Keras, TensorFlow, PyTorch, MXNet, ONNXRuntime, Keras-MXNet, TF2ONNX, and ONNX2PyTorch.

Key Insights and Ideas

  • API Call Diversity is the Key: The core "aha moment" is that library bugs are often hidden in the fine-grained details of how a layer is invoked (its specific parameters and input shapes) rather than just the overall model architecture.
  • Synthesis for Efficiency: You don't need a massive 50-million-parameter model to test a library's logic. A synthesized 400k-parameter model that makes the same API calls is just as effective for bug hunting and runs much faster.
  • Guided Exploration Beats Randomness: The huge search space of possible models makes random fuzzing inefficient. By explicitly tracking "layer property coverage," COMET can systematically explore the corners of the API space where developers might have missed edge cases.

Key Results

COMET demonstrated a significant leap over previous tools like Muffin and LEMON:

  • Superior Coverage: It covered 69.7% of layer inputs (vs. 34.1% for the best baseline) and 39.0% of layer sequences (vs. 15.6%).
  • Library Code Reach: It increased branch coverage in TensorFlow by 3.4% compared to existing techniques.
  • Real-World Impact: COMET detected 32 new bugs across the eight libraries. At the time of publication, 21 had been confirmed by developers, and 7 had already been fixed. These included critical "core dump" crashes and silent numerical errors (NaN outputs).

Limitations and Future Work

Despite its success, COMET still only covers about 19.4% of the total branches in TensorFlow's model construction modules. The authors note two main reasons:

  1. Implementation Restrictions: COMET currently uses Keras as a front-end to generate models. This means it cannot easily reach low-level or private library methods that aren't exposed through the high-level Keras API.
  2. Reachability: Some library code is designed for internal developer utilities and cannot be triggered by standard model execution.

Future work could involve expanding COMET to support more diverse front-ends beyond Keras and developing techniques to target even deeper, low-level library implementations.

Summary updated

BibTeX
@misc{li2022comet,
  author = {Meiziniu Li and Jialun Cao and Yongqiang Tian and Tsz On Li and Ming Wen and Shing-Chi Cheung},
  title = {{COMET: Coverage-guided Model Generation For Deep Learning Library Testing}},
  year = {2022},
  eprint = {2208.01508},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.01508},
}
Figure