Abstract
Automatic Differentiation (AD) is the mathematical engine behind deep learning training. Despite its criticality, AD implementations are complex and difficult to verify, often leading to "silent" bugs where models train on incorrect gradients without crashing. We introduce $\nabla$Fuzz (NablaFuzz), a tool that applies differential testing to AD by cross-referencing Forward-mode AD, Reverse-mode AD, and Numerical Differentiation. Testing across PyTorch, TensorFlow, JAX, and OneFlow, $\nabla$Fuzz identified 173 bugs, 144 of which have been confirmed by developers.
Introduction: The Hidden Complexity of AD
Deep learning (DL) libraries like PyTorch and TensorFlow have revolutionized AI, but their reliability during the training phase depends entirely on Automatic Differentiation (AD). Unlike inference, which simply executes a forward pass, training requires computing gradients for billions of parameters. AD decomposes complex mathematical functions into a sequence of elementary operations, forming a computational graph.
Testing AD is uniquely challenging. Libraries often implement multiple modes—Reverse-mode (backpropagation) and Forward-mode (Jacobian-vector products)—alongside specialized kernels for various hardware. A bug in any of these paths can result in a "silent killer": a model that converges to a sub-optimal state or fails entirely without ever throwing an error. Previous fuzzing research has largely focused on the inference phase, leaving the AD logic under-tested.
Methodology: The $\nabla$Fuzz Framework
$\nabla$Fuzz addresses this gap by treating every DL API as a vector-to-vector function $f(x)$ and applying differential testing. The core innovation lies in its multi-mode test oracle, which compares different methods of calculating derivatives to find discrepancies.
The workflow consists of four primary stages:
- Input Generation: Utilizing the FreeFuzz database, the tool generates valid tensors and arguments for thousands of APIs across PyTorch, TensorFlow, JAX, and OneFlow.
- Execution Scenarios: For each API, $\nabla$Fuzz executes a Direct Invocation, Reverse-mode AD, and Forward-mode AD. It also computes a "ground truth" using Numerical Differentiation (ND) via finite differences.
- The Oracle: The tool compares the outputs of these modes. If the gradients produced by Reverse AD do not match those from Forward AD or the ND approximation within a specific tolerance, a potential bug is flagged.
- Higher-Order Testing: $\nabla$Fuzz can recursively apply AD to its own gradient functions, allowing it to test second-order (Hessian) and third-order derivatives, which are often less tested and more bug-prone.
To minimize false positives caused by floating-point noise or non-differentiable points (e.g., the "kink" in a ReLU function), $\nabla$Fuzz employs neighbor sampling. It checks the local stability of the function before reporting an inconsistency, ensuring that reported bugs are likely genuine logic errors rather than numerical artifacts.
Key Results and Impact
$\nabla$Fuzz was evaluated against the extensive API surfaces of four major libraries. The results demonstrate high efficacy in finding critical training-phase errors:
- Bug Detection: The tool uncovered 173 bugs, with 107 directly residing in AD logic. 144 of these have already been confirmed by framework maintainers.
- High Priority: In a two-month window, $\nabla$Fuzz accounted for 58.3% of all high-priority AD bugs reported for PyTorch and JAX.
- Code Coverage: It achieved superior C++ code coverage (25.8% in PyTorch) compared to state-of-the-art inference fuzzers like FreeFuzz (21.1%), specifically by exercising the complex logic paths required for gradient computation.
- Unique Finds: None of the AD-related bugs found by $\nabla$Fuzz were detectable by previous model-level or inference-only fuzzers, highlighting the necessity of AD-specific testing.
Conclusion
$\nabla$Fuzz demonstrates that differential testing, when combined with robust numerical stability checks, is highly effective at uncovering deep-seated logic errors in AD engines. By identifying "silent" gradient bugs that previous tools missed, $\nabla$Fuzz provides a critical layer of security for the training pipelines of modern AI systems. Future work may involve using Large Language Models to generate even more complex API sequences to test deeper interactions between library components.
Summary updated