Skip to content

Allow GraphBuilder to call script functions#2820

Merged
gramalingam merged 20 commits intomainfrom
rama/builder2
Feb 24, 2026
Merged

Allow GraphBuilder to call script functions#2820
gramalingam merged 20 commits intomainfrom
rama/builder2

Conversation

@gramalingam
Copy link
Copy Markdown
Collaborator

  • This extension allows calls to scripted functions within traced (GraphBuilder) calls.
  • As part of this extension, allow the use of OpBuilder within scripted function
  • Also fix the default value naming strategy to include node number to ensure uniqueness (in common cases).

TODO later: Consider integration of standard execution of script functions with execution of OpBuilder calls, as well as other extensions within script-mode to ensure both modes are seamless and uniform

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Comment thread onnxscript/_internal/builder_test.py Fixed
Comment thread onnxscript/_internal/builder_test.py Fixed
Comment thread onnxscript/_internal/builder_test.py Fixed
Comment thread onnxscript/_internal/builder_test.py Fixed
Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 77.21519% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.48%. Comparing base (8b79816) to head (36da9f5).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/_internal/builder_test.py 80.00% 17 Missing ⚠️
onnxscript/_internal/_inliner.py 60.00% 6 Missing and 2 partials ⚠️
onnxscript/_internal/converter.py 60.00% 3 Missing and 3 partials ⚠️
onnxscript/_internal/builder.py 86.84% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2820      +/-   ##
==========================================
+ Coverage   71.44%   71.48%   +0.03%     
==========================================
  Files         236      237       +1     
  Lines       28496    28645     +149     
  Branches     2819     2841      +22     
==========================================
+ Hits        20360    20476     +116     
- Misses       7171     7199      +28     
- Partials      965      970       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread onnxscript/_internal/builder.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enables GraphBuilder/OpBuilder to call @script-decorated ONNXScript functions, allowing seamless composition of imperative (builder) and declarative (script) code. The PR also updates the default output naming strategy to include node numbers for better uniqueness.

Changes:

  • Added call() method to GraphBuilder and OpBuilder that inlines script functions into the builder's graph
  • Modified converter to accept OpBuilder as a default_opset parameter, converting it to Opset internally
  • Updated default output naming from {op_type}_output to {op_type}_n{count}_output for uniqueness
  • Created new _inliner.py module with function instantiation logic

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
onnxscript/_internal/builder.py Added call() methods and domain/version properties to OpBuilder; updated naming strategy
onnxscript/_internal/converter.py Added support for OpBuilder as default_opset with automatic conversion to Opset
onnxscript/_internal/_inliner.py New module providing function instantiation/inlining capabilities
onnxscript/_internal/builder_test.py Comprehensive tests for call() functionality with various options (_outputs, _prefix)
docs/tutorial/builder/graph_builder.md Documentation for calling script functions from OpBuilder

Comment thread onnxscript/_internal/builder_test.py Outdated
Comment thread onnxscript/_internal/_inliner.py Outdated
Comment thread onnxscript/_internal/builder.py Outdated
Comment thread onnxscript/_internal/converter.py Outdated
Comment thread onnxscript/_internal/builder_test.py Outdated
Comment thread onnxscript/_internal/builder_test.py Outdated
Comment thread onnxscript/_internal/builder.py Outdated
Comment thread onnxscript/_internal/builder.py Outdated
Comment thread onnxscript/_internal/builder_test.py Outdated
Comment thread onnxscript/_internal/builder_test.py Outdated
gramalingam and others added 5 commits February 20, 2026 16:58
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 <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread onnxscript/_internal/builder.py Fixed
Comment thread onnxscript/_internal/builder.py Fixed
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@gramalingam gramalingam enabled auto-merge (squash) February 21, 2026 01:20
Comment thread onnxscript/_internal/_inliner.py Fixed
Comment thread onnxscript/_internal/_inliner.py Fixed
Comment thread onnxscript/_internal/_inliner.py Fixed
Comment thread onnxscript/_internal/_inliner.py Fixed
Comment thread onnxscript/_internal/_inliner.py Fixed
Comment thread onnxscript/_internal/builder.py Outdated
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Comment thread onnxscript/_internal/_inliner.py
Comment thread onnxscript/_internal/builder.py Outdated
Comment thread onnxscript/_internal/builder.py
Comment thread onnxscript/_internal/builder.py
Comment thread onnxscript/_internal/builder.py
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Comment thread onnxscript/_internal/builder.py
@gramalingam gramalingam merged commit f99fa7d into main Feb 24, 2026
30 of 33 checks passed
@gramalingam gramalingam deleted the rama/builder2 branch February 24, 2026 19:03
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.

4 participants