What is ONNX?

Open Neural Network Exchange: a common model format for exchanging models between frameworks and inference runtimes.

Field: AI Hardware & Software Stack

Japanese name: ONNX

What ONNX defines

ONNX is an open specification for representing a model as a computational graph. It defines three main things: how the graph is represented, standard data types, and standard operators. A graph is a list of nodes, each representing an operation, and it contains no cycles. The weights fixed by training are saved together with the model as named tensors. A file saved in this format is loaded and executed by other software.

Why a common format is needed

The framework used for training and the environment that runs inference are often different. If every format is different, a conversion tool is needed for each combination. With 3 frameworks and 4 runtimes, for example, that is 3 × 4 = 12 converters. With a common format in between, 3 exporters and 4 importers are enough, 3 + 4 = 7 in total. Because the training environment and the inference environment are decoupled, it becomes easier to choose an execution engine that suits each device.

Operator versions and cautions

The collection of standard operators is called an operator set and is managed by version number. A model states which version of the operator set it depends on. If the loading side does not support that version or an operator, the model cannot run. ONNX defines how a model is represented and what each operator means, not how it is implemented and executed or how fast it runs. The speed of the same file varies with the runtime that loads it and the hardware. It is used mainly for handing a trained model over to inference.

Try it: questions about ONNX

Which describes ONNX?

  1. AThe name of an AI-specific semiconductor chip
  2. BA method for compressing AI training data
  3. CA common model format for exchanging models between different frameworks and inference runtimes
Show answer and explanation

Answer: C. A common model format for exchanging models between different frameworks and inference runtimes

ONNX (Open Neural Network Exchange) is a standard for representing a model's computational graph and weights in a common format. A model trained in PyTorch or similar can be exported to ONNX and then loaded and run by other vendors' inference runtimes or hardware toolchains. Decoupling the training environment from the inference environment makes it easy to choose the best execution stack for each device.

Why can inference runtimes such as TensorRT or ONNX Runtime run faster than using the training framework directly for inference?

  1. AThey optimize the graph for inference only, applying fusion, quantization and hardware-specific kernel selection
  2. BThey skip computation and give approximate answers
  3. CThey increase the number of model weights
Show answer and explanation

Answer: A. They optimize the graph for inference only, applying fusion, quantization and hardware-specific kernel selection

Training frameworks prioritize flexibility and recording for backpropagation, which is wasteful for inference alone. After loading a model, an inference runtime strips parts unneeded for inference, fuses operations, converts weights and activations to lower precision where appropriate and selects the fastest kernels for the target GPU or NPU. This greatly reduces latency and memory for the same model.

FAQ

Is ONNX the name of an inference runtime?

No, it is the name of a specification that defines a model format. The software that executes models in that format is separate. ONNX Runtime is one such inference runtime.

Will a model exported to ONNX run in any environment?

Not necessarily. The executing side has to support the operators the model uses and their versions. If an unsupported operator is included, conversion or loading may fail.

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary