[Paper Review] Free Lunch for Testing: Fuzzing Deep-Learning Libraries from Open Source
FreeFuzz is a novel, fully automated approach for fuzzing deep learning libraries by mining code from open-source sources—documentation, developer tests, and real-world models—then using dynamic instrumentation to extract runtime type and shape information for targeted API-level fuzzing. It achieves 1158 covered APIs (9× more than LEMON) with 3.5× lower overhead and discovered 49 bugs in PyTorch and TensorFlow, 38 of which were confirmed as previously unknown by developers.
Deep learning (DL) systems can make our life much easier, and thus are gaining more and more attention from both academia and industry. Meanwhile, bugs in DL systems can be disastrous, and can even threaten human lives in safety-critical applications. To date, a huge body of research efforts have been dedicated to testing DL models. However, interestingly, there is still limited work for testing the underlying DL libraries, which are the foundation for building, optimizing, and running DL models. One potential reason is that test generation for the underlying DL libraries can be rather challenging since their public APIs are mainly exposed in Python, making it even hard to automatically determine the API input parameter types due to dynamic typing. In this paper, we propose FreeFuzz, the first approach to fuzzing DL libraries via mining from open source. More specifically, FreeFuzz obtains code/models from three different sources: 1) code snippets from the library documentation, 2) library developer tests, and 3) DL models in the wild. Then, FreeFuzz automatically runs all the collected code/models with instrumentation to trace the dynamic information for each covered API, including the types and values of each parameter during invocation, and shapes of input/output tensors. Lastly, FreeFuzz will leverage the traced dynamic information to perform fuzz testing for each covered API. The extensive study of FreeFuzz on PyTorch and TensorFlow, two of the most popular DL libraries, shows that FreeFuzz is able to automatically trace valid dynamic information for fuzzing 1158 popular APIs, 9X more than state-of-the-art LEMON with 3.5X lower overhead than LEMON. To date, FreeFuzz has detected 49 bugs for PyTorch and TensorFlow (with 38 already confirmed by developers as previously unknown).
Motivation & Objective
- To address the critical gap in automated testing for deep learning libraries, which are foundational to DL model development but under-tested compared to models themselves.
- To overcome the challenge of dynamic typing in Python-based DL libraries that hinders automatic test input generation and type inference.
- To enable high-coverage, efficient, and automated fuzzing of DL library APIs by leveraging real-world code and runtime instrumentation.
- To improve upon existing model-level testing approaches (e.g., CRADLE, LEMON) that suffer from low code coverage, high overhead, and limited input diversity.
- To detect previously unknown bugs in widely used DL libraries like PyTorch and TensorFlow through fine-grained, API-level fuzzing.
Proposed method
- FreeFuzz collects code and models from three open-source sources: official library documentation, developer test suites, and real-world DL models from public repositories.
- It instruments and executes all collected code to dynamically trace API invocations, capturing parameter types, values, and input/output tensor shapes at runtime.
- The traced dynamic information is used to generate targeted, type-aware fuzzing inputs for each covered API, enabling precise and effective mutation testing.
- It employs a coverage-guided fuzzing strategy at the API level, focusing on unit-testing individual library functions rather than end-to-end model execution.
- The approach uses lightweight runtime instrumentation to minimize performance overhead while maximizing observable API behavior.
- It integrates with existing test oracles by comparing outputs across fuzzed inputs, identifying inconsistencies indicative of potential bugs.
Experimental results
Research questions
- RQ1Can open-source code and models be effectively mined to automatically generate diverse, valid test inputs for deep learning library APIs?
- RQ2Can dynamic instrumentation extract reliable type and shape information for Python-based DL APIs despite dynamic typing?
- RQ3Can API-level fuzzing outperform model-level testing in terms of code coverage, efficiency, and bug detection for DL libraries?
- RQ4How does FreeFuzz compare to state-of-the-art approaches like LEMON in coverage, overhead, and real-world bug discovery?
- RQ5To what extent can existing model mutation techniques in prior work (e.g., LEMON) truly improve coverage and detect new bugs in DL libraries?
Key findings
- FreeFuzz successfully traced dynamic information for 1158 popular APIs in PyTorch and TensorFlow, representing a 900% increase over the 128 APIs covered by LEMON.
- The approach achieved 3.5× lower runtime overhead compared to LEMON, demonstrating superior efficiency in instrumentation and execution.
- FreeFuzz discovered 49 unique bugs in PyTorch and TensorFlow, with 38 confirmed by developers as previously unknown issues.
- The study revealed that LEMON’s model mutation rules are highly constrained and fail to significantly improve code coverage, limiting their effectiveness.
- API-level fuzzing via FreeFuzz provides a more scalable and effective alternative to model-level differential testing for uncovering low-level library bugs.
- The use of real-world code from documentation and open-source models enables broader and more realistic API coverage than synthetic or pre-trained model-based approaches.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.