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.4.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.4-cp312-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

onnxsim-0.6.4-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.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: onnxsim-0.6.4.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.4.tar.gz
Algorithm Hash digest
SHA256 0daa26aa494e6557d3d27ecdfb75236c6543fac0d32cfc38f8b536e35226834a
MD5 fbb34ed5547a52c073001a86d73b3246
BLAKE2b-256 1412a9408d345b170e2d51c240a1e739669582d946b47006427643b15c18f6c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnxsim-0.6.4.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.4-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: onnxsim-0.6.4-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.4-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b666ebf90ba6d367adb44caf6401c2be650e0a8936c4e4cf1b184eda2ba05ee0
MD5 cffc5835b3523a86eb2355aa6bf14c5e
BLAKE2b-256 54ff026e17f208367c2499923ad7bc433aab586e8577359c040a7362f8e35b2c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9363caa2cc75513138c9af5aec41ea53368b9a37a041b04810d4084401b25094
MD5 569c192132ade2c1ed3a1b25f87ad0c9
BLAKE2b-256 b2a0af3721b3f6f85a22f6a72d26464cf290c1260baddcbe88b2d1a030518822

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cb0096ca3cc5a40c96aa98f05a67ebb0a812cc6e582967651a122b632637bc56
MD5 227e20ba0a3adc776847595373de6cae
BLAKE2b-256 d46ce353b307046fd4b0f03eee5f5b26f856a0c1ffc8128904bd267bd8eea0a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c26e3076a16f55bd229b77d84ac6ff3a84f8054e3311994c6812ada4167a673f
MD5 dd01dafc9f496d5308895b4e2f833d3d
BLAKE2b-256 6de6eb68fa11b91c30a120db695f43b6a9d8ecddd9aae044dd6f68ad4e391fe1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: onnxsim-0.6.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b4c34c0aac0c9cb7f802f6e594bb7892a0cd8164e85b05cfe29ad99af9fb5ee7
MD5 6e8fe85ab0ca6b00553f27d1e8be3092
BLAKE2b-256 4ca7098e8ac1133066e8c2b4c8d91b24629749c4f28dd8629ee34444428771c8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9b21f8b232485b34d079fabfb023aff300259dd7ad63f0119bc3b85e646494bb
MD5 894bce117f4da613d4e9f0fb4f138717
BLAKE2b-256 4158cb280af2a309766a6527dd843567b2862e0b10128386e89cee6aca6286a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8ed8ad0e47fa672c02a053ea665d56cff59070f364924197f2d674bf7b4ae73e
MD5 a198d195f515f4b052ec327bd9b4ae4d
BLAKE2b-256 c7895bf13741d11c34cc59f9f618574d4e2dfb7263c9b1e972a5f45a4086bc0a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7cf5d45837ae42c78754c54b5217d7e67339f3a0d503d6233c5ccd385a5e927a
MD5 0ca11f82dcdac50dbaae1c7be5258339
BLAKE2b-256 e30eeaf4cb934c21cd23b5d7f469a766c32407891a31e2b0d87895288a64f217

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: onnxsim-0.6.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f1702aac6cdb2fc1e237dddd9103b3966d9441f65dde433cccd5fa04d662a435
MD5 e2ea79144e669cb2c26fdf57f186e39f
BLAKE2b-256 79669307b1929df6ceac1824c4d42691d5f146ae368a1150619685442e0c5d8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f1f643f0acf48db130a902b22ebb082e78741647fdf4596e134037f55d30f66b
MD5 87ae8357c63051b0274f1654fc505906
BLAKE2b-256 e2b70dc1b28dd2345398205ce257a341b0ebde5c91a587c4253d418a46928bf7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fccdb33aaba25180c3ca64cd389865ac499147bd57da7b556b735f1f9d036ce1
MD5 689be87e129a33f9414065749b7c15ee
BLAKE2b-256 aba271096f4aaea88fb6b941c924bc3f42a143e3d377a61e9a01e4181a2b2099

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for onnxsim-0.6.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1043161c03e40ebaacf10315d6296d5a40fadda9c84c6bf5e605fe0f61166e3b
MD5 0bf9fc2fe72432dd34ca950116f4fa3d
BLAKE2b-256 27a66a5f8e23617512dbedc630845ad9d8fbde4b561e0a1bf6ee3d9af7948c94

See more details on using hashes here.

Provenance

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