Add C++ IR (Graph) entry point to the optimizer - #319
Open
take-cheeze wants to merge 1 commit into
Open
Conversation
Previously every public entry point required a ModelProto (or serialized bytes / file path); the in-memory ONNX C++ IR (Graph) was only ever built internally via ImportModelProto and torn down via ExportModelProto, never exposed as an input. A C++ caller already holding a Graph had to pay a full serialize/parse round-trip on both sides just to run the passes. Add in-place Graph entry points that run the configured passes directly on the IR: - Optimizer::optimize(Graph&) overload that runs the pass manager on the graph in place; the existing optimize(ModelProto&) now reuses it. - Free functions OptimizeGraph / OptimizeGraphFixed mirroring Optimize / OptimizeFixed but operating on a Graph&. Proto-level concerns (ir_version upgrade, function copying) stay on the ModelProto path since they have no Graph equivalent. The additions are purely additive with no ABI break. Add a gtest covering the Graph path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7PHiYF9q8Tv1KWV5w65Hq Signed-off-by: take-cheeze <takechi101010@gmail.com>
take-cheeze
force-pushed
the
claude/onnx-cpp-ir-optimizer-api-rrjtni
branch
from
July 26, 2026 03:09
91bbecc to
880ef9d
Compare
3 tasks
take-cheeze
added a commit
to onnxsim/onnxsim
that referenced
this pull request
Aug 18, 2026
Add Graph-native optimize entry points (port of onnx/optimizer#319)
pull Bot
pushed a commit
to naonao-cola/onnx-simplifier
that referenced
this pull request
Aug 18, 2026
Ports onnx/optimizer#319 (Optimizer::optimize(Graph&), OptimizeGraph, OptimizeGraphFixed) into onnxsim's onnx-optimizer fork: a C++ caller that already holds a Graph can run the configured passes directly on it, with no ModelProto <-> Graph round trip at all. onnxsim's own ModelProto-based Optimize()/OptimizeFixed() calls (onnxsim.cpp) already round-trip through ModelProto on every round of OptAndShape's fixed point, alternating with InferShapes; the fixed point's convergence check (FixedPointFn's bool-returning overload) stops as soon as *either* side reports no change, so there is no "several consecutive Optimize-only rounds on a resident Graph" window in the current algorithm to route through the new Graph-native entry point for a further round-trip reduction there -- that still needs shape inference itself ported to Graph IR (onnx issue onnxsim#633's "remaining option 2", "a different order of magnitude of work" per that issue). This bump lands the primitive and keeps onnxsim/optimizer's ModelProto-based optimize() sharing one code path with it (the fork's two ModelProto overloads now delegate to optimize(Graph&, report) internally instead of calling pass_manager->run() directly), without changing onnxsim.cpp's behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously every public entry point required a ModelProto (or serialized bytes / file path); the in-memory ONNX C++ IR (Graph) was only ever built internally via ImportModelProto and torn down via ExportModelProto, never exposed as an input. A C++ caller already holding a Graph had to pay a full serialize/parse round-trip on both sides just to run the passes.
Add in-place Graph entry points that run the configured passes directly on the IR:
Proto-level concerns (ir_version upgrade, function copying) stay on the ModelProto path since they have no Graph equivalent. The additions are purely additive with no ABI break. Add a gtest covering the Graph path.
Claude-Session: https://claude.ai/code/session_01U7PHiYF9q8Tv1KWV5w65Hq