skillfed

onnxoptimizer

ONNX Optimizer

onnxoptimizer v0.4.2 413.1K downloads/30d#6,843 on PyPI826
Permissive license Apache-2.0 Active released

What it is and what it does

ONNX Optimizer is a C++ library with Python bindings that applies graph-level transformations to ONNX neural network models. It provides a set of prepackaged optimization passes—such as operator fusion and constant elimination—designed to be reusable across different ONNX backend implementations. The library aims to reduce duplication of optimization work by centralizing common transformations that can be expressed at the graph level without backend-specific knowledge.

You use it by loading an ONNX model, calling the optimizer with your chosen passes (or letting it apply the default fuse-and-elimination set), and saving the result. It also exposes a command-line interface for batch optimization. The package depends only on onnx and targets modern Python versions, with prebuilt wheels for common platforms.

Use it for:

  • Reduce model size and inference latency by fusing adjacent operators into single kernels before deployment.
  • Apply constant folding to precompute static subgraphs and eliminate redundant computations at runtime.
  • Standardize model optimization across multiple ONNX backend implementations without reimplementing passes.
  • Batch-optimize a collection of ONNX models via command-line without writing Python scripts.
  • Prepare models for edge deployment by applying graph-level optimizations before quantization or pruning.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Applies graph-level optimizations to ONNX models, including a library of prepackaged passes for common transformations like operator fusion and constant elimination.

Yes, if you work with ONNX models and want to reduce inference cost. The package is actively maintained, has no known vulnerabilities, uses a permissive license, and offers both a Python API and command-line interface. Install friction is moderate due to compiled wheels, but prebuilt binaries for current Python versions mitigate that. Suitable for model optimization pipelines in production or research.

Install

onnxoptimizer on PyPI

pip

pip install onnxoptimizer

uv

uv add onnxoptimizer

poetry

poetry add onnxoptimizer

Installing onnxoptimizer

Before you install

Medium install friction due to compiled wheels; prebuilt binaries available for current Python versions on macOS, Linux, and Windows. Actively maintained with recent releases and no known vulnerabilities.

License in practice

Licensed under Apache-2.0 (permissive), allowing commercial use, modification, and redistribution with minimal restrictions.

Quickstart

pip install onnxoptimizer

import onnx
import onnxoptimizer

model = onnx.load('model.onnx')
optimized = onnxoptimizer.optimize(model)
onnx.save(optimized, 'optimized_model.onnx')

Requires Python 3.10 or later; onnx must be installed as a runtime dependency.

Verify before relying

  • Which specific optimization passes are included in the prepackaged set beyond fusion and elimination.
  • Performance impact (latency/throughput gains) from applying these optimizations on typical models.
  • Whether custom optimization passes can be implemented and registered by users.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction medium — platform-specific wheel
Runtime dependencies 1 — onnx
Maintenance actively maintained — 219 days since the last release
Last repo commit
First released
Downloads 413,130/month — #6,843 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: onnxoptimizer-0.4.2-cp310-cp310-macosx_10_15_universal2.whl; onnxoptimizer-0.4.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; onnxoptimizer-0.4.2-cp310-cp310-win_amd64.whl; onnxoptimizer-0.4.2-cp311-cp311-macosx_10_15_universal2.whl; onnxoptimizer-0.4.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; onnxoptimizer-0.4.2-cp311-cp311-win_amd64.whl; onnxoptimizer-0.4.2-cp312-abi3-macosx_10_15_universal2.whl; onnxoptimizer-0.4.2-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; onnxoptimizer-0.4.2-cp312-abi3-win_amd64.whl

Keywords: deep-learning, ONNX

Tags

onnx model optimizationonnx graph optimization passesonnx operator fusiononnx model compressiononnx inference optimizationonnx constant foldingneural network model optimization
model-optimizationonnxgraph-rewriting

More Artificial Intelligence packages