Subgraph-Oriented Testing for Deep Learning Libraries

Xiaoyuan Xie, Yan Song, Songqiang Chen, Jinfu Chen · DOI

Introduction

Deep learning (DL) libraries such as PyTorch and TensorFlow serve as the foundational infrastructure for modern artificial intelligence. Despite their critical role, ensuring their reliability remains a significant challenge. Traditional testing methodologies generally fall into two categories: model-level testing and API-level testing. Model-level testing involves executing entire architectures (e.g., ResNet), which makes isolating the specific API responsible for a bug nearly impossible. Conversely, API-level testing focuses on individual functions in isolation, often generating unrealistic "garbage" inputs that are rejected by the library or failing to capture bugs that emerge only through API interactions.

Furthermore, existing tools primarily target crash bugs, often overlooking precision bugs—subtle numerical discrepancies between different hardware backends (e.g., CPU vs. GPU). These errors can accumulate across a model's layers, leading to non-convergence or degraded inference accuracy. To bridge this gap, researchers have introduced SORT (Subgraph-Oriented Realistic Testing), a framework that tests libraries at a "middle-ground" granularity using frequent subgraphs and realistic runtime data.

The SORT Framework

SORT identifies and tests common patterns of API interactions, known as "frequent subgraphs," which are extracted from real-world models. This approach allows the framework to detect interaction-related bugs and accumulated precision errors that single-API tests miss.

Overview of the SORT framework including subgraph extraction, feature collection, and differential testing.

The framework consists of four primary modules:

  1. Frequent Subgraph Extraction: By analyzing 49 popular models from the OpenMMLab zoo using the gSpan algorithm, SORT identifies recurring motifs, such as the sequence of conv2d followed by batch_norm and relu.
  2. Runtime Feature Collection: To ensure test inputs are representative of real-world usage, SORT instruments production models to record the shapes, data types, and value ranges of tensors during actual execution.
  3. Realistic Input Generation: Using the collected runtime features, SORT generates new tensors that mimic the properties of real data, significantly reducing the likelihood of inputs being rejected by the APIs.
  4. Differential Testing: The generated subgraphs are executed on different hardware backends (e.g., CPU and GPU). If the outputs diverge beyond a predefined threshold ($10^{-3}$), a potential precision bug is flagged.

Experimental Evaluation

The effectiveness of SORT was evaluated using 728 unique frequent subgraphs extracted from 49 PyTorch models. The framework was compared against five state-of-the-art baselines: FreeFuzz, DeepREL, DocTer, ACETest, and TitanFuzz.

Comparison of SORT against state-of-the-art baselines across various APIs, highlighting its 100% validity rate.

The results demonstrate SORT's clear superiority. Most notably, SORT achieved a 100% valid input rate, whereas some baselines struggled with validity rates as low as 6.72%. This high validity is a direct result of using realistic runtime features for input generation. In terms of bug detection, SORT identified 3,376 precision bugs in PyTorch, 18 of which have already been confirmed by developers. While baselines are effective at finding crash bugs, they found almost zero precision bugs, highlighting the unique value of the subgraph-oriented approach.

Key Insights and Future Directions

A critical finding of this research is the "magnification" effect: minor numerical discrepancies in early layers can be significantly amplified by subsequent operations. SORT's ability to test sequences of APIs makes it uniquely capable of capturing these accumulated errors. Additionally, a survey of DL engineers confirmed that the realism of test cases is paramount; bugs found using realistic data are far more likely to be prioritized and fixed by library maintainers.

Despite its success, SORT has limitations. Its input generation is dependent on the diversity of the models used for feature collection. If an API is used in a rare configuration not present in the initial 49 models, SORT may not cover it. Future work will focus on expanding the model dataset, refining the precision error thresholds, and extending the framework to other libraries like TensorFlow and MindSpore.

Summary updated

BibTeX
@article{xie2026subgraph,
  author = {Xiaoyuan Xie and Yan Song and Songqiang Chen and Jinfu Chen},
  title = {{Subgraph-Oriented Testing for Deep Learning Libraries}},
  journal = {IEEE Trans. Software Eng.},
  year = {2026},
  doi = {10.1109/tse.2026.3655712},
}
Figure