Skip to main content

Simplify your ONNX model

Project description

ONNX Simplifier Prebuilt

PyPI version PyPI pyversions PyPI license Build and Test

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
    • The library name remains unchanged from onnxsim, so you can import it as import onnxsim just like the original onnxsim
    • Can be used as a drop-in replacement for the original onnxsim
  • 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
  • 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

PyPI version PyPI pyversions PyPI license PRs Welcome

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

simple_reshape

However, I got the following complicated model instead:

complicated_reshape

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:

Comparison between old model and new model

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnxsim_prebuilt-0.4.39.post2.tar.gz (12.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

onnxsim_prebuilt-0.4.39.post2-cp312-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

onnxsim_prebuilt-0.4.39.post2-cp312-abi3-macosx_10_15_universal2.whl (3.7 MB view details)

Uploaded CPython 3.12+macOS 10.15+ universal2 (ARM64, x86-64)

onnxsim_prebuilt-0.4.39.post2-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

onnxsim_prebuilt-0.4.39.post2-cp311-cp311-macosx_10_15_universal2.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 10.15+ universal2 (ARM64, x86-64)

onnxsim_prebuilt-0.4.39.post2-cp310-cp310-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

onnxsim_prebuilt-0.4.39.post2-cp310-cp310-macosx_10_15_universal2.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file onnxsim_prebuilt-0.4.39.post2.tar.gz.

File metadata

  • Download URL: onnxsim_prebuilt-0.4.39.post2.tar.gz
  • Upload date:
  • Size: 12.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2.tar.gz
Algorithm Hash digest
SHA256 731420cd8830d2ebde341c41abac1b718718891db4934f2655d7ec4df0b100fd
MD5 3263fbf3108f425befb9eb815dcec73b
BLAKE2b-256 89399d05c88e05b4495d870b96244808bcec89bddf0d6de7fb37a1dfaec32a83

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ddfa75679246e51b1cc55e37d02b473c653c906b2987f817c220adf2c90f1cf2
MD5 befe6eea6c1b654d9536813dce4ac450
BLAKE2b-256 fe8c5e69d067256f7e27b6905e8a16938097a98d563f8dc9f0c7171fd4a9da29

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5f129c78b379f040caafc40360db1db91617179c0663049e712c7dde4a0d6c28
MD5 130bbf0c3a48b79012717157d08ed668
BLAKE2b-256 643a677d73f0fd8a0a9baa58e470e4d70f6ff3cffce432c2b3e35802c56ae175

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 59b671d008fb5f8c51cd20c3c06475e64dd6267659f61912cf1579bee25d9405
MD5 05795e75e12e10121d159a2ce966c084
BLAKE2b-256 a0ad88c7ef2d16e6c78577363abf0656f207a6130da5a8b00d3a9bd67313dfc7

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp312-abi3-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 b454921fb8f6f4f48ef26e49fa629074d3a0428c0f1e4f746215a7d7f0b72944
MD5 6546762c3325c649ad437f33eb5bdda3
BLAKE2b-256 7c540197a7ab94785031517513f326e804558baba41537d37dc77fe0c359fada

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ad2ea55e44901bacac5a592bcd1a6fa8b34540e7047b59d906b3689bbc939d26
MD5 2e8ba381f57e51faf83a63e3d3c3f6b9
BLAKE2b-256 21ae175559f7d1fe7d68ff587e160cd694553c75fa7c766ec591f13eb43b063b

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf2f4688ac48072a4706873609ceec00f65ac397c45460837f827a04b73d872e
MD5 d7a2cafe07e284967ee0033f37d9c3fd
BLAKE2b-256 e8f0f2b4b5d14823a73bcc3a07178ecdec47a2c021a96f85fd75cf85b7d7275b

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f883fd21d2ab0f3f6253366a3963911011ab80f4748b1a83949170cf2f120ad8
MD5 dfa0f070598e377151acbb208f1d8586
BLAKE2b-256 ce54867845c3fee32a5fd1f0e0def8296a648789e0ca3ba370afa39db4adb689

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 78ccc734fbb6c037a89e9d8a9e0b4abcda000854e6d2bad64cf497a3ce92bdc1
MD5 55f82c21d117675256aa77cebad18ce7
BLAKE2b-256 19e8088b2920990cd37840c8624ff02efa18318c61e77500071ae17860e31ef1

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 85670a8885e34c56920ae4f4f16afe3d3ed9019d5d92981b0f1af7318374f3dc
MD5 d7d4b2e05ee8098e16e0b54be28126c6
BLAKE2b-256 7de7fc82d055f245b352e77f7bccf67a84be28afb1ecf7ed15cd48a33f6d0315

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 39ff782c82c8fe3ebf0fc9a6fa8f29da6787325f09325327b5c9e6c86720562e
MD5 157a9eb806d6ed150c7ef59e362b27de
BLAKE2b-256 bad059bed073ec37f252da8d72055dfaca49d999edc3150cd3401c081dee6d64

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 05143aa0609822d5c1a7ab00077e6c76b74ce8483934185a050fe4530325de0c
MD5 03c7cc675fa8f21a437ca37abf3b7118
BLAKE2b-256 2fded473eb52675a20a4c05938a7e5c9a8f6819da5e9a7f1f34349b85c90796e

See more details on using hashes here.

File details

Details for the file onnxsim_prebuilt-0.4.39.post2-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post2-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 c1e061dc142cc1eb5b483c37e85267bfde065f32fdc4f6c3e2bad5d4e0209661
MD5 8203e78c3910824a511bf68137615ec4
BLAKE2b-256 884841df16eb40188fdfda61cc0b917352ea3a412f21fe81a8d44d4b521ca224

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page