TL;DR
DocTer is an automated testing framework that extracts deep learning (DL) specific input constraints directly from API documentation to guide fuzzing. By "reading" the manual, it generates high-quality test cases that bypass simple input validation to uncover deep-seated bugs, successfully identifying 94 bugs across TensorFlow, PyTorch, and MXNet.
What Problem Does This Paper Address?
Deep learning libraries like TensorFlow and PyTorch are the bedrock of modern AI, yet they are notoriously difficult to test. Their API functions have highly specific requirements: a parameter might need to be a "5-D tensor of type float32" or a "list of 3 integers."
Standard automated testing tools (fuzzers) usually generate random data. For DL APIs, this random data almost always fails the initial "sanity check" performed by the library, meaning the fuzzer only tests the error-handling code and never reaches the complex numerical logic where the real bugs hide. While developers describe these constraints in documentation, the text is informal and written in natural language, making it difficult for traditional tools to parse and use for test generation.
Methods
DocTer bridges the gap between informal documentation and rigorous testing through a three-phase pipeline:
- Rule Construction: The system starts with a small set of manually annotated API descriptions. It "normalizes" the text (e.g., converting "float32" or "int64" into a generic
D_TYPEplaceholder) and uses a dependency tree parser to understand the grammatical structure of the sentences. It then uses a novel optimization algorithm to find the best "rules"—mappings between specific grammatical patterns and abstract constraints (like data type, tensor shape, or valid ranges). - Constraint Extraction: DocTer applies these learned rules to thousands of API documents. It extracts concrete constraints for every parameter, including dependencies between parameters (e.g., "parameter A must have the same shape as parameter B").
- Testing Phase: Using these constraints, DocTer generates two types of inputs:
- Conforming Inputs: Valid data that follows all rules to exercise the API's core functionality.
- Violating Inputs: Data that intentionally breaks one rule to test if the library handles errors gracefully (without crashing).
Datasets
The authors evaluated DocTer on the documentation and code of three major DL libraries:
- TensorFlow (v2.1.0): 2,334 pages of documentation.
- PyTorch (v1.5.0): 529 relevant APIs.
- MXNet (v1.6.0): 1,021 relevant APIs.
They also tested the "generality" of their rules by applying them to scikit-learn and newer versions of the original three libraries.
Key Insights and Ideas
- Grammar over Keywords: Simple keyword matching (searching for "int") is insufficient. DocTer uses dependency parse trees to understand how words relate. For example, it can distinguish between "a list of integers" and "an integer or a list," which require very different test inputs.
- The "Core Logic" vs. "Validation" Gap: The paper highlights that without constraints, fuzzers are "blind." DocTer's ability to generate valid-looking tensors allows it to reach deeper states in the C++ backend of these libraries.
- Documentation as a Double-Edged Sword: Documentation is a great source of truth, but it's often buggy itself. DocTer found 43 instances where the documentation was inconsistent or referred to non-existent parameters.
- Optimization-Based Rule Learning: Rather than hard-coding rules, the authors formulated rule discovery as an optimization problem, aiming for the smallest set of rules that provides the highest coverage and accuracy.
Key Results
- High Precision: DocTer extracted constraints with 85.4% precision.
- Bug Bounty: It detected 94 bugs across 174 APIs. Crucially, 63 of these were previously unknown, and 54 have already been fixed or confirmed by developers.
- Security Impact: One of the bugs DocTer found was classified as a security vulnerability and added to the CVE database (CVE-2020-15265).
- Superiority over Baselines: A baseline fuzzer without documentation guidance found only 59 bugs. DocTer was significantly more effective at generating "passing" inputs that actually exercised the library's logic (33.4% vs 21.5% for the baseline).
Limitations and Future Work
- Complex Constraints: DocTer struggles with highly complex, nested constraints or indirect dependencies that appear in about 6.4% of the sampled parameters.
- Initial Manual Effort: The system requires about 36 hours of manual annotation for the initial training set (though this is a one-time cost per domain).
- Future Directions: The authors suggest extending DocTer to other domains beyond deep learning and improving the system's ability to handle more intricate, multi-parameter logic.
Summary updated