Open model format + runtime · onnx & onnxruntime · export / run / optimize · verified 2026

ONNX cheat sheet

ONNX is an open format for ML models — train in PyTorch/TF/sklearn, export once, run anywhere. ONNX Runtime (onnxruntime) is the fast, cross-platform engine: load a .onnx file into an InferenceSession and call run() on CPU, CUDA, TensorRT, DirectML, CoreML, and more via execution providers. The onnx package is the format toolkit — build, check, shape-infer, and edit the graph. Quantize & optimize for smaller/faster deployment. Targets onnx 1.22 + onnxruntime 1.29 (2026).

run models export / create providers & perf the ONNX format versioning & ecosystem gotcha most common

Verified 2026-08-31 against onnxruntime.ai & onnx.ai / PyPI: onnxruntime 1.29.0 (2026-08-17, Python 3.11–3.14) and onnx 1.22.0 (2026-06-15, Python 3.10+). Two packages: onnx (format/graph toolkit) and onnxruntime (inference engine) — install what you need.

Outline

Most users start by running a model with onnxruntime; export from your framework; then tune providers, quantize, and (if needed) edit the graph with the onnx toolkit.

Run models

  1. 1Install
  2. 2InferenceSession
  3. 3Inputs, outputs & IO binding

Export / create

  1. 4Export from PyTorch
  2. 5Export sklearn / TF / others

Providers & performance

  1. 6Execution providers
  2. 7Session options & perf
  3. 8Quantization

The ONNX format

  1. 9Model structure & checker
  2. 10Graph helpers & tools

Versioning & ecosystem

  1. 11Opset & versioning
  2. 12Ecosystem & deploy

Run Models

Load a .onnx file and run inference — the 90% use case.

1Installtwo packages
2InferenceSessionrun a model
3Inputs, outputs & IO bindingintrospect

Export & Create

Convert a trained model from your framework into a portable .onnx file.

4Export from PyTorchtorch.onnx
5Export sklearn / TF / othersconverters

Providers & Performance

Pick the hardware backend, tune the session, and shrink the model.

6Execution providersthe backend
7Session options & perftune it
8Quantizationsmaller & faster

The ONNX Format

The onnx package to load, validate, and edit the model graph itself.

9Model structure & checkervalidate
10Graph helpers & toolsbuild / edit

Versioning & Ecosystem

Mind the opset when exporting; know where ONNX plugs into deployment.

11Opset & versioningcompatibility
12Ecosystem & deployrun anywhere

Worth memorizing

two packagesonnxruntime (run) · onnx (format toolkit)
InferenceSessionload .onnx, pass providers=[...]
sess.runrun(None, {input_name: np_array})
get_inputs()discover names / shapes / dtypes
torch.onnx.exportdynamo=True + dynamic_axes
skl2onnx / tf2onnxexport sklearn / TF models
providers orderCUDA/TensorRT ... then CPU fallback
onnxruntime-gpurequired for CUDA EP (not the CPU pkg)
quantize_dynamicweights -> INT8, ~4x smaller
checker + shape_inferencevalidate & propagate shapes
opset_versionmust be supported by target runtime
dtype matchx.astype(np.float32) — #1 gotcha