ExAIS: Executable AI Semantics

Richard Schumi, Jun Sun · DOI

Introduction

In traditional software engineering, formal semantics for languages like C ensure that compilers behave predictably and correctly. Deep learning frameworks such as TensorFlow and PyTorch have become the "compilers" for a new programming paradigm: neural networks. However, these frameworks are massive, complex, and lack a formal correctness specification. This absence creates two major hurdles: the Oracle Problem, where testers cannot easily verify if a library's output is mathematically exact, and the Generation Problem, where creating valid, non-crashing neural network models for fuzzing is notoriously difficult due to strict layer requirements.

The ExAIS Approach

To address these challenges, researchers developed ExAIS (Executable AI Semantics). ExAIS provides a formal, executable specification for 72 TensorFlow layers using Prolog, a declarative logic programming language. Prolog was chosen because its paradigm is fundamentally different from the C++ and Python used in TensorFlow, making it highly unlikely to replicate the same implementation bugs found in the target library.

The ExAIS testing workflow, comparing TensorFlow outputs against a formal Prolog specification.

The system leverages these semantics in two primary ways:

  1. A Strong Oracle: By executing the Prolog specification, ExAIS calculates precise expected constraints and outputs, allowing for direct comparison against TensorFlow’s actual results.
  2. Guided Fuzzing: ExAIS introduces a "badness value"—a distance metric that quantifies how far a generated model is from being valid (e.g., due to shape mismatches). This allows the test generator to mutate models systematically until they are valid.

Key Results

The application of formal semantics yielded significant improvements in both testing efficiency and bug detection. ExAIS achieved a 99.1% success rate in generating valid AI models, a massive leap over the 25% success rate of previous documentation-guided approaches.

An example of a complex, valid neural network architecture generated and verified by ExAIS.

Beyond model generation, the tool revealed 14 issues in TensorFlow, including:

  • 3 Logic Bugs: Most notably, a bug in the ReLU activation function where it behaved incorrectly with negative thresholds.
  • 6 Error Message Bugs: Cases where TensorFlow provided misleading or inconsistent failure reasons.
  • 5 Documentation Bugs: Discrepancies between the official manual and the actual code implementation.

Discussion and Future Work

The success of ExAIS suggests that AI frameworks are excellent candidates for formal methods because they rely on a limited set of functions with relatively stable mathematical behaviors. While the current implementation focuses on the "forward pass" (inference) and static weights, it demonstrates that formal rigor can be brought to the heart of the AI stack. Future work aims to extend these semantics to cover the training process, backpropagation, and automated AI model synthesis, where users provide high-level requirements and the system generates a mathematically sound architecture.

Summary updated

BibTeX
@inproceedings{schumi2022exais,
  author = {Richard Schumi and Jun Sun},
  title = {{ExAIS: Executable AI Semantics}},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510112},
}
Figure