← LeaderboardThe Skill Leaderboard

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.

Published by sickn33 ↗sickn33/agentic-awesome-skills

Try your first task

A source-grounded starter task has not been verified for this skill yet.

SKILL.md

name: onnx-opset-compatibility-auditdescription: "Audit ONNX graph validity, IR/opset domain boundaries, CPU ONNX Runtime session creation, known-output numerical assertions, and custom-op limits offline."category: datarisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [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:

  • model-serving-kubernetes: deploys KServe and Triton InferenceServer manifests on Kubernetes clusters rather than auditing ONNX IR/opset/session/numerical boundaries offline.
  • transformers-js: guides client-side JavaScript inference with @huggingface/transformers and ONNX WebAssembly paths rather than running Python onnx.checker + onnxruntime.InferenceSession opset compatibility checks.
  • ml-engineer: covers general PyTorch/TensorFlow training pipelines and serving architecture without executable ONNX opset/IR compatibility tests.

When to Use

  • Upgrading ONNX exporters (torch.onnx.export, onnxscript, converters) or pinning a target onnxruntime release.
  • Checking whether a model's ir_version and per-domain opset_import versions load and execute accurately on the pinned CPU ONNX Runtime.
  • Distinguishing protobuf parse errors (INVALID_INPUT), structural ONNX graph errors, runtime opset/custom-op rejections, and wrong numerical outputs.
  • Do not use this skill to load untrusted third-party/downloaded models, register native custom-operator shared libraries, or deploy models to clusters.

Prerequisites

  • Python 3.12+ with pinned ONNX, ONNX Runtime, NumPy, and pytest packages (numpy==2.5.3 requires >=3.12; onnxruntime==1.31.0 requires >=3.11; tested with Python 3.12.10, onnx==1.23.2, onnxruntime==1.31.0, numpy==2.5.3, pytest==9.1.1).
  • Synthetic or trusted in-memory .onnx protobuf models within bounded size (16 MiB max; models referencing TensorProto.EXTERNAL tensor files are rejected as UNSUPPORTED).
  • No GPU hardware, CUDA drivers, external model downloads, or network access required.

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

  • Tests strictly on CPUExecutionProvider (onnxruntime==1.31.0); a passing CPU fixture never proves CUDAExecutionProvider, TensorrtExecutionProvider, CoreMLExecutionProvider, quantized NPU, or production throughput compatibility.
  • Custom operators (com.microsoft, custom domains) and external-weight models (> 2 GiB protobuf split .onnx_data) are rejected or require explicit trusted custom-op libraries outside this offline audit.
  • Small synthetic input tensors do not establish full-domain numerical stability across edge shapes (batch=0, dynamic sequence lengths, FP16 overflow).

Safety and Side Effects

  • Strictly offline and in-memory over small synthetic ONNX protobuf graphs (16 MiB limit).
  • Never downloads untrusted external checkpoints, loads custom native .dll/.so operator extensions, or deploys endpoints.

Sources and related skills