Skip to content

Add optional graph-modification report to optimize() - #324

Open
take-cheeze wants to merge 1 commit into
onnx:mainfrom
onnxsim:claude/optimize-graph-modifications-result-nv82ma
Open

Add optional graph-modification report to optimize()#324
take-cheeze wants to merge 1 commit into
onnx:mainfrom
onnxsim:claude/optimize-graph-modifications-result-nv82ma

Conversation

@take-cheeze

Copy link
Copy Markdown
Member

The optimization passes already compute how many positive transforms each pass applies to the graph (CountBasedPassAnalysis), but every layer discarded this information, so optimize() only returned the optimized model.

This threads a per-pass modification report through the whole stack:

  • PassManagerAnalysis now carries a transform_counts map (pass name -> total positive transforms); both GeneralPassManager::run and FixedPointPassManager::run populate it instead of returning an empty analysis.
  • Optimizer::optimize / Optimize / OptimizeFixed accept an optional report out-parameter (defaults to nullptr, fully backward compatible).
  • New nanobind bindings optimize_report / optimize_fixedpoint_report and the path-based optimize_from_path_report / optimize_fixedpoint_from_path_report return the report alongside the model.
  • Python optimize() gains a return_report keyword. When True it returns a (model, report) tuple where report is a dict mapping pass name to the number of graph modifications; the default return type is unchanged.

Add tests covering the tuple return, the counted transform, and the zero-count (pass ran but matched nothing) case.

Claude-Session: https://claude.ai/code/session_01TSYXLexqD5r4Lkg3KfeGZj

The optimization passes already compute how many positive transforms each
pass applies to the graph (CountBasedPassAnalysis), but every layer
discarded this information, so optimize() only returned the optimized model.

This threads a per-pass modification report through the whole stack:

- PassManagerAnalysis now carries a transform_counts map (pass name ->
  total positive transforms); both GeneralPassManager::run and
  FixedPointPassManager::run populate it instead of returning an empty
  analysis.
- Optimizer::optimize / Optimize / OptimizeFixed accept an optional report
  out-parameter (defaults to nullptr, fully backward compatible).
- New nanobind bindings optimize_report / optimize_fixedpoint_report and the
  path-based optimize_from_path_report / optimize_fixedpoint_from_path_report
  return the report alongside the model.
- Python optimize() gains a return_report keyword. When True it returns a
  (model, report) tuple where report is a dict mapping pass name to the
  number of graph modifications; the default return type is unchanged.

Add tests covering the tuple return, the counted transform, and the
zero-count (pass ran but matched nothing) case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSYXLexqD5r4Lkg3KfeGZj
Signed-off-by: take-cheeze <takechi101010@gmail.com>
@take-cheeze
take-cheeze requested review from a team as code owners July 29, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants