Introduction
Deep learning (DL) libraries such as PyTorch, TensorFlow, and JAX serve as the foundational infrastructure for modern artificial intelligence. Given their critical role, ensuring the correctness of their underlying APIs is paramount. However, identifying hidden implementation bugs in these complex libraries is notoriously difficult.
Traditionally, researchers have relied on fuzzing combined with intra-framework differential testing. This method involves executing the same API on different hardware backends (e.g., CPU vs. GPU) within a single framework and flagging discrepancies in the output. While effective for hardware-specific issues, this approach suffers from a significant blind spot: if a bug is rooted in the algorithmic logic itself, it will likely produce identical incorrect results across all backends. These "backend-agnostic" bugs can silently propagate errors into sensitive downstream applications like autonomous driving and medical imaging. To address this, we introduce XAMT, a novel tool that shifts the testing paradigm toward cross-framework differential testing.
Methodology
XAMT (Cross-framework API Matching for Testing) identifies bugs by comparing the behavior of functionally equivalent APIs across different DL libraries. The system operates through a three-stage pipeline: API Matching, Input Alignment, and Variance-Guided Fuzzing.
1. API Matching
XAMT automatically identifies equivalent APIs across frameworks using a multi-stage similarity analysis:
- Lexical Similarity: Comparing API names using Levenshtein distance.
- Semantic Similarity: Utilizing Sentence-BERT embeddings to analyze official API documentation and descriptions. This allows the tool to match functions with different naming conventions, such as
softmax_cross_entropyandcrossentropy_loss. - Structural Similarity: Evaluating parameter counts and types. To ensure accuracy, XAMT filters out framework-specific "control" parameters (e.g.,
deviceorlog_level) that do not influence the core mathematical operations.
2. Input Alignment
Once APIs are grouped into functional clusters, XAMT aligns their parameters to a canonical signature, using PyTorch as the baseline. This ensures that a single generated input can be fed into multiple frameworks simultaneously for direct comparison.
3. Variance-Guided Fuzzing
Instead of relying on purely random input generation, XAMT employs a variance-guided mutation strategy. The tool generates unified input seeds (tensors, scalars, and shapes) and iteratively tweaks them to maximize the output discrepancy (variance) across the matched frameworks. If an input causes significant divergence, inconsistent NaNs, or crashes in one framework but not others, XAMT flags the behavior as a potential bug.
Experimental Evaluation
The authors evaluated XAMT against five major frameworks: PyTorch (2.2.1), TensorFlow (2.16.1), Keras (3.6.0), Chainer (7.8.1), and JAX (0.4.26). The study focused on 554 core APIs within the torch and torch.nn namespaces as the baseline for matching.
Bug Detection and Accuracy
XAMT successfully matched 839 APIs across the five frameworks, forming 238 functionally equivalent groups. During testing, the tool detected 17 unique bugs: 3 in PyTorch, 5 in TensorFlow, 2 in Keras, 2 in Chainer, and 5 in JAX. Notably, 12 of these bugs have already been confirmed by the respective framework developers.
Comparison with State-of-the-Art
XAMT was compared against existing API fuzzers, FreeFuzz and DeepREL, using a fixed testing budget of 500 test cases per API. XAMT demonstrated superior performance in two key areas:
- Code Coverage: XAMT achieved higher coverage than its predecessors (e.g., 20.01% vs. ~13.9% in PyTorch; 22.80% vs. ~21.6% in TensorFlow).
- Detection Capability: In a direct comparison involving 8 specific APIs where XAMT found bugs, the baseline tools detected only one crash. The baselines failed to find the remaining logical errors because those errors were consistent across CPU and GPU backends within a single framework.
Key Insights
The success of XAMT highlights several important takeaways for DL library testing:
- Cross-Framework Consensus as an Oracle: Comparing different implementations of the same algorithm is a powerful way to expose logical flaws that hardware-level testing cannot see.
- Documentation as a Resource: NLP-based analysis of official documentation is highly effective for mapping equivalent functions across disparate codebases.
- Efficiency of Variance-Guidance: Mutating inputs to specifically increase output divergence is more efficient at finding edge-case bugs than random generation.
Limitations and Future Work
Despite its effectiveness, XAMT has limitations. It cannot detect "common-mode" bugs—errors where multiple frameworks share the same flawed logic or misinterpretation of a mathematical formula. Additionally, its strict matching rules, while minimizing false positives, may exclude equivalent APIs with highly unconventional parameter designs.
Future iterations of XAMT may leverage Large Language Models (LLMs) to further improve documentation extraction and matching. Furthermore, integrating metamorphic relations could help the tool identify common-mode bugs that currently evade cross-framework consensus.
Summary updated