ONNX Runtime
ONNX Runtime (ORT for short) is a cross-platform inference engine open-sourced by Microsoft for efficiently executing models in ONNX format. It supports not only ONNX but can also directly load formats such as TorchScript exported from PyTorch and SavedModel from TensorFlow; it is one of the most widely used general inference runtimes in production environments today, covering cloud, desktop, mobile and the browser.
Core Principles
The core of ONNX Runtime is a two-layer architecture of graph optimization plus execution providers (EPs). After a model is loaded it first goes through a series of graph-level optimizations: operator fusion (combining Conv+BN+ReLU into a single operator), constant folding, memory reuse planning, layout transformation elimination and so on, and then subgraphs are assigned to different hardware for execution according to the capabilities of each EP.
The EP is its trump card: on CPU it provides highly optimized MLAS kernels using AVX2/AVX-512 and ARM NEON; on GPU there are the CUDA EP and the TensorRT EP; there are also DirectML (Windows), OpenVINO (Intel), CoreML, QNN (Qualcomm), WebGPU/WebAssembly and others. A single model can run some operators on TensorRT and fall back the rest to CUDA or CPU, and this subgraph partitioning capability lets it still run when some operators are unsupported.
At the execution level it supports multithreading, batching, memory pools and IO Binding (zero-copy input and output), and provides multi-language APIs including C/C++/Python/C#/Java through OrtSession.
Key Points
1. Quantization support: built-in dynamic quantization (weights converted to int8, activations quantized at runtime), static quantization (requiring calibration data) and QAT-aware quantization; int8 quantization often brings 2 to 4 times speedup on CPU with usually controllable accuracy loss.
2. Relationship with TensorRT: the TensorRT EP lets ORT borrow TensorRT's extreme optimizations, balancing ease of use and performance; pure TensorRT requires handling engine building and operator compatibility by oneself.
3. ONNX Runtime GenAI: an extension specifically for large language models with built-in KV Cache management, sampling and batching logic, able to run the ONNX versions of models such as Llama, Phi and Qwen directly.
4. Mobile and Web: ORT Mobile supports Android/iOS, and ORT Web is based on WebAssembly plus WebGPU, enabling local inference inside the browser.
5. Comparison with native PyTorch inference: for small models and single-call scenarios native PyTorch is already enough; for batch throughput, cross-hardware deployment and resource-constrained edge scenarios, ORT has a clear advantage.
Common Misconceptions
Misconception one is thinking ORT only runs ONNX, whereas it actually supports multiple formats and custom operators. Misconception two is thinking quantization is always lossless; without a representative calibration set, static quantization may lose noticeable accuracy, so it needs layer-by-layer evaluation. Misconception three is ignoring EP priority configuration, causing subgraphs that should run on GPU to fall back to CPU and become slower. In addition, ORT is an inference engine and does not do training (there is ORT Training on the training side, but its ecosystem is weak).
Application Scenarios
Cloud batch inference services, AI embedded in Windows desktop applications, offline recognition on mobile, local models in the browser, edge box deployment, model quantization and compression, unified delivery across hardware, and private inference inside enterprise intranets