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 Inference

From Leeroopedia


Knowledge Sources
Domains Model_Evaluation, Inference
Last Updated 2026-02-10 00:00 GMT

Overview

An execution mechanism that runs an ONNX model node by node using pure Python operator implementations, producing output tensors from input data.

Description

Reference inference executes an ONNX model by processing each node in topological order, feeding the outputs of completed nodes as inputs to subsequent nodes. For each node, the evaluator looks up the appropriate Python operator implementation, passes the input tensors, and collects the output tensors. This pure Python execution provides a reference implementation of the ONNX specification that can be used to validate the correctness of optimized runtimes.

The execution supports both standard inference (returning only the requested outputs) and intermediate mode (returning all intermediate tensor values for debugging).

Usage

Use this principle after initializing a ReferenceEvaluator and preparing input data as NumPy arrays. The evaluator's run method executes the model and returns results that can be compared against expected outputs or outputs from other runtimes.

Theoretical Basis

Reference inference is a topological execution of the computation graph:

results= Failed to parse (syntax error): {\displaystyle \forall n \in \text{topological\_order}(G): \text{results}[\text{outputs}(n)] = \text{impl}(n)(\text{results}[\text{inputs}(n)]) }

Pseudo-code:

# Abstract inference algorithm
def run(graph, feed_inputs):
    results = {}
    results.update(initializers)  # constant values
    results.update(feed_inputs)   # user-provided inputs
    for node in topological_order(graph.nodes):
        inputs = [results[name] for name in node.inputs]
        outputs = node.implementation.run(*inputs)
        for name, value in zip(node.outputs, outputs):
            results[name] = value
    return [results[name] for name in requested_outputs]

Related Pages

Implemented By

Page Connections

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