Skip to main content

Simplify your ONNX model

Project description

ONNX Simplifier

PyPI version PyPI pyversions PyPI license PRs Welcome Discord

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 GitHub pages. 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-0.6.3.tar.gz (2.7 MB view details)

Uploaded Source

Built Distributions

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

onnxsim-0.6.3-cp312-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

onnxsim-0.6.3-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

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

onnxsim-0.6.3-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

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

onnxsim-0.6.3-cp312-abi3-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

onnxsim-0.6.3-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

onnxsim-0.6.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

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

onnxsim-0.6.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

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

onnxsim-0.6.3-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

onnxsim-0.6.3-cp310-cp310-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

onnxsim-0.6.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

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

onnxsim-0.6.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (2.6 MB view details)

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

onnxsim-0.6.3-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file onnxsim-0.6.3.tar.gz.

File metadata

  • Download URL: onnxsim-0.6.3.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onnxsim-0.6.3.tar.gz
Algorithm Hash digest
SHA256 5ea844096208ba0a19d59ecee9b88e37c0059222ec2d30d35f400a2cdc5e5c58
MD5 29cd212591e54c337cff6722234d5334
BLAKE2b-256 cae218dc34b79893dfa40fab6386b9024cfafb7050d87441b7af99dec414b65c

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3.tar.gz:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.3-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onnxsim-0.6.3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8e5334d2946dca52564cf05df6628830c7a1b1a24ef91adca61d06b123b61f58
MD5 cb06398981e5df9088f435005b785c44
BLAKE2b-256 e4125cb26d101e20897bb270f3ea0e4eba1d6f8b78787f199bc6caf3d13928c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp312-abi3-win_amd64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b5f78597af8e7f845ab326739809dab1a1e9196016b861f0bb12bd4521a85cf
MD5 f41760ef2e5926dbfb6631fe3d7c994d
BLAKE2b-256 6b689bbb830e240557f6f5bbd2da2e9df3abbf3bf850e088814bd90194ee8efe

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2308fc339a1767611dbd7336c3b84a4d91ff7b5172cadbd082ac3170717cac0f
MD5 d15920951528e18d09772c6f9e5400b5
BLAKE2b-256 b59a27e3441185153715b05e3ba9ba758f95d583e96b3e5b912448929a4b8d4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 272982fc45af9527528208bff5fb7ea4f9eefd9543e63e9b4ed12c2886639c15
MD5 d9626160b2a8118449aad8433a000472
BLAKE2b-256 ecb68aaa5a08fc552c85c7def463c34f77c955a7cb77d1fc09fd0cb28ef498f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onnxsim-0.6.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d626a2977d2ff6d394eb79e7626d35a71166ebd66bf30d1f7f8fce92c5504b8a
MD5 2b02301454063a3e93ccf76666d01191
BLAKE2b-256 baa568afb3b3b2f2afc1d9795a08951a81592ec5fc218ce7854da1739c954f6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp311-cp311-win_amd64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a990beccd50af79d075aaf46ddb38780dfbfe1b809d3bf0c27cc2378eeeb397
MD5 ac4b50d505808a17af0ed3d28f62f835
BLAKE2b-256 01110bee3644a9d0130ceecf2b1d227766e2216da12bcc070645c5e62740404a

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 95071fa6031dba9d67334d3757c0cfeb512238dd2f188fc05a7b41c2104cfb84
MD5 0d212d17c60faeb0f463ecfc9379d7cc
BLAKE2b-256 ff8fb6a8b80b24b40195854c3d505072a1a2b9702673995c594857200a2cda9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4db8f10c4cb85d69618cf68d354670b307016046bc685c787124c2690e25e521
MD5 521df448dd6da901003eb8ef81a2d2ef
BLAKE2b-256 462c6893f3bc2ee925db9b692c3c21776ddf85c5e76289cc8c3856625624e5e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onnxsim-0.6.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 60299269e426d5142dac51fec38463f4ec7b9db3a16ad0522e230b3f1ca14a49
MD5 5e30955a7bbd47967e8f8d5954ef0c61
BLAKE2b-256 1ac504a4267f9cdf3545d8e07c01bdee5eb8b7e321d2bd8f3a399211652d9fc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp310-cp310-win_amd64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1020ca5315fbc46ef2e421c711d7da9a4888a8eb9ec2b01354f0c51884fe1289
MD5 852fad7437afee9789cba665374762ff
BLAKE2b-256 2e51c9fdf1de85bff91d77b61ebde637934c2253432f3d4e085e3573ceab2a5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bf5e7bb9ee1fc4c52860cc6a09da89da24961d08a9c2df2f754cede139b1f8fc
MD5 61ea6f90a8f2332a87e6331bc60fe067
BLAKE2b-256 05cb4f121c0a76fce13adaa9dae70bce34e58e8c4d9ca942c94028b7a7cd7951

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file onnxsim-0.6.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dec25e910e491fb5aa67ddc47cc714d9a245ea2f1c34e5bc2df6d2f03a934c23
MD5 61701fddc7995fb69ede79c9a8d0e3fa
BLAKE2b-256 a0408df422f9f4c8ad692fe268eaa3434683b711a90dbaf21a630cf6a77ce604

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.3-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-and-test.yml on onnxsim/onnxsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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