Abstract
Deep Learning (DL) frameworks like PyTorch and TensorFlow are the foundational infrastructure of modern AI, yet their complexity makes them prone to critical bugs. Testing these systems is uniquely challenging because test cases must be valid computational graphs—DNN models—where every operator satisfies strict shape and attribute constraints. NeuRI (Neural Network Synthesis via Rule Inference) introduces a novel approach to automated testing by using inductive program synthesis to automatically learn these constraints from existing API traces. By generating structurally diverse and valid models, NeuRI discovered 100 new bugs in major frameworks, including high-priority security vulnerabilities.
Introduction
As DL libraries and compilers (such as PyTorch’s JIT and TensorFlow’s XLA) grow in complexity, ensuring their reliability becomes a monumental task. Traditional fuzzing techniques often fail here because a random input is unlikely to form a valid computational graph. Existing model-level fuzzers attempt to solve this by using predefined rules for operator behavior, but these rules are typically written by hand—a process that is unscalable and error-prone given the thousands of APIs in modern frameworks. NeuRI addresses this "scalability wall" by asking: Can we automatically infer these rules instead of writing them by hand?
Methodology
NeuRI employs a three-stage pipeline to automate the generation of high-quality, diverse DNN models for testing.
1. Instrumentation and Augmentation
To understand how operators behave, NeuRI first looks at how developers use them. The system instruments official developer regression tests in PyTorch and TensorFlow to collect "traces"—real-world examples of API calls with specific input shapes and attributes. To create a more robust dataset for learning, NeuRI augments these traces through mutation (e.g., incrementing dimensions or swapping values), generating a large library of both passing and failing examples.
2. Inductive Rule Inference
This stage serves as the core engine of NeuRI. Using bottom-up enumerative program synthesis, NeuRI searches for simple arithmetic expressions that describe an operator's behavior, such as how an output shape is derived from an input shape. To maintain efficiency, NeuRI utilizes two key strategies:
- Partial Operators: Instead of seeking a single rule for an entire API, NeuRI specializes. It creates specific rules for an operator when used with specific tensor ranks (e.g., a rule for 3D tensors and a separate one for 4D tensors).
- Pruning: The system uses heavy pruning to discard redundant or rare expressions, focusing on the simplest rules that explain the data.
3. Hybrid (Concolic) Model Generation
When constructing a new test model, NeuRI uses a "concolic" (concrete + symbolic) approach. It builds graphs by inserting two types of operators:
- Symbolic Operators: These use the inferred rules and an SMT solver to find valid parameters for new, unseen combinations.
- Concrete Operators: These directly replay successful traces from the instrumentation phase.
This hybrid strategy allows NeuRI to support hundreds of operators even if a general symbolic rule could not be perfectly synthesized for all of them. Finally, the system uses differential testing—comparing the framework's interpreter output against its compiler output—to identify inconsistencies, crashes, or memory errors.
Key Results and Impact
NeuRI was evaluated against NNSmith, the previous state-of-the-art model-level fuzzer, and demonstrated significant improvements in both coverage and bug discovery:
- Increased Coverage: NeuRI improved branch coverage by 24% for TensorFlow and 15% for PyTorch.
- Bug Discovery: In just four months, NeuRI found 100 new bugs, 81 of which were promptly fixed or confirmed by framework maintainers. Notably, 10% of these were classified as high-priority or security vulnerabilities, including a heap-overflow with an assigned CVE.
- Synthesis Efficiency: The rule inference process is highly performant; 95% of shape propagation rules were inferred in less than 17 milliseconds.
- Developer Feedback: Maintainers noted that NeuRI-generated tests were "high-quality" and representative of real-world usage patterns, distinguishing them from the "fuzzer junk" often produced by less sophisticated tools.
Discussion and Future Work
While NeuRI significantly advances the state of DL framework testing, it faces limitations with complex variadic rules (operators taking a variable number of inputs) and potential overfitting to the initial trace data. Future research may explore the synergy between NeuRI’s formal constraint solving and the natural language capabilities of Large Language Models (LLMs) to generate even more "natural" and structurally diverse code. By automating the inference of complex rules, NeuRI provides a scalable and effective path toward hardening the software that powers modern artificial intelligence.
Summary updated