Skip to content

Commit 609f1be

Browse files
committed
onnxsim: pin ir_version in test_profiling's _foldable_model
cp312-manylinux_riscv64's test step failed all 10 tests in tests/test_profiling.py: RuntimeError: Your model ir_version 14 is higher than the checker's (13). _foldable_model() builds its onnx.ModelProto via helper.make_model() with no ir_version, so the model is stamped with whatever onnx.IR_VERSION the installed onnx package currently defines - and our registry's newest riscv64 onnx build for cp312 is 1.23.0. onnxsim statically links a vendored onnx (via the onnx-optimizer git submodule, frozen at a pinned commit) whose checker only recognizes up to ir_version 13, so any onnx installed newer than that submodule's pin breaks every caller of _foldable_model() before the test gets to what it actually checks. Every other test file in the suite (test_python_api.py, test_function_rewriter.py, test_constant_fold_determinism.py, ...) already pins ir_version explicitly for exactly this reason - test_profiling.py is the one file that didn't. Not riscv64-specific: the same break reproduces on any platform the moment pip resolves an onnx release newer than the vendored submodule tolerates. Patches tests/test_profiling.py to pin ir_version=10, matching the convention already used throughout the rest of the suite, and wires the `Checkout python-wheels` + `Apply patches` steps (mirroring build-py-spy.yml) into build-onnxsim.yml so the patch actually lands during CI.
1 parent d6481a8 commit 609f1be

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎.github/workflows/build-onnxsim.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ on:
1616
paths:
1717
- '.github/workflows/build-onnxsim.yml'
1818
- 'docs/packages/onnxsim.yaml'
19+
- 'patches/onnxsim/**'
1920
push:
2021
branches: [main]
2122
paths:
2223
- '.github/workflows/build-onnxsim.yml'
2324
- 'docs/packages/onnxsim.yaml'
25+
- 'patches/onnxsim/**'
2426

2527
concurrency:
2628
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -79,6 +81,15 @@ jobs:
7981
submodules: recursive
8082
persist-credentials: false
8183

84+
- name: Checkout python-wheels
85+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
86+
with:
87+
path: python-wheels
88+
persist-credentials: false
89+
90+
- name: Apply patches
91+
run: git apply -v python-wheels/patches/onnxsim/${{ env.ONNXSIM_VERSION }}/*.patch
92+
8293
- name: Build wheels
8394
uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
8495
with:

‎docs/packages/onnxsim.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ warning: |
1414
handling.
1515
versions:
1616
- version: 0.7.3
17+
patched: true
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Ludovic Henry <git@ludovic.dev>
3+
Date: Thu, 24 Sep 2026 00:00:00 +0000
4+
Subject: [PATCH] tests: pin ir_version in test_profiling's _foldable_model
5+
6+
Every other test file that builds an onnx.ModelProto by hand pins
7+
ir_version explicitly (test_python_api.py, test_function_rewriter.py,
8+
test_constant_fold_determinism.py, etc. all pass ir_version=... to
9+
helper.make_model()). test_profiling.py's _foldable_model() is the one
10+
holdout: it calls helper.make_model(graph, opset_imports=[...]) with no
11+
ir_version, so the model is stamped with whatever onnx.IR_VERSION the
12+
currently installed onnx package defines.
13+
14+
onnxsim statically links a vendored onnx (via the onnx-optimizer git
15+
submodule, frozen at a pinned commit) into its C++ core, and that
16+
core's checker enforces its own, older notion of the max supported IR
17+
version. Once the *installed* onnx package (an unpinned "onnx" runtime
18+
dependency in pyproject.toml) is newer than whatever onnx-optimizer's
19+
submodule was pinned to at release time, every one of
20+
_foldable_model()'s callers in this file fails identically:
21+
22+
RuntimeError: Your model ir_version 14 is higher than the
23+
checker's (13).
24+
25+
before reaching any of what the test actually means to check (the
26+
profiler's spans, the OrtSession nesting, the env var save/restore).
27+
This is a real ambient-versioning gap, not a riscv64-only symptom: the
28+
same break reproduces on any platform the moment pip resolves an onnx
29+
release newer than the vendored submodule tolerates, which is exactly
30+
why every sibling test file already pins ir_version defensively -
31+
test_profiling.py just missed doing the same for its one hand-built
32+
model.
33+
34+
Match the existing convention used throughout the suite (ir_version=10
35+
regardless of opset) so the fixture stays valid across the wide range
36+
of onnx versions the unpinned runtime dependency can resolve to.
37+
38+
Upstream-Status: To upstream [no push/issue access to onnxsim/onnxsim from
39+
this environment - only riseproject-dev/python-wheels is attached; the fix
40+
is a one-line ir_version pin matching every sibling test file's existing
41+
convention]
42+
43+
Signed-off-by: Ludovic Henry <git@ludovic.dev>
44+
---
45+
diff --git a/tests/test_profiling.py b/tests/test_profiling.py
46+
--- a/tests/test_profiling.py
47+
+++ b/tests/test_profiling.py
48+
@@ -29,7 +29,18 @@
49+
x = helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 4])
50+
y = helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 4])
51+
graph = helper.make_graph([add_const, add_x], "g", [x], [y], [a, b])
52+
- model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)])
53+
+ model = helper.make_model(
54+
+ graph,
55+
+ opset_imports=[helper.make_opsetid("", 17)],
56+
+ # Pin ir_version like every other model-building test in this suite
57+
+ # already does (test_python_api.py, test_function_rewriter.py, etc.):
58+
+ # onnx.helper.make_model() otherwise stamps the installed onnx package's
59+
+ # current onnx.IR_VERSION, which floats upward with each onnx release and
60+
+ # can exceed what the vendored onnx-optimizer/onnx submodule's checker
61+
+ # (frozen at a pinned commit) accepts, e.g. "Your model ir_version 14 is
62+
+ # higher than the checker's (13)" once a newer onnx is installed.
63+
+ ir_version=10,
64+
+ )
65+
onnx.checker.check_model(model)
66+
return model
67+

0 commit comments

Comments
 (0)