liveBook · Manning

ORT for Python

As explained in Domain-Specific Small Language Models

The Python interface to ONNX Runtime used here to evaluate ONNX models, nodes, and intermediate results.

Python-side evaluation can inspect an ONNX model’s full graph, individual nodes, and intermediate values. This helps locate inefficiencies introduced during conversion or framework migration. section 10.3

For operational evaluation, it can:

  • Run a complete model or an individual node using ONNX’s ReferenceEvaluator. section 10.3
  • Increase verbosity to show operations, input values, and intermediate outputs. section 10.3
  • Compare original and custom-node implementations for output agreement and execution time. section 10.3
from onnx.reference import ReferenceEvaluator

sess = ReferenceEvaluator(onnx_model)

A minimal ReferenceEvaluator setup for running an ONNX model. section 10.3

sess = ReferenceEvaluator(onnx_optimized_model, verbose=2,
➥ new_ops=[AddEyeLike])

Register a custom operator with the evaluator to test an optimized graph. section 10.3

How Domain-Specific Small Language Models covers it

How deep it goes
Evaluates full graphs, individual nodes, and intermediate values, then compares custom-node outputs and timings.
Examples
Uses linear regression graphs, an EyeLike-plus-Add custom operator, and GPT-2 model optimization.
What it assumes
Assumes an ONNX model and prepared input arrays; demonstrates model construction and evaluation rather than teaching Python or ONNX from zero.
What you can do after
Apply ReferenceEvaluator to run models or nodes, inspect intermediate results, and compare optimized implementations.
How it connects
Connects ONNX graph evaluation with custom operators, linear regression, and GPT-2 graph optimization.

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.