Skip to content

onnxsim: Add version 0.7.3 - #2266

Merged
luhenry merged 6 commits into
mainfrom
onnxsim
Sep 25, 2026
Merged

luhenry merged 6 commits into
mainfrom
onnxsim

Conversation

@luhenry

@luhenry luhenry commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Compiles a C++ extension (via nanobind) that statically links a vendored onnx-optimizer, onnx and protobuf to simplify ONNX graphs. Upstream publishes no riscv64 wheel.

Mirrors upstream's build-and-test.yml, narrowed to the same onnxoptimizer-style static-link shape already ported in #2258.

Differs from upstream

  • nanobind and protobuf pip-installed before configure - CMake locates nanobind via python -m nanobind --cmake_dir and would otherwise fetch it from GitHub
  • ONNXSIM_RELEASE set from the tag - upstream's own setup.py appends a .devN git-describe suffix without it, which would have published onnxsim-0.7.3.dev0

Matrix: cp311 and cp312 only - onnx has no riscv64 wheel for cp310; cp312's abi3 wheel also serves 3.13+

Testing

  • same as upstream; the optional torch/onnxscript/timm/sympy/onnxslim/ultralytics/rfdetr paths are pytest.importorskip-guarded and skip without riscv64 wheels
  • onnxruntime added only on cp312, the only interpreter with a riscv64 wheel for it
  • cp311 (no onnxruntime) deselects test_fuse_conv_bn_into_conv/test_fuse_convtranspose_bn - onnx's ReferenceEvaluator has a BatchNormalization_9 bug (always mixes in batch stats regardless of momentum) that these two tests hit only without onnxruntime; reproduces identically on x86_64

License: OK - the wheel statically links onnx (MIT) and protobuf (BSD-3-Clause) via the vendored onnx-optimizer (Apache-2.0), pulling in abseil (Apache-2.0, no NOTICE file), already covered by onnxsim's own LICENSE.

Mirrors build-onnxoptimizer.yml: onnxsim vendors onnx-optimizer (which
vendors onnx) as git submodules and links onnx/protobuf statically, the
same shape already ported. cp310 is dropped for the same reason
(onnxoptimizer has no riscv64 onnx wheel there); cp312's abi3 wheel
serves 3.12+.
luhenry added a commit that referenced this pull request Sep 24, 2026
An include list whose entries share no key with the base matrix
collapses onto a single job instead of adding one per entry (confirmed
against onnxoptimizer's own CI run, which built only cp312 despite
listing cp311 too). Make python a real matrix dimension so include only
attaches onnxruntime to the matching combination.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-25 17:29 UTC

luhenry added a commit that referenced this pull request Sep 24, 2026
…m to ci-running (build jobs still in_progress on PR #2266)
CI confirmed the wheel itself builds and passes abi3audit on both
interpreters, but pytest aborts collection outright on test_python_api.py,
test_simple.py, test_timm.py, test_rfdetr.py and test_yolo.py: each does
a module-level import of torch, timm or onnxruntime with no
pytest.importorskip guard, so a missing module is a collection error
(exit code 2) rather than a skip. None of those packages have riscv64
wheels (onnxruntime only from cp312, which still lacks timm/rfdetr/
ultralytics/torch), so ignore the files themselves.
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 means to check.

Every other test file that builds a model by hand pins ir_version
explicitly; test_profiling.py's _foldable_model() was the one
holdout. Match the existing convention (ir_version=10) so the fixture
stays valid across the range of onnx versions the unpinned runtime
dependency can resolve to.

Adds the checkout/apply-patches step pair (mirroring
build-py-spy.yml) and patches/onnxsim/** to path triggers.
cp311 has no riscv64 onnxruntime wheel, so onnxsim's check_n equivalence
check runs through onnx's ReferenceEvaluator instead. For opset 9-13 that
dispatches BatchNormalization to BatchNormalization_9, whose inference
path is guarded by `if momentum is None` -- but OpRun fills the attribute
with its schema default 0.9, so it always takes the momentum branch and
blends the batch's own mean/var into the running statistics. The
unsimplified Conv+BN model is therefore evaluated wrongly, and the
correctly fused single Conv is reported as a mismatch (max diff 5.33 in
the riscv64 log).

Not riscv64-specific and not a precision issue: onnxsim 0.7.3's PyPI
x86_64 wheel with onnx 1.23.0 / numpy 2.4.6 and no onnxruntime fails the
same two tests every run (max diff 1.3-3.7). Against a float64 numpy
reference, the fused Conv is within 3.7e-6 while the reference
evaluator's Conv+BN is off by 16.3 and matches the momentum-blended
formula to 2.3e-6. With onnxruntime installed (cp312 here, and every leg
of upstream's CI) both tests pass. onnx main still has the same
BatchNormalization_9 code.
setup.py appends `.dev<N>` from `git rev-list --count v<ver>..HEAD`
whenever git is available, which it is in the cibuildwheel container, so
the previous run built onnxsim-0.7.3.dev0-*.whl. The publish job titles
the release from the wheel metadata and would have shipped
onnxsim-v0.7.3.dev0. Upstream's own tag builds set ONNXSIM_RELEASE for
exactly this; mirror that.
@luhenry
luhenry merged commit 0a2d958 into main Sep 25, 2026
13 checks passed
@luhenry
luhenry deleted the onnxsim branch September 25, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant