https://github.com/onnx/optimizer
ONNX Optimizer
https://github.com/onnx/optimizer
onnx optimizations
Last synced: 3 months ago
JSON representation
ONNX Optimizer
- Host: GitHub
- URL: https://github.com/onnx/optimizer
- Owner: onnx
- License: apache-2.0
- Created: 2020-07-20T21:03:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-05-01T14:59:28.000Z (11 months ago)
- Last Synced: 2025-05-05T05:03:11.664Z (11 months ago)
- Topics: onnx, optimizations
- Language: C++
- Homepage:
- Size: 8.8 MB
- Stars: 700
- Watchers: 31
- Forks: 94
- Open Issues: 62
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ONNX Optimizer
[](https://pypi.python.org/pypi/onnxoptimizer/)
[](https://pypi.python.org/pypi/onnxoptimizer/)
[](https://github.com/onnx/optimizer/pulls)
## Introduction
ONNX provides a C++ library for performing arbitrary optimizations on ONNX models, as well as a growing list of prepackaged optimization passes.
The primary motivation is to share work between the many ONNX backend implementations. Not all possible optimizations can be directly implemented on ONNX graphs - some will need additional backend-specific information - but many can, and our aim is to provide all such passes along with ONNX so that they can be re-used with a single function call.
You may be interested in invoking the provided passes, or in implementing new ones (or both).
## Installation
You can install onnxoptimizer from PyPI:
```bash
pip3 install onnxoptimizer
```
Note that you may need to upgrade your pip first if you have trouble:
```bash
pip3 install -U pip
```
If you want to build from source:
```bash
git clone --recursive https://github.com/onnx/optimizer onnxoptimizer
cd onnxoptimizer
pip3 install -e .
```
Note that you need to install protobuf before building from source.
## Command-line API
Now you can use command-line api in terminal instead of python script.
```
python -m onnxoptimizer input_model.onnx output_model.onnx
```
Arguments list is following:
```
# python3 -m onnxoptimizer -h
usage: python -m onnxoptimizer input_model.onnx output_model.onnx
onnxoptimizer command-line api
optional arguments:
-h, --help show this help message and exit
--print_all_passes print all available passes
--print_fuse_elimination_passes
print all fuse and elimination passes
-p [PASSES ...], --passes [PASSES ...]
list of optimization passes name, if no set, fuse_and_elimination_passes will be used
--fixed_point fixed point
```
## Roadmap
* More built-in pass
* Separate graph rewriting and constant folding (or a pure graph rewriting mode, see [issue #9](https://github.com/onnx/optimizer/issues/9) for the details)
## Relevant tools
* [onnx-simplifier](https://github.com/daquexian/onnx-simplifier): A handy and popular tool based on onnxoptimizer
## Code of Conduct
[ONNX Open Source Code of Conduct](https://onnx.ai/codeofconduct.html)