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

Uploaded CPython 3.12+Windows x86-64

onnxsim_prebuilt-0.4.39.post1-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.post1-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.post1-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.post1-cp311-cp311-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

onnxsim_prebuilt-0.4.39.post1-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.post1-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.post1-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.post1-cp310-cp310-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

onnxsim_prebuilt-0.4.39.post1-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.post1-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.post1-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.post1.tar.gz.

File metadata

  • Download URL: onnxsim_prebuilt-0.4.39.post1.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.post1.tar.gz
Algorithm Hash digest
SHA256 8c17d35b62f1c686973db0a2a81eef64f60d5f4c94e6341f0827b8a66448e290
MD5 25a9c9e7f211aa4c15e395a024387712
BLAKE2b-256 984dbb3f5951bd763ce52747011e6bff827b0eff473a7e2403ac14941d8fca13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 43c3810cc3bd9e4469577aa04ddb924a0bbd30377bf7fb91b119e994601f1883
MD5 fe8ed8d196c726313a0050f18cc6b263
BLAKE2b-256 a0b6ae1c455f36bfdbe2b1a0f5c1c0573f8d31c0e291c1a3c95c3e7b790c073b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c40bc193cadde412a0f33de41ed51ea9402a75ee30a4eacd5af2bf2b14219a6
MD5 86d019138b3eeeed87d2bc62ec7dab02
BLAKE2b-256 20cff989e0c70c5be4cc1a8656ac2cde1cf0db477e423448841792bd75f9822a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3b22736954d652bf13a53f3d61a585ffe8ba9002331f60c48ae4aab05346d485
MD5 d180583a5d09e8b50432c63d0f66243f
BLAKE2b-256 00932f65e40e60369bf83cb0ba0bef5e0e73a6ca5ac59e95fad95331e9141d77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 d26571f8e6fc75bac25fcc34db9a6caef0fe0d692da7ab3ef7d0a54604975291
MD5 a255d966252e7be68c41b32891bd0340
BLAKE2b-256 c523d44268e61131e72d9c3489ada6b2c000a8e8913ff367fc84b13b65bd9b94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2677f6cb8002610ac77d5d432eaf9ab67f0f81063afd358953276c4dd9fc848e
MD5 6ca0ac17585bb1c63df24d0253cb8da9
BLAKE2b-256 bbff7f92bb2918e3564f1005c4554f4d97430634c30f744bc436c3b096575cb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0f9ca60c560c9a48881c5cf2ff62dac4b1e649498f2af5b90fa47d404996636a
MD5 4abe3dd8e63230a4f09d9595139be5ad
BLAKE2b-256 a3f703378885aba0bf752a05e2b47419dba77ec61578fabcfef6adeac23393ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a705c4cf64c8386dd919a80ee1fcc4d35dd9dc91657c1e5fe17072bb909efb5f
MD5 714453d7e7e02987916451293a0c6bde
BLAKE2b-256 2a22be38465f86665fd602b25ae3c79dd8e83c2bf1263a5f585bfffa5a0ea92d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 eb6275f97546ba7d75670a2f1d2cfa6fb6086d7b2f53aa466b266d345f825157
MD5 59c8c4f671abe2feb8a7ab3e64612657
BLAKE2b-256 f0abf178ee572c298504f13d9040746d018784a0eeebb5c61b61f58b773a7d38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c2258f4385c122887556aa408c3b7c753a3e6f1ece31168cd9846fdb6e448edc
MD5 3738d4072be610c39539bce2ae72ba3e
BLAKE2b-256 d6294d9be1be648549a3f0fc4369701830b7bf87324c8588bc15bd183e3a8114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7da990706ca1428622a30adafbc956c667e5ded062be5b390937736747c7354c
MD5 bc1ddf590d5b79653c8fb1206bf54294
BLAKE2b-256 845c246793064e558d6056ec12094299347c0617d2827fa3d8aec7ab7c1ea979

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f44ea88461b89baa191acd0c93222ef6ab9193a90426ad17a20c0f94e6af6944
MD5 01f311400b1bade99bdded20bd7719ba
BLAKE2b-256 07302d5389d4e35388abda8cddf7227fb828532b9ba6e84c19d0aa51ee1e2cce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for onnxsim_prebuilt-0.4.39.post1-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 3079a1b7c1e7ee0a362ef902bc71faa2161827a65ddc0d5f73864a144ba59856
MD5 52dfcd77a22b30ae9466774b91650785
BLAKE2b-256 f95b591fd896499aebea01d9af7c383e7d536c2ab2658b8a4925efb70fd942a7

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