Principle:Onnx Onnx Reference Evaluation Init
| Knowledge Sources | |
|---|---|
| Domains | Model_Evaluation, Testing |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
An initialization mechanism that prepares a pure Python execution engine for running ONNX models by loading operator implementations and resolving the execution graph.
Description
Reference evaluation initialization creates an execution context for ONNX models using pure Python/NumPy operator implementations. Unlike production runtimes (ONNX Runtime, TensorRT), the reference evaluator prioritizes correctness and readability over performance, making it ideal for testing, debugging, and validating operator implementations.
During initialization, the evaluator parses the model protobuf, resolves each node's operator to a Python implementation class (from the ~170 files in onnx/reference/ops/), loads initializers as NumPy arrays, and optionally substitutes optimized operator variants. The evaluator also supports custom operator implementations via the new_ops parameter.
Usage
Use this principle when you need a reference execution of an ONNX model for testing, debugging, or validating operator behavior. The reference evaluator is not optimized for production inference but provides a faithful implementation of the ONNX specification that can be used to verify the correctness of optimized runtimes.
Theoretical Basis
Reference evaluation initialization performs:
- Parse: Convert protobuf to internal representation
- Resolve: Map each node's (domain, op_type, version) to a Python implementation class
- Load: Convert initializers from TensorProto to NumPy arrays
- Wire: Establish the execution order from the graph topology
Pseudo-code:
# Abstract initialization
def init_evaluator(model):
graph = model.graph
opset = {d.domain: d.version for d in model.opset_import}
implementations = {}
for node in graph.node:
impl_class = find_implementation(node.op_type, opset[node.domain])
implementations[node] = impl_class(node.attributes)
initializers = {t.name: to_numpy(t) for t in graph.initializer}
return EvaluationContext(implementations, initializers, graph)