ONNX Simplifier Prebuilt

raw JSON →
0.4.39.post2 verified Fri May 01 auth: no python

Prebuilt wheels of onnxsim (ONNX Simplifier) distributed as a standalone pip package for platforms that lack a compatible compiler. Current version is 0.4.39.post2, with irregular releases tied to upstream onnxsim updates.

pip install onnxsim-prebuilt
error ModuleNotFoundError: No module named 'onnxsim'
cause Forgot to install the package, or installed 'onnxsim-prebuilt' but attempted to import something else.
fix
Run 'pip install onnxsim-prebuilt' to get the prebuilt wheels.
error AttributeError: module 'onnxsim' has no attribute 'simplify'
cause Very old version of onnxsim or onnxsim-prebuilt that does not have the simplify function.
fix
Upgrade to the latest version: 'pip install --upgrade onnxsim-prebuilt'.
gotcha Do NOT import from 'onnxsim_prebuilt'. The import module is 'onnxsim', matching the upstream package. The 'onnxsim-prebuilt' name only applies to the pip package.
fix Use 'from onnxsim import simplify' instead of 'from onnxsim_prebuilt import simplify'.
gotcha The 'simplify' function may produce a model that does not preserve output exactness for all ops. Always check the returned boolean flag.
fix After calling simplify, verify that the returned 'check' is True before using the simplified model.
deprecated The function 'check_out' (if used) is deprecated in favor of the built-in check in simplify.
fix Use the return value of simplify instead of calling check_out separately.

Basic usage: load a model, simplify, save.

import onnx
from onnxsim import simplify

# Load your ONNX model
model = onnx.load('model.onnx')
# Simplify the model
model_simp, check = simplify(model)
if check:
    onnx.save(model_simp, 'model_simplified.onnx')
    print('Simplified model saved.')
else:
    print('Simplification failed to preserve outputs.')