Skip to content

Add parent/root tracking to GraphBuilder for subgraph Parameter realization#2877

Merged
gramalingam merged 6 commits intomainfrom
rama/initializer
Apr 2, 2026
Merged

Add parent/root tracking to GraphBuilder for subgraph Parameter realization#2877
gramalingam merged 6 commits intomainfrom
rama/initializer

Conversation

@gramalingam
Copy link
Copy Markdown
Collaborator

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:

  • 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

…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
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.03%. Comparing base (1077da7) to head (e20440c).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@gramalingam gramalingam enabled auto-merge (squash) April 1, 2026 21:58
gramalingam and others added 4 commits April 1, 2026 15:37
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>
@gramalingam gramalingam merged commit 5391619 into main Apr 2, 2026
30 of 33 checks passed
@gramalingam gramalingam deleted the rama/initializer branch April 2, 2026 00:21
@github-project-automation github-project-automation bot moved this from Todo to Done in ONNX Script Review Board Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants