ONNX export and parity
Quick answer
ONNX is a graph interchange format that represents operators, tensors and model metadata for compatible runtimes. Export success alone does not establish prediction parity. Examples use standard-library Python; optional ONNX execution is not tested. ByteMind execution is unverified.
Numerical parity
import matha=[1.0,100.0];b=[1.000001,100.00001]print(all(math.isclose(x,y,rel_tol=1e-6,abs_tol=1e-8) for x,y in zip(a,b)))Expected output (locally tested): True. A declared relative tolerance handles magnitude differences.
How it works
An exporter lowers framework computation to supported graph operators. The chosen opset fixes operator semantics, while runtime/provider capabilities constrain which graphs and data types execute. An unsupported operation must block export or receive an explicitly reviewed translation; never silently drop it. Check preprocessing, raw outputs and postprocessing on the same representative fixtures, including boundary values and batch sizes. Use declared absolute and relative tolerances rather than exact bit equality for floating point; compare discrete decisions separately near thresholds. For PyTorch, torch.onnx.export with dynamo=True is the documented modern route; an ONNX Runtime InferenceSession then runs the graph using named inputs. The optional script is syntax-checked only because ONNX dependencies are absent. The local milestone exports a restricted JSON linear graph and compares Python and NumPy, which is not ONNX conformance.
Decision parity is distinct
a,b=0.499999,0.500001print(abs(a-b)<0.00001, (a>=0.5)==(b>=0.5))Expected output (locally tested): True False. Small numerical differences can flip a threshold decision.
Common mistakes
A successful conversion may still change normalization, output order or threshold decisions. One matching sample cannot establish general parity.
Practice and next steps
Create a score just below a decision threshold and a second score just above it. Show how numerically close outputs can disagree on the discrete decision.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
ONNX export and parity — knowledge check
Apply onnx export and parity to small examples and debugging scenarios.
What does ONNX opset describe?
What if an operator is unsupported?
Why compare discrete decisions too?
What is a useful parity fixture?
What does the JSON lab prove?