Skip to main content

Common subexpression elimination for ONNX graphs

Project description

onnx-cse

CI

onnx-cse is a tiny library for common subexpression elimination (CSE) from ONNX models.

Example usage

The onnx_cse package provides a single function:

from onnx_cse import eliminate_common_subexpressions
import onnx

model = onnx.load_model("model.onnx")
# Update model in-place
eliminate_common_subexpressions(model)

Comparisons

It is written in pure Python with minimal dependencies and focuses on being safe, fast, and simple. It differs from similar tools such as onnxoptimizer, onnx-simplifier, and onnxruntimes own CSE-pass in the following ways:

Simplicity

onnx-cse does one thing (CSE) but does it well. The entire library is less then a couple of hundred lines of code and easy to understand for anybody interested.

Performance

From personal experience onnx-cse handily outperforms onnxruntime's CSE pass on very large graphs with small weights (~10k nodes with nested subgraphs) while onnxoptimizer fails to finish its operation on such graphs at all.

Optimization across subgraph boundaries

onnx-cse eliminates subexpressions in subgraphs if they can be replaced with expressions found in the enclosing scope.

Installation

pypi

pip install onnx-cse

conda-forge

Using pixi:

pixi add onnx-cse

or using conda:

conda install onnx-cse

Development

You can install the package in development mode using:

git clone https://github.com/cbourjau/onnx-cse
cd onnx-cse
pixi run pre-commit-install
pixi run postinstall
pixi run test

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

onnx_cse-0.2.0.tar.gz (87.2 kB view details)

Uploaded Source

Built Distribution

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

onnx_cse-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file onnx_cse-0.2.0.tar.gz.

File metadata

  • Download URL: onnx_cse-0.2.0.tar.gz
  • Upload date:
  • Size: 87.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for onnx_cse-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ebaa92db3eead5f99fdca36e58eeb572976a8cab882bad30f0da7c3448c99a9b
MD5 10b49b0e3e8d33de2abf43f3d0a1fa4a
BLAKE2b-256 79ae4585ea80345d17f15862bb12725e5e84539f07cc49db98347d5b5707a260

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnx_cse-0.2.0.tar.gz:

Publisher: package.yml on cbourjau/onnx-cse

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

File details

Details for the file onnx_cse-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: onnx_cse-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for onnx_cse-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2eaa5be9731928d45b4f7e931a1095d1571ce37e1660f51a999dda42ba30759
MD5 1ab798b443e1479dc5600a0346cfa13c
BLAKE2b-256 0092bbb4f1b91a233a46ec6df0877649d208da9744d49c4a6d75aa047cc970e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for onnx_cse-0.2.0-py3-none-any.whl:

Publisher: package.yml on cbourjau/onnx-cse

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