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.5.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.5-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12+Windows x86-64

onnxsim-0.6.5-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.5-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.5-cp312-abi3-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

onnxsim-0.6.5-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.5-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.5-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

onnxsim-0.6.5-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.5-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.5-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.5.tar.gz.

File metadata

  • Download URL: onnxsim-0.6.5.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.5.tar.gz
Algorithm Hash digest
SHA256 ae63902477793c3d160fc8dcc796cfd041c38e72f1fb74358a0cbd85bc3e777f
MD5 2999f994fe3773a24fba041b522d861d
BLAKE2b-256 c1ac8b1635f72adafc2be084bae43dc7a5043424eced4587a341430d7213dd32

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5.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.5-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 30025eaed4c5262fb0f2e2faec911c4693029e89104b7595fb207bf6f6c9471d
MD5 81cdd704f59dbb9daa0ac63ad9c7183d
BLAKE2b-256 5b60cb6923cded2b7933a8ae171bbc377f87dc1203464c0fd9f006ffe61857ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-cp314-cp314t-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.5-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.5-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.5-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 34305a8ea447b91c3b3b74d6eb5451fa7fef3ad2708f934c3eabac91e329dd12
MD5 5c2e4252e76dd31c276bee6e3836e3ac
BLAKE2b-256 4a86714847c834ee49f5e689034eea65ef8c789b3b9078c655e8d1e7f53d1559

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bc7c2717c0bc0ffa21e501c675af520f344e70f2bfda835e8fefa127ffd6ac92
MD5 5fcd443df95f510f2cd794f30998eabf
BLAKE2b-256 01826ea262bb9500a30b54181946ec0ce093530895afacb66ac6b86688713dff

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2a4abf6bde92ad23bca70d05e4a3f5eb13144bdc126ef6b24849e2ed24647c10
MD5 7d5b3957d7b3cb101865840a8b5ddb86
BLAKE2b-256 3b4ec3647021735e7473e557d26c6740297da097790ea5d7e0bc92e6422c93a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4047cbb6902c48104abd16b41fd982a6f6254cbc8f390c7d2740b1b61aaed8dc
MD5 7e6e3dc7fb03dcb8527cc94f435295ca
BLAKE2b-256 052a658fd32b774643196c29793cf92cdf56590597d845a96fcd215506565c4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 706341c5953f4fa1ffe6220512caa3c924bc43bca5a7f772e6b707a2fba9e496
MD5 51f089b08b521a3bd4f28431c9f54a83
BLAKE2b-256 873c2d63f678b86a915009abbf866e2145f101ce027f49ea7fca47a720e4494f

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4fbfd08d09c9be8b5066358b3705a7dc8df68904ba4a629a77bb20beb6d09bcc
MD5 5634d06c4d21865475cab9351d54701d
BLAKE2b-256 e1e53fe3becdaabeaaf38525c79cb2170a5a356a4555c4c7e4f621608262b2a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9d8181d3cf63b6abc731e54c894bd14d305aaec93cfca1b3600ecd4c4e907c2e
MD5 8f0cb2e9c97eec3b29cdeb633cee664a
BLAKE2b-256 602a88e9c4cfc1f831bc6ec0771d02f5f71a2da00ca2dd13858ea98660f3d185

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 679d55a4d20c7cc8228e7fb7acc65e57a47b684be05eca92c67c5f65a8876e1e
MD5 cc1bf5c2bc5dcef04e41568346f767b0
BLAKE2b-256 1531af1e83c35f6ba77ee5ea6c2805973c966daf3d7ba7080ef53fe3a75a4818

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.5-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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fc2841c850d034c9ddc429799c4c3fec251e21fe90af35f347a0370358f988e1
MD5 1ebde14f6c3b0d6821d2b4986e28c912
BLAKE2b-256 cd7f2de12ba3f360bae769393994f86db6d6b7efbb06c195ed6109407d962cda

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00de35a56def1f476944c08c9b3c249bc136bdd70c6470f34e6d9e6ea7c60562
MD5 f962abb0972f64fa85e3c493d7cac2e7
BLAKE2b-256 0054a548e46294276d934f8d13aa91caccce343ddec2beabb9d2a0686a519f96

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b7324ab1aa023fbd54039dc40b8504237fc74cb10127eedaeb1a3080c8b24ab0
MD5 0d79f0493ad0303b7e1174d8a80e25ab
BLAKE2b-256 323e60eeb82e7ff51269b3404027d34e539c4d725d34082abbf5fbdad3665a81

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for onnxsim-0.6.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4ebb410b5569fd543749cc08b02fba89e4f613c5b0a489414e716fbff500f38
MD5 6640477c82adea4f50fde9f51f4970e6
BLAKE2b-256 5d1f53a8b70717c0c2b2f46f4873a89b382e46dc293a1fe85e9c090d8e645df2

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.5-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