Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Onnx Onnx Reference Evaluation Init

From Leeroopedia


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:

  1. Parse: Convert protobuf to internal representation
  2. Resolve: Map each node's (domain, op_type, version) to a Python implementation class
  3. Load: Convert initializers from TensorProto to NumPy arrays
  4. 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)

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment