技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
advanced-graph-control【数据与研究】Advanced graph-control workflows for ONNX Simplifier: custom rewriters, FunctionProto rules, metrics, graph diffs, metadata, and profiling.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is not just "simplify this ONNX model", but needs control over the simplification fixed point, graph rewrite rules, schema registration, graph inspection, model metrics, metadata annotations, or profiling traces.
../python-simplification/SKILL.md.../bindings-and-packaging/SKILL.md.references/rewriters-and-rules.mdreferences/metrics-and-profiling.mdreferences/troubleshooting.mdRun these from any environment where onnx and onnxsim are importable; they do
not require the original repository checkout.
python scripts/function_rule_smoke.py --help
python scripts/function_rule_smoke.py
python scripts/model_metrics_smoke.py --help
python scripts/model_metrics_smoke.py
scripts/function_rule_smoke.py builds a
tiny MatMul + Add model, applies a pure-data FunctionProto rule that rewrites
it to Gemm, skips the built-in Gemm fusion so the rule is provably
responsible, and asserts the rewritten graph contains Gemm.scripts/model_metrics_smoke.py builds a
tiny model, reports ModelInfo metrics, annotates metrics into
metadata_props, and prints a compact graph-diff summary.Use custom_rewriter= when the rewrite is Python-only or needs a richer matcher
than onnxsim's built-in FunctionProto matcher.
onnx.ModelProto.onnx.ModelProto and either:
onnx.ModelProto,None, orFalse when this fixed-point round changed nothing.onnxsim.simplify(model, custom_rewriter=callable, check_n=...).check_n > 0.Prefer returning False on no-op rounds; it is the no-change sentinel that
prevents unnecessary serialize/parse copies and helps the fixed point converge.
Use function_rewrite_rules= when a rule can be expressed as pure ONNX graph
data and should also be usable from C or Rust.
(pattern, replacement) pair as onnx.FunctionProto objects,
usually with onnx.parser.parse_function.@name / ref_attr_name for attribute wildcards that bind from the
matched node and substitute into the replacement.function_rewrite_rules=[(pattern, replacement)] to onnxsim.simplify.skipped_optimizers=["that_optimizer"] while validating the rule itself.custom_rewriter and function_rewrite_rules are mutually exclusive in one
simplify() call.
If the model contains custom ops that should remain schema-valid:
import onnx
import onnxsim
onnx.defs.register_schema(my_op_schema)
# simplify() imports registered schemas automatically by default.
model_simp, ok = onnxsim.simplify(model)
Call onnxsim.import_onnx_schemas() explicitly when you need an import count or
want to prime the onnxsim registry. Disable the automatic import only when you
know the model does not require Python-registered schemas:
onnxsim.simplify(model, import_custom_schemas=False) or CLI
--skip-schema-import.
Use onnxsim.model_info for static inspection without running inference:
from onnxsim.model_info import ModelInfo, annotate_metadata, diff_graphs
info = ModelInfo(model)
annotated = annotate_metadata(model)
diff = diff_graphs(original_model, simplified_model)
Metrics include operator counts, serialized model size, MACs, FLOPs, memory
access, peak memory footprint, and compute density. Some values are symbolic
when dynamic dimensions are named and sympy is installed; otherwise unresolved
dimensions are best-effort lower bounds.
Use profiling when a simplification is unexpectedly slow, memory-heavy, or when constant folding/optimizer cost attribution matters.
model_simp, ok = onnxsim.simplify(model, profile="profile.json")
model_simp, ok = onnxsim.simplify(model, ort_profile="ort_profile")
model_simp, ok = onnxsim.simplify(
model, profile="profile.json", merge_ort_profile=True
)
CLI equivalents are --profile, --ort-profile, and --merge-ort-profile.
Open Chrome trace JSON files in chrome://tracing or Perfetto. Use a scratch or
user-selected output directory for traces; do not leave large trace files in a
runtime skill directory.
--help checks before relying on a script in a new environment.onnx.checker.check_n or explicit input_data; use check_n=0
only for structural or intentionally semantics-changing transformations.