ONNX (Open Neural Network Exchange) is an open standard for representing machine-learning models across frameworks and hardware platforms. A model trained in one framework can be exported to ONNX for inference without making the training framework the only deployment option. The format describes the model; ONNX Runtime is a separate, optional way to execute it. section 5.1
An ONNX model is a computation graph built from operators such as matrix multiplication, addition, and neural-network layers. Its tensors have defined element types and shapes, and its graph is serialized using protobuf. The format supports common numerical types as well as specialized types such as bfloat16. This structure makes a model portable, but a valid export still needs an output comparison against the original model. section 5.2 section 5.7
A practical deployment path separates conversion, execution, and optimization:
- Export a trained model with a supported tool. PyTorch’s torch.onnx.export exposes settings such as operator-set version, input and output names, and dynamic axes; Transformers and Optimum offer less manual conversion paths. section 5.5 section 6.3
- Check the exported schema, then compare inference outputs with the original model on test inputs. A successful schema check alone does not establish matching behavior. section 5.5
- Choose a runtime and hardware provider. ONNX Runtime supports CPU and GPU execution providers; graph optimizations, quantization, and GPU I/O binding are further options when performance matters. section 5.6 section 5.7
A small graph and a production-scale export
For Y = XA + B, an ONNX graph uses MatMul followed by Add; Python helpers declare typed inputs and outputs, assemble the graph, check it, and serialize it. For question answering, a BERT model is exported with variable batch and sequence axes, checked, and compared with its original outputs on SQuAD samples before CPU inference is benchmarked. The latter workflow tests deployment behavior, not just whether a file can be saved. section 5.2 section 5.5
Portability does not mean every deployment has the same cost. ONNX Runtime can optimize a graph during conversion or session initialization, and transformer-specific optimization can be applied to an exported model. On a GPU, default CPU placement of inputs and outputs can add transfers; IOBinding allows data to remain on the execution device. Measure latency and check accuracy after changes such as 8-bit quantization. section 5.6.1 section 5.6.2 section 6.3






