onnxsim
Repo skill for ONNX Simplifier: ONNX model simplification, graph rewriting, metrics, profiling, packaging, and bindings.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- onnxsim
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Repo skill for ONNX Simplifier: ONNX model simplification, graph rewriting, metrics, profiling, packaging, and bindings.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/package-overview.md4.3 KB
- 参考文档references/repo-provenance.md2.1 KB
- 参考文档references/repo-routing-metadata.json520 B
- 参考文档references/troubleshooting.md3.8 KB
- 脚本scripts/check_onnxsim_env.py6.9 KB
03 SKILL.md 正文
ONNX Simplifier (onnxsim)
Use this repo skill when a task involves ONNX Simplifier / onnxsim: simplifying
exported ONNX graphs, validating simplified models, controlling optimizer and
constant-folding behavior, using custom rewrite rules, inspecting model metrics
or profile traces, or maintaining the package's Python/C++/Rust/WASM bindings.
Start here
- Read package overview for package identity, install commands, backend model, and route selection.
- Read cross-cutting troubleshooting when the failure surface is unclear.
- Read repository provenance before deciding whether this skill is current for a checkout or before running a refresh.
references/repo-routing-metadata.jsonis structured metadata for managed repo-skill import; do not hand-edit router Markdown.
Minimal installed-package check
python -m pip install -U onnxsim
python -c "import onnxsim; print(onnxsim.__version__)"
onnxsim --help
onnxsim --list-default-optimizers
If an environment may be broken, run the bundled checker from this skill root:
python scripts/check_onnxsim_env.py --help
python scripts/check_onnxsim_env.py --smoke --json
python scripts/check_onnxsim_env.py --providers CPUExecutionProvider --json
The checker imports onnxsim, verifies the compiled extension, reports optional
ONNX Runtime providers, probes the CLI optimizer list, and can run a tiny
in-memory simplification smoke.
Route by task
| User task | Read |
|---|---|
| Simplify an ONNX file with the CLI, set input shapes, run correctness checks, choose CPU/CUDA providers, save external data, convert target opset, or use custom operator schemas | sub-skills/python-simplification/SKILL.md |
Call onnxsim.simplify from Python with ModelProto objects, inspect the full API signature, map CLI flags to parameters, or recover from model/check/provider errors |
sub-skills/python-simplification/SKILL.md |
Author Python custom_rewriter callbacks, pure-data FunctionProto rewrite rules, or custom schema import logic |
sub-skills/advanced-graph-control/SKILL.md |
Use ModelInfo, MACs/FLOPs/memory metrics, annotate_metadata, diff_graphs, --graph-diff, profile, ort_profile, or merged ONNX Runtime traces |
sub-skills/advanced-graph-control/SKILL.md |
| Install/build from source, diagnose missing submodules/nanobind/protobuf/CMake, build the C API, use Rust crates, build WASM/npm/web demo, or check release versions | sub-skills/bindings-and-packaging/SKILL.md |
Key operating facts
onnxsim.simplify(model, ...)accepts an ONNX file path or an in-memoryonnx.ModelProtoand returns(simplified_model, check_ok).- CPU constant folding is the default.
onnxruntimeis optional for the Python package; without it, onnxsim can use ONNX's reference evaluator. - Non-CPU execution providers require ONNX Runtime with the matching provider
build.
--cudameans--providers CUDAExecutionProvider CPUExecutionProvider. - Custom operator schemas registered in Python ONNX are imported into onnxsim's
registry by default; CLI users can disable that with
--skip-schema-import. - Python
custom_rewritercallbacks and pure-datafunction_rewrite_rulesare mutually exclusive in onesimplify()call. - FunctionProto rewrite rules are portable to C/Rust bindings because they are protobuf data matched in the C++ core.
ModelInfoandannotate_metadataare static inspection tools; unknown shapes or missing optionalsympycan make metrics best-effort or symbolic.- The Python wheel/editable build uses
-DONNXSIM_BUILTIN_ORT=OFF; it does not compile vendored ONNX Runtime C++. ONNX Runtime C++ builds belong to standalone CMake/C API/Rust native-library/default-WASM paths.
Bundled scripts
scripts/check_onnxsim_env.py: installed package, provider, CLI, and tiny simplification smoke checker.sub-skills/python-simplification/scripts/simplify_tiny_model.py: safe tiny model simplification helper.sub-skills/advanced-graph-control/scripts/function_rule_smoke.py: pure-data FunctionProto rewrite smoke.sub-skills/advanced-graph-control/scripts/model_metrics_smoke.py: metrics, metadata, and graph-diff smoke.sub-skills/bindings-and-packaging/scripts/check_version_sync.py: read-only version metadata checker for a user-supplied source tree.
Safe defaults
- Prefer a released wheel plus
onnxsim --help/--list-default-optimizersfor ordinary use. - Use
check_n, deterministicinput_fill, and explicittest_input_shapeswhen correctness matters. - Start optional provider and build investigations with help/version/smoke checks; do not install heavy CUDA/QNN/TVM/Halide/model-export stacks or launch long WASM/Rust/native builds unless the user explicitly selected that path.
- Treat
check_ok=False, provider validation errors, and schema validation errors as blockers for deployment-style tasks until the user accepts the risk or the issue is fixed.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).