Sionnx: Automatic Unit Test Generator for ONNX Conformance

Xinli Cai, Peng Zhou, Shuhan Ding, Guoyang Chen, Weifeng ZhangarXiv 2019 · arXiv

Abstract

Model portability remains a critical bottleneck in the deployment of machine learning models across heterogeneous hardware and software backends. The Open Neural Network Exchange (ONNX) was established to standardize operator definitions; however, ensuring backend compliance currently relies on a limited set of manual test cases. This paper introduces Sionnx, the first automated unit test generator for ONNX conformance. By leveraging a custom Operator Specification Language (OSL) and a targeted three-phase randomization strategy (TDBc-gen), Sionnx replaces manual validation with high-coverage, automated testing.

Introduction

In the contemporary AI landscape, moving models between frameworks like PyTorch and TensorFlow or onto specialized hardware often results in subtle execution discrepancies. These issues arise because different platforms implement operators—such as convolutions or matrix multiplications—with slight variations. While ONNX serves as a "universal translator" to mitigate these issues, its effectiveness is limited by the current conformance testing infrastructure.

The authors identify a critical flaw: the current system for checking if a backend complies with ONNX standards relies on a small number of handwritten test cases. This manual approach is inherently slow, error-prone, and fails to capture complex edge cases. Consequently, it is difficult for developers to trust that a model will behave identically across different systems. There is a pressing need for a systematic approach to verify that backends strictly adhere to the ONNX standard.

Methodology

Sionnx addresses the limitations of manual testing through a structured framework designed for automated test generation. The architecture consists of three core components: the Operator Specification Language (OSL), Reference Algorithms, and the TDBc-gen randomization engine.

The Sionnx framework architecture, illustrating the generation of ONNX compliance tests from OSL and reference algorithms.

Operator Specification Language (OSL)

Built upon LLVM’s TableGen, OSL provides a high-level, structured way for developers to define operator constraints. A key insight driving OSL's design is that almost all operator constraints can be distilled into three fundamental properties: Data Type, Data Dimension, and Data Value Range. This simplification allows for a very compact and efficient specification language. Developers can describe constraints—such as an input needing to be between -1 and 1, or an axis attribute not exceeding the number of dimensions—in a way that the generator can easily interpret.

Reference Algorithms

To validate test results, Sionnx requires a "ground truth" or reference result. Writing these reference implementations in raw Python or NumPy is a tedious task; for instance, an LSTM cell can require over 60 lines of code. Sionnx innovates by "borrowing" logic from mature, well-established frameworks like TensorFlow to act as the gold standard. By leveraging these existing implementations, Sionnx significantly reduces the human effort required to define reference behavior for complex operators.

TDBc-gen: The Randomization Engine

The core of Sionnx's generation capability is TDBc-gen, the randomization engine. Rather than employing brute-force random testing, it uses a sophisticated three-phase approach to ensure high coverage:

  • Type Phase: Covers all valid combinations of data types, such as float32 and int8.
  • Dimension Phase: Systematically tests different tensor shapes to ensure structural robustness.
  • Boundary Conditions Phase: Specifically targets edge cases, such as dimensions of size 1, which are frequent sources of bugs or specialized behaviors like broadcasting. This targeted approach finds bugs that purely random testing would likely miss.

Evaluation and Results

The authors conducted an empirical study covering the entire set of ONNX operators to ensure that OSL rules were expressive enough to capture every existing operator's constraints. The results demonstrate that Sionnx successfully automates the conformance testing process, moving beyond "best effort" manual suites.

Key results include:

  • Systematic Automation: Sionnx transforms ONNX testing into a systematic, automated process.
  • Enhanced Coverage: The framework generates tests with significantly larger coverage than existing handwritten suites, particularly for complex dependencies between attributes and input shapes.
  • Community Accessibility: The tool is designed to be lightweight and cross-framework, and it has been open-sourced to the community via GitHub.

Limitations and Future Work

While Sionnx represents a significant advancement, several areas for improvement remain. Currently, reference algorithms are primarily supported in Python, and extending this support to other languages is a priority for future work. Additionally, certain highly complex dependencies (e.g., in DepthToSpace or BatchNorm) are currently handled within the Sionnx compiler; refining OSL to handle these "corner cases" more elegantly is a potential area for improvement. Finally, the authors note that performance could be further improved by utilizing GPU acceleration for the reference checks, moving beyond the current CPU-based validation.

Summary updated

BibTeX
@misc{cai2019sionnx,
  author = {Xinli Cai and Peng Zhou and Shuhan Ding and Guoyang Chen and Weifeng Zhang},
  title = {{Sionnx: Automatic Unit Test Generator for ONNX Conformance}},
  year = {2019},
  eprint = {1906.05676},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1906.05676},
}
Figure