Home / Market / onnx opset compatibility audit

onnx opset compatibility audit

Audit ONNX graph validity, IR/opset domain boundaries, CPU ONNX Runtime session creation, known-output numerical assertions, and custom-op limits offline.

skill★ 509030 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- name: onnx-opset-compatibility-audit description: "Audit ONNX graph validity, IR/opset domain boundaries, CPU ONNX Runtime session creation, known-output numerical assertions, and custom-op limits offline." category: data risk: safe source: self source_type: self date_added: "2026-12-01" author: Koushik-Katkam tags: [onnx, onnxruntime, opset, compatibility, ml-inference, verification]

---

ONNX Opset Compatibility Audit

Overview

Verify ONNX model files offline using pinned onnx==1.23.2 and onnxruntime==1.31.0 across three strictly separated stages: (1) ONNX structural graph validity (onnx.checker.check_model), (2) ONNX Runtime InferenceSession instantiation for concrete ir_version and opset_import domains, and (3) known-output numerical inference assertions (np.allclose). Explicitly exposes where a model passes onnx.checker yet fails runtime loading (such as unsupported opsets or unregistered custom operators), and never infers GPU/TensorRT/production compatibility from a passing CPUExecutionProvider fixture.

Distinction from existing ML serving and deployment skills:

When to Use

Prerequisites

How It Works

1. Inspect IR version, opset imports, external data, and graph validity

  1. Parse bounded serialized bytes with onnx.load_from_string (INVALID_INPUT on corrupt protobuf bytes).
  2. Reject model-local functions and training sections as outside this harness's inference-only scope. Recursively scan supported graph tensor containers (graph.initializer, graph.sparse_initializer, node attributes t/tensors/sparse_tensor/sparse_tensors, and nested subgraph g/graphs attributes up to bounded depth 16) and reject any TensorProto.EXTERNAL / external_data reference (EXTERNAL_DATA_UNSUPPORTED -> UNSUPPORTED, or SUBGRAPH_DEPTH_EXCEEDED -> UNSUPPORTED beyond depth 16) before invoking onnx.checker or InferenceSession, so no external tensor data files are opened outside synthetic/in-memory payloads.
  3. Extract model.ir_version and {imp.domain or "ai.onnx": imp.version for imp in model.opset_import}.
  4. Run onnx.checker.check_model(model) separately so structural graph errors (ValidationError) are recorded as ONNX_CHECKER_FAILED without conflating them with runtime opset limits.

2. Instantiate pinned ONNX Runtime session and separate inference/numerical status

Run the local verification suite in ONNX opset compatibility harness:

  1. Session creation (CPUExecutionProvider): Attempt onnxruntime.InferenceSession(model_bytes, providers=["CPUExecutionProvider"]). Observe that ir_version=10, opset=99 passes onnx.checker yet fails InferenceSession, proving graph validity is not runtime compatibility.
  2. Unsupported IR & custom operator domain checks: Reject ir_version=99 and custom domains (com.example.custom) that fail session creation unless registered; classify non-default execution provider demands separately.
  3. Inference execution & dense-tensor numerical verification: Validate sample_inputs / expected_outputs structures, catch session.run(...) failures as structured INFERENCE_FAILED errors rather than uncaught exceptions, require exact key equality across all model output names (flagging both missing and unexpected extra keys), classify non-np.ndarray runtime outputs (such as ONNX Sequence lists or Map dicts) as structured UNSUPPORTED (NON_NDARRAY_OUTPUT) before reading .shape, and explicitly report numerical_status="NOT_TESTED" when numerical assertions were not run.

Examples

Run the self-contained verification suite in ONNX opset compatibility harness:

User request: "Verify our exported Relu+Linear ONNX graph passes checker, loads in ONNX Runtime 1.31.0, and matches expected values."
Inputs: Synthetic in-memory ONNX ModelProto bytes with explicit ir_version and opset_import.
Expected result: Compatible fixture (ir_version=10, ai.onnx opset=21) passes all 3 stages on CPUExecutionProvider;
  opset=99 passes checker but fails ORT session creation; ir_version=99 fails both; wrong bias fails numerical stage only.

Limitations

Safety and Side Effects

Sources and related skills