Muffin: Testing Deep Learning Libraries via Neural Architecture Fuzzing

Jiazhen Gu, Xuchuan Luo, Yangfan Zhou, Xin Wang · DOI

Abstract

Deep learning (DL) techniques are proven effective in many challenging tasks and have become widely adopted in practice. However, DL libraries, the basis of building and executing DL models, contain bugs that can cause severe consequences. Existing testing approaches often fail to comprehensively exercise these libraries as they rely on existing trained models and only detect bugs during the model inference phase. We propose Muffin, a model fuzzing approach that generates diverse DL models to explore target libraries. Muffin enables differential testing in the model training phase by tailoring metrics to measure inconsistencies between different libraries. Evaluating Muffin on three widely-used libraries—TensorFlow, CNTK, and Theano—resulted in the detection of 39 new bugs in their latest release versions.

Introduction

Deep learning libraries like TensorFlow and CNTK are the bedrock of modern AI, yet their internal complexity makes them prone to subtle and impactful bugs. Traditional testing methods have two major limitations: they use a narrow scope of pre-trained models and focus almost exclusively on the inference phase. This leaves the most complex parts of these libraries—gradient descent, backpropagation, and loss calculations—largely untested.

The deep learning software stack, highlighting the role of low-level libraries like TensorFlow and CNTK.

Methodology: Neural Architecture Fuzzing

Muffin addresses these gaps through a two-pronged approach: automated model generation and differential training-phase testing.

1. Model Generation

Instead of mutating existing models, Muffin generates new architectures from scratch using Directed Acyclic Graph (DAG) templates. It employs Fitness Proportionate Selection to populate these structures with a diverse set of layers (e.g., Convolution, LSTM, BatchNormalization), prioritizing those that have been under-tested in previous runs. This approach achieved a functionality coverage of 98.3%, compared to just 35.6% for traditional mutation-based methods.

The Muffin workflow, illustrating the process from model generation to inconsistency detection across multiple library backends.

2. Differential Training-Phase Testing

Muffin runs generated models across multiple backends and compares "data traces" during three stages:

  • Forward Calculation (FC): Layer-by-layer output comparison.
  • Loss Calculation (LC): Scalar loss value comparison.
  • Backward Calculation (BC): Gradient comparison for each layer.

To distinguish real bugs from harmless floating-point noise, Muffin uses the Chebyshev distance ($L_\infty$) and monitors for inconsistency amplification. If the divergence between libraries spikes significantly between consecutive layers, it is flagged as a potential bug.

Experimental Results

Muffin was tested using six diverse datasets, ranging from image classification (MNIST, ImageNet) to sequence data (Stock-Price).

Bug Discovery and Impact

Muffin detected 39 new bugs in the latest release versions of TensorFlow, CNTK, and Theano. These included 18 logic bugs (incorrect calculations) and 21 crash bugs. Several of these were confirmed and fixed by developers, such as a gradient calculation error in TensorFlow's BinaryCrossentropy and a pooling location bug in Theano.

API Coverage

Muffin exercised nearly three times more library APIs than previous state-of-the-art tools like LEMON, demonstrating the effectiveness of its architecture fuzzing approach in exploring the vast internal functions of DL libraries.

Conclusion

Muffin highlights that the training phase is a critical blind spot in current DL library testing. By generating diverse architectures and measuring inconsistency amplification, Muffin provides a robust framework for ensuring the reliability of the software foundations of AI. Future work will look into metamorphic testing to reduce reliance on multiple backends and improve automated bug localization.

Summary updated

BibTeX
@misc{gu2022muffin,
  author = {Jiazhen Gu and Xuchuan Luo and Yangfan Zhou and Xin Wang},
  title = {{Muffin: Testing Deep Learning Libraries via Neural Architecture Fuzzing}},
  year = {2022},
  eprint = {2204.08734},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2204.08734},
}
Figure