Add parent/root tracking to GraphBuilder for subgraph Parameter realization#2877
Merged
gramalingam merged 6 commits intomainfrom Apr 2, 2026
Merged
Add parent/root tracking to GraphBuilder for subgraph Parameter realization#2877gramalingam merged 6 commits intomainfrom
gramalingam merged 6 commits intomainfrom
Conversation
…zation GraphBuilder now accepts an optional parent parameter. When provided, _root points to the root builder of the parent chain, ensuring that Parameter._realize() registers initializers in the main (root) graph rather than in the subgraph where the parameter is referenced. This is needed for ONNX Scan/Loop body subgraphs where nn.Module parameters must be stored in the parent graph as implicit inputs. Changes: - GraphBuilder.__init__: accept parent, store _parent and _root - build_graph(): accept and forward parent to sub-builder - GraphBuilder.subgraph(): pass parent=self to build_graph() - Parameter._realize(): use builder._root for name qualification and initializer registration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: G Ramalingam <grama@microsoft.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2877 +/- ##
==========================================
+ Coverage 71.96% 72.03% +0.06%
==========================================
Files 239 239
Lines 29224 29295 +71
Branches 2878 2879 +1
==========================================
+ Hits 21031 21102 +71
Misses 7216 7216
Partials 977 977 ☔ View full report in Codecov by Sentry. |
justinchuby
approved these changes
Apr 1, 2026
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
justinchuby
approved these changes
Apr 2, 2026
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.
GraphBuilder now accepts an optional parent parameter. When provided, _root points to the root builder of the parent chain, ensuring that Parameter._realize() registers initializers in the main (root) graph rather than in the subgraph where the parameter is referenced.
This is needed for ONNX Scan/Loop body subgraphs where nn.Module parameters must be stored in the root graph instead of the attribute subgraph.
Changes: