Support None as op input in GraphBuilder#2868
Merged
justinchuby merged 3 commits intomainfrom Mar 27, 2026
Merged
Conversation
added 2 commits
March 26, 2026 17:40
Signed-off-by: Justin Chu <justinchuby@noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for passing None as an op input in onnxscript’s imperative GraphBuilder, enabling correct construction of nodes with optional inputs (e.g., Gemm’s optional C input).
Changes:
- Extends
VALUE_LIKEand input conversion to allowNoneto pass through as an omitted/optional input. - Updates builder call paths (
_partition_inputs_attributes,call_op) to acceptNonein input sequences. - Adds unit tests validating
Nonebehavior for both standard-domain and custom-domain ops.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
onnxscript/_internal/builder.py |
Extends accepted input types and conversion/call signatures to preserve None inputs. |
onnxscript/_internal/builder_test.py |
Adds tests asserting None is preserved in node input slots for optional inputs. |
Comments suppressed due to low confidence (1)
onnxscript/_internal/builder.py:366
_partition_inputs_attributescan returninputscontainingNone(e.g., whenschema is Noneit returnsinputsunchanged). The return type annotation currently excludesNone, which makes the typing inconsistent with the new optional-input behavior and with_cast_inputs(which returnsSequence[ir.Value | None]). Please update the return type (and ideally the acceptedinputstype) to includeNone/VALUE_LIKEso the signatures match actual runtime behavior.
inputs: Sequence[ir.Value | ir.TensorProtocol | None],
kwargs: dict[str, Any],
) -> tuple[Sequence[ir.Value | ir.TensorProtocol], dict[str, Any]]:
if schema is None:
return inputs, kwargs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2868 +/- ##
==========================================
+ Coverage 71.87% 71.90% +0.02%
==========================================
Files 239 239
Lines 29150 29175 +25
Branches 2875 2876 +1
==========================================
+ Hits 20953 20978 +25
Misses 7219 7219
Partials 978 978 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Justin Chu <justinchuby@noreply.github.com>
titaiwangms
approved these changes
Mar 27, 2026
justinchuby
added a commit
that referenced
this pull request
Apr 17, 2026
Support \`None\` as a valid input to \`op.OpType()\` calls in the onnxscript builder. This is needed for ONNX ops with optional inputs (e.g., Gemm's optional C input). - Add \`None\` to the \`VALUE_LIKE\` union type - Update \`_input_to_ir_value\` to return \`ir.Value | None\` and pass \`None\` through - Update \`_partition_inputs_attributes\` and \`call_op\` type signatures to accept \`None\` - Add tests for \`None\` inputs with standard and custom domain ops Also removed pylint because it is not doing much good nowadays. --------- Signed-off-by: Justin Chu <justinchuby@noreply.github.com> Co-authored-by: Justin Chu <justinchuby@noreply.github.com>
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.
Summary
Support `None` as a valid input to `op.OpType()` calls in the onnxscript builder. This is needed for ONNX ops with optional inputs (e.g., Gemm's optional C input).
Changes
Also removed pylint because it is not doing much good nowadays.