Skip to content

Implement schema-based input/attribute partitioning in GraphBuilder#2837

Open
gramalingam wants to merge 1 commit intomainfrom
rama/params
Open

Implement schema-based input/attribute partitioning in GraphBuilder#2837
gramalingam wants to merge 1 commit intomainfrom
rama/params

Conversation

@gramalingam
Copy link
Collaborator

  • Convert onnx.defs.OpSchema to ir.schemas.OpSignature via from_op_schema and delegate to separate_input_attributes_from_arguments
  • Add allow_extra_args parameter to separate_input_attributes_from_arguments for rejecting unexpected positional arguments (default True for compat)
  • Builder uses strict mode: allow_extra_kwargs=False, allow_extra_args=False
  • Refactor _build test helper: accept TypeSpec, optional trace_function, return ir.Graph directly
  • Add comprehensive tests for input/attribute partitioning

- Convert onnx.defs.OpSchema to ir.schemas.OpSignature via from_op_schema
  and delegate to separate_input_attributes_from_arguments
- Add allow_extra_args parameter to separate_input_attributes_from_arguments
  for rejecting unexpected positional arguments (default True for compat)
- Builder uses strict mode: allow_extra_kwargs=False, allow_extra_args=False
- Refactor _build test helper: accept TypeSpec, optional trace_function,
  return ir.Graph directly
- Add comprehensive tests for input/attribute partitioning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
)

onnx_model = ir.Model(graph=graph, ir_version=10)
resolved_inputs = [builder._resolve_type_spec(t) for t in input_types]

Check warning

Code scanning / lintrunner

PYLINT/W0212 Warning

Access to a protected member _resolve_type_spec of a client class (protected-access)
See protected-access. To disable, use # pylint: disable=protected-access
output.type = output_type.type # TODO: need merge_type method in ir.Value
output.merge_shapes(output_type.shape)
if output_types is not None:
resolved_outputs = [builder._resolve_type_spec(t) for t in output_types]

Check warning

Code scanning / lintrunner

PYLINT/W0212 Warning

Access to a protected member _resolve_type_spec of a client class (protected-access)
See protected-access. To disable, use # pylint: disable=protected-access
trace_function=_dummy,
)
x, y = graph.inputs
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
trace_function=_add,
)
x, y = graph.inputs
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
trace_function=_gemm,
)
a, b, c = graph.inputs
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
trace_function=_gemm_no_c,
)
a, b = graph.inputs
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
input_types=[FLOAT[3, 4], FLOAT[4, 5]],
trace_function=_gemm_no_attrs,
)
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
trace_function=_concat,
)
x, y, z = graph.inputs
node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
)
data, starts, ends, axes, steps = graph.inputs

slice_node = list(graph)[0]

Check warning

Code scanning / lintrunner

RUFF/RUF015 Warning

Prefer next(iter(graph)) over single element slice.
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 97.05882% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.87%. Comparing base (555f81e) to head (acc5090).
⚠️ 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 96.77% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2837      +/-   ##
==========================================
+ Coverage   71.79%   71.87%   +0.07%     
==========================================
  Files         239      239              
  Lines       29019    29092      +73     
  Branches     2864     2867       +3     
==========================================
+ Hits        20834    20909      +75     
+ Misses       7213     7210       -3     
- Partials      972      973       +1     

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

# Not implemented yet
del schema
return inputs, kwargs
if schema is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Op object has the signature cached. Would it be possible to use that?

Copy link
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 PR activates schema-based input/attribute partitioning in GraphBuilder, which was previously stubbed out. It also adds an allow_extra_args parameter to separate_input_attributes_from_arguments for strict positional-argument validation, and refactors the _build test helper to return ir.Graph directly (removing the intermediate ir.Model wrapper).

Changes:

  • Added allow_extra_args parameter to separate_input_attributes_from_arguments in param_manipulation.py, enforcing a check for extra positional arguments when a schema is known and no variadic parameter exists.
  • Implemented GraphBuilder._partition_inputs_attributes in builder.py to delegate to separate_input_attributes_from_arguments via ir.schemas.OpSignature.from_op_schema, using strict mode (fill_defaults=False, allow_extra_args=False).
  • Refactored the _build test helper in builder_test.py to accept TypeSpec inputs, make trace_function optional, return ir.Graph directly, and added a comprehensive PartitionInputsAttributesTest suite.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
onnxscript/_internal/param_manipulation.py Adds allow_extra_args parameter and validates extra positional args after the main loop
onnxscript/_internal/builder.py Implements _partition_inputs_attributes using schema-based partitioning instead of a no-op stub
onnxscript/_internal/builder_test.py Refactors _build helper and adds PartitionInputsAttributesTest covering 9 new test cases

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