microsoft/onnxscript

ONNX Script enables developers to naturally author ONNX functions and models using a subset of Python.

What it solves

ONNX Script simplifies the process of authoring, debugging, and optimizing ONNX models. Instead of manually constructing complex ONNX graphs, developers can use a concise, Python-based syntax to define functions and models that are then translated into valid ONNX graphs.

How it works

The project provides a converter that traverses the Python Abstract Syntax Tree (AST) to translate Python functions (marked with a @script decorator) into ONNX graphs. It also supports the inverse process, converting ONNX models back into ONNX Script for easier readability. To aid debugging, it includes a runtime shim that allows for "eager-mode" evaluation of these functions using ONNX Runtime or a Python-only reference evaluator.

Who it’s for

AI developers and ML engineers who need to create or modify ONNX models and want a more natural, debuggable, and expressive way to define them compared to raw graph construction.

Highlights

  • Pythonic Authoring: Define ONNX functions using a subset of Python for a more concise and simple experience.
  • Bidirectional Conversion: Supports translating Python functions to ONNX graphs and vice versa.
  • Eager Mode: Enables immediate evaluation of functions for faster debugging and validation of intermediate results.
  • Optimization Tools: Includes an optimizer for constant folding and dead code elimination, and a rewriter to replace specific graph patterns based on user-defined rules.

Related

  • Project
  • Project
  • Project
  • Project
  • Project