ONNX Optimizer: Streamlining Model Optimization
Introduction
The ONNX Optimizer is a C++ library designed to enhance the performance of models created in the ONNX format. It provides a robust framework for implementing various optimization techniques, offering a wide array of pre-built optimization processes known as passes. The main goal of the ONNX Optimizer is to facilitate model optimization across different ONNX-backed systems by maximizing reusability and efficiency. While some optimizations might require detailed backend information, many can be executed directly using the provided tools, making it simpler for developers to enhance their models with just a single function call.
Installation
Installing the ONNX Optimizer is straightforward. It is available via the Python Package Index (PyPI), making it easy for users to integrate into their projects. The command to install it is:
pip3 install onnxoptimizer
If users face any installation issues, they might need to update pip
with:
pip3 install -U pip
For those who prefer to build the library from the source, they can clone the repository and install it using the following commands:
git clone --recursive https://github.com/onnx/optimizer onnxoptimizer
cd onnxoptimizer
pip3 install -e .
It's important to note that building from source requires the installation of the protobuf
library.
Command-line API
The ONNX Optimizer provides a command-line interface (CLI) that allows users to optimize models without writing a full Python script. The basic usage of the CLI is:
python -m onnxoptimizer input_model.onnx output_model.onnx
The tool comes with various optional arguments to customize the optimization process:
--print_all_passes
: Displays all available optimization passes.--print_fuse_elimination_passes
: Displays all fusion and elimination optimization passes.-p [PASSES ...], --passes [PASSES ...]
: Specifies a list of optimization passes. If not set, the default fuse and elimination passes will be used.--fixed_point
: Enables fixed-point computation.
These options give the user control over how models are optimized, providing the flexibility needed for different use cases.
Roadmap
The ONNX Optimizer team is committed to continual improvement and expansion of its capabilities. Future developments include:
- Adding more built-in optimization passes.
- Enhancing separation between graph rewriting and constant folding, or potentially introducing a pure graph rewriting mode (as discussed in issue #9).
Relevant Tools
To support model simplification and use, the ONNX Optimizer works alongside several other tools:
- onnx-simplifier: This is a widely-used tool based on the ONNX Optimizer, offering an easy way to simplify complex ONNX models.
- convertmodel.com: A web service that utilizes the ONNX Optimizer compiled as WebAssembly, allowing users to optimize models directly from their browsers.
Code of Conduct
The ONNX project adheres to the ONNX Open Source Code of Conduct, ensuring a welcoming and respectful environment for all contributors and users.
The ONNX Optimizer stands as a formidable tool in the domain of model optimization, empowering developers to fine-tune their ONNX models efficiently and effectively.