Skip to content

Simple, safe, and fast common subexpression elimination in ONNX models

License

Notifications You must be signed in to change notification settings

cbourjau/onnx-cse

Repository files navigation

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

About

Simple, safe, and fast common subexpression elimination in ONNX models

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published