Deep Learning (DL) libraries like PyTorch and TensorFlow are foundational to modern AI, yet their complexity makes them notoriously difficult to test. Traditional fuzzing techniques often struggle with the strict multi-layered constraints of these libraries, which require both syntactically valid Python and semantically valid tensor operations. While Large Language Models (LLMs) have shown promise in generating valid code, they tend to produce "natural" or common code patterns, whereas bugs typically reside in rare edge cases. This paper introduces FuzzGPT, a framework that "primes" LLMs to generate unusual, bug-triggering programs by leveraging historical bug data.
The Challenge of DL Library Testing
Testing DL operators involves satisfying complex constraints. For instance, an operator like torch.nn.Fold requires specific input shapes and parameters to function correctly. LLMs can implicitly learn these rules, but their training data biases them toward standard usage. FuzzGPT addresses this "naturalness bias" by steering models toward the "unnatural" patterns found in historical bug reports, operating on the "Bugs Cluster" hypothesis: that historical bugs contain rare but valuable code ingredients that are likely to trigger new vulnerabilities.
Methodology: Priming LLMs for Fuzzing
The FuzzGPT pipeline consists of several key stages designed to transform historical bug reports into a priming mechanism for models like Codex, CodeGen, and ChatGPT:
- Dataset Mining: A web crawler collected 2,383 bug-triggering snippets (1,750 for PyTorch, 633 for TensorFlow) from GitHub issues and pull requests.
- Automated Annotation: An LLM-based self-training approach was used to label the specific APIs responsible for bugs in the mined snippets, as bug reports often lack explicit API labels.
- Priming Strategies: The framework employs few-shot learning (providing historical examples), zero-shot completion/editing, and fine-tuning to direct LLMs toward bug-prone code styles.
- Chain-of-Thought (CoT) Fuzzing: Models are prompted to describe a potential bug before generating the code to trigger it, increasing the diversity and effectiveness of the test cases.
Experimental Results
FuzzGPT was evaluated against the latest versions of PyTorch and TensorFlow, using baselines like TitanFuzz and traditional fuzzers (FreeFuzz, DeepREL, etc.).
- Bug Discovery: FuzzGPT detected 76 unique bugs, 61 of which have been confirmed by developers, including 49 previously unknown vulnerabilities. Notably, 11 were classified as high-priority or security risks, such as buffer sharing issues.
- Coverage Gains: FuzzGPT significantly outperformed TitanFuzz, achieving a 60.7% improvement in line coverage for PyTorch. This suggests that the intent behind the generated code matters more than the sheer volume of random mutations.
- Unique Crashes: As shown in the Venn diagrams below, FuzzGPT identified numerous unique crashes that existing state-of-the-art tools missed, demonstrating its ability to explore edge cases that traditional LLM-based fuzzers overlook.
Conclusion
FuzzGPT demonstrates that LLMs can be effectively steered to explore the "unnatural" edge cases of software libraries. By mimicking the style of historical bugs, FuzzGPT provides a high-quality, low-volume approach to fuzzing that identifies critical vulnerabilities missed by traditional methods. While the technique currently relies on high-quality historical data, its success suggests a new paradigm for automated testing in complex software domains.
Summary updated