Simplify your ONNX model
Project description
ONNX Simplifier Prebuilt
onnxsim-prebuilt is a fork of onnxsim that aims to publish prebuilt wheels for Python 3.12 and later to PyPI.
Changes in this fork
- Changed package name to
onnxsim-prebuilt - Publish prebuilt wheels for all platforms (Windows, macOS x64/arm64, Linux x64/arm64) on PyPI
- onnx-simplifier depends on C++, CMake, and submodules, making the build environment setup relatively difficult and time-consuming
- For over a year, onnxsim has not been updated, and prebuilt wheels for Python 3.12/3.13 are not available (ref: onnxsim/issues/334, onnxsim/pull/359)
- Various issues arise, such as the need to install build-essentials and CMake in Docker images just for installation, and long build times
- By publishing prebuilt wheels on PyPI, we aim to enable easy installation even on PCs without a build environment
- Incorporated the CI improvements proposed in the pull request onnxsim/pull/359, and further enhanced it to build and publish prebuilt wheels for Linux aarch64
- onnx-simplifier depends on C++, CMake, and submodules, making the build environment setup relatively difficult and time-consuming
- Explicitly added Python 3.12 / 3.13 to supported versions
- Changed CI target Python versions to Python 3.10 and above
- This fork does not support Python 3.9 and below
Installation
You can install the library by running the following command:
pip install onnxsim-prebuilt
The documentation below is inherited from the original onnxsim without any modifications.
There is no guarantee that the content of this documentation applies to onnxsim-prebuilt.
ONNX Simplifier
ONNX is great, but sometimes too complicated.
Background
One day I wanted to export the following simple reshape operation to ONNX:
import torch
class JustReshape(torch.nn.Module):
def __init__(self):
super(JustReshape, self).__init__()
def forward(self, x):
return x.view((x.shape[0], x.shape[1], x.shape[3], x.shape[2]))
net = JustReshape()
model_name = 'just_reshape.onnx'
dummy_input = torch.randn(2, 3, 4, 5)
torch.onnx.export(net, dummy_input, model_name, input_names=['input'], output_names=['output'])
The input shape in this model is static, so what I expected is
However, I got the following complicated model instead:
Our solution
ONNX Simplifier is presented to simplify the ONNX model. It infers the whole computation graph and then replaces the redundant operators with their constant outputs (a.k.a. constant folding).
Web version
We have published ONNX Simplifier on convertmodel.com. It works out of the box and doesn't need any installation. Note that it runs in the browser locally and your model is completely safe.
Python version
pip3 install -U pip && pip3 install onnxsim
Then
onnxsim input_onnx_model output_onnx_model
For more advanced features, try the following command for help message
onnxsim -h
Demonstration
An overall comparison between a complicated model and its simplified version:
In-script workflow
If you would like to embed ONNX simplifier python package in another script, it is just that simple.
import onnx
from onnxsim import simplify
# load your predefined ONNX model
model = onnx.load(filename)
# convert model
model_simp, check = simplify(model)
assert check, "Simplified ONNX model could not be validated"
# use model_simp as a standard ONNX model object
You can see more details of the API in onnxsim/onnx_simplifier.py
Projects Using ONNX Simplifier
- MXNet
- MMDetection
- YOLOv5
- ncnn
- ...
Chat
We created a Chinese QQ group for ONNX!
ONNX QQ Group (Chinese): 1021964010, verification code: nndab. Welcome to join!
For English users, I'm active on the ONNX Slack. You can find and chat with me (daquexian) there.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onnxsim_prebuilt-0.4.36.post1.tar.gz.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1.tar.gz
- Upload date:
- Size: 21.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
119f5f70230e880cc1bf661afefa021c886411097b8bb63173ea14fdac1a516a
|
|
| MD5 |
5fbe2b9b1f4c6d78f5ba0c263b3046be
|
|
| BLAKE2b-256 |
224e10fb6041904ad11c7839b87619daf0c9922023c197a93c96b8ac94f53291
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da09ab17348721e23c7d8bff7a365be37c165ea87f2958a7ec3f3f68257a3fa
|
|
| MD5 |
0b0a299eaf3a7b599958768048b0314f
|
|
| BLAKE2b-256 |
9079d50035c8a25a36eb70bb6826449bdc139cdd46f6130f09221d463d875d34
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44e61dad354d73d0633c062f0489d7947ce2fb10706eaa7c33af3d54b4127e31
|
|
| MD5 |
1e927c05606cf6d61fd5c7b49145897b
|
|
| BLAKE2b-256 |
20d01572cf04bb8d35d12c158a4a9693361a8825408b4faa7d90d2fc3b5d8ac3
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1989256273297f92335b4929199ab81543b6bd8065f163b50f79fa213951cd6f
|
|
| MD5 |
6a25ff9e7114d7976110e4e1f135ac66
|
|
| BLAKE2b-256 |
6f1db780b6a16cd709ab52c0dfbd01bc5bd7f82225c0af15554fb6fde99f1c34
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp313-cp313-macosx_10_15_universal2.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp313-cp313-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.13, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b6aad14d6bbabd87ade5ac4f6729e48d62585731cdc181cb4ac9757af7c393b
|
|
| MD5 |
749ee2ada396c802c360ce44afef9eb0
|
|
| BLAKE2b-256 |
8ff69111bcd21138d3d4df60c3af75f9026ad39c1e7a1873b9bf146baae6cb0b
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7eb893b13fa53db4c5a80d1f205bd8cb2eec52732b2f45cb347f699605514db
|
|
| MD5 |
3737a6220592a9c58cdacb3fdc7bff85
|
|
| BLAKE2b-256 |
86de0625beab5e3cd64dde339304317177c8ed1558d141c4f9ecda82a7b50bc2
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffc8dd8b575f51d15ab7b9ffa662d66858b687cb4a2a48c51aa13f2031f715de
|
|
| MD5 |
5ffa36a098671ca9c17a5256d51abf68
|
|
| BLAKE2b-256 |
ce3f7eb5343a133f35c2629af8e89e25e277e7e4090530077355b5bac62a3e19
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db81c50e0df7f4c31be715bfd2637068bfca0512e0936153780b0cfd66209571
|
|
| MD5 |
87f1b0d7a8671416fc3660efda6d2234
|
|
| BLAKE2b-256 |
b556ce52a2d05489832a90089b063b4a440a646bb8bf6c3b5997c036eedab4d8
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp312-cp312-macosx_10_15_universal2.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp312-cp312-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.12, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13bebc54684a0646986a31fc58065d102978d90328dcaf190194e20e304273d9
|
|
| MD5 |
e8cc7d70f03697f1bf4eebffbc4326d1
|
|
| BLAKE2b-256 |
d7d56b15aee1b75a18984b3a6eb0a2cc395fe331e5be72ed55ac97f532d85e13
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3c6245867c60d68b7ae64259f76e11fb779fe0595955e54ca0a8d0799dab924
|
|
| MD5 |
82888c497bb337a108dd241e5b54e786
|
|
| BLAKE2b-256 |
4e5f11e97ae048e0f6d73b05782c9f9bd4eff810b18c38b07c85b2d35a03b9b7
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a6187c774b1d8ac2d0d4204e44cd00e5e87e2f0c6e4c44cc97061b23007eb67
|
|
| MD5 |
7ec3e7bc33c7702fb05180ca6dc58308
|
|
| BLAKE2b-256 |
f782be9d42c77ceab8c4406c4fc92bffc73a012b9c93a7bc24d5ca04a6bcbcdb
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89102a32aaaa445249c0416f44031640488df42ccaf223de7d5fadaaa6ba74a6
|
|
| MD5 |
1f99266cbda09e18a9fe5beec9119226
|
|
| BLAKE2b-256 |
d0a014c71c3b27f1f3c4e82721a68fe68d64883ad9eb0c42c13d477898bc3cbc
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp311-cp311-macosx_10_15_universal2.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp311-cp311-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.11, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64301d5fd81dba7d31965d54a5ac5e406433a247b9ab40ef3a22d0136cd41f65
|
|
| MD5 |
24f12bbbc9c7d1e472dbd9ad5fdcb7b3
|
|
| BLAKE2b-256 |
aa64207c995545dc9dc60043d456f16c3064470444ab110a717fafb8f51a7f34
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3728b33e94a405a0d94141019edb4eae1e641a9d56a44c825bd9f8f7061fe9
|
|
| MD5 |
5c1a0f15720d6bbfdc58e5e67c540351
|
|
| BLAKE2b-256 |
59df9a7d1cc9ff737d0a1e80c5f7eb59c16160aee3b0ee98e74a53c1408e5566
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baadcdfc400987c378adb6f8f81b01e3e8affe04fc6ea858241e60e58318ac02
|
|
| MD5 |
9fe73be519201e4da7993166f18478eb
|
|
| BLAKE2b-256 |
ce2d8f340977fd0502143a4bc5adf70ed55eafd8b591bf8c8ea514d531e02284
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a3a3559d2a41688847900677c4cecf7d7237de267fbe0e2f3d9f7bc185b1edf
|
|
| MD5 |
0a3fe6edb4850671f4dd8052f4e661f2
|
|
| BLAKE2b-256 |
097f86b6b1f8db35107e54d62f211974e156d9131b427955859d926f149fdd38
|
File details
Details for the file onnxsim_prebuilt-0.4.36.post1-cp310-cp310-macosx_10_15_universal2.whl.
File metadata
- Download URL: onnxsim_prebuilt-0.4.36.post1-cp310-cp310-macosx_10_15_universal2.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.10, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f4cc9cc7b6cf35b06b40e833a9906f10bdbc3c0fe94ee727480a71870ee0c0
|
|
| MD5 |
8a1d07b270f2c65d411de054738a87ca
|
|
| BLAKE2b-256 |
92822b4c19e0b616dc7875c3a08875ebbcaebd0eb810a5c3e49637035c54c168
|