optimizer

onnxApache-2.0活跃维护

对 ONNX 模型做图级优化的 Python 工具,通过算子融合、常量折叠等变换精简计算图,让推理更快、模型更小。

ONNX Optimizer

v0.4.2发布于 2026-01-07 12:58 UTC841star115fork同步于 2026-11-10 05:58 UTC

怎么上手

由 README 提炼,执行前请确认
pip3 install onnxoptimizer
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

ONNX 模型的 C++ 优化库,提供可复用的预置优化 pass,供各后端共享图优化工作

对 ONNX 模型做图级优化的 Python 工具,通过算子融合、常量折叠等变换精简计算图,让推理更快、模型更小。

核心能力

  • 提供 C++ 库对 ONNX 模型执行任意优化
  • 内置一系列预置优化 pass 可直接调用
  • 支持用 -p 指定 pass 列表,默认跑 fuse 与 elimination pass
  • 支持 --fixed_point 反复迭代直到不再变化
  • 提供命令行入口,无需写 Python 脚本

容易踩的坑

从源码构建需先安装 protobuf,且要 git clone --recursive 拉取子模块;命令行不指定 -p 时默认只跑 fuse_and_elimination_passes,而非全部 pass;pip 安装失败时需先 pip3 install -U pip 升级 pip

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.4.2
  1. v0.4.20.4.2最新正式版2026-01-07 · 2026-01-07 12:58 UTC

    What's Changed

    Full Changelog: https://github.com/onnx/optimizer/compare/v0.4.1...v0.4.2

  2. v0.4.2rc2pre-release2026-01-01 · 2026-01-01 16:33 UTC

    这个版本没有写更新说明。

  3. v0.4.2rc1pre-release2025-12-31 · 2025-12-31 07:36 UTC

    这个版本没有写更新说明。

  4. v0.4.1_12025-12-30 · 2025-12-30 17:03 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/onnx/optimizer/compare/v0.4.1...v0.4.1_1

  5. v0.4.12025-12-30 · 2025-12-30 06:59 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/onnx/optimizer/compare/v0.4.0...v0.4.1

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    ONNX Optimizer

    PyPI version PyPI license PRs Welcome

    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:

    pip3 install onnxoptimizer
    

    Note that you may need to upgrade your pip first if you have trouble:

    pip3 install -U pip
    

    If you want to build from source:

    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 for the details)

    Relevant tools

    Code of Conduct

    ONNX Open Source Code of Conduct