-
Notifications
You must be signed in to change notification settings - Fork 98
Replace op_schema with op_signature #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2771 +/- ##
==========================================
- Coverage 70.45% 62.96% -7.49%
==========================================
Files 228 228
Lines 27257 27140 -117
Branches 2760 2736 -24
==========================================
- Hits 19203 17089 -2114
- Misses 7102 9207 +2105
+ Partials 952 844 -108 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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 refactors how operator schemas are handled by replacing direct usage of onnx.defs.OpSchema with a new _schemas.OpSignature abstraction throughout the autocast, converter, and evaluator modules. This change improves modularity and encapsulation when dealing with operator signatures.
Changes:
- Replaced
OpSchemawithOpSignaturein autocast functions for input type casting - Updated converter to pass
op_signatureinstead ofop_schemato autocast functions - Refactored evaluator methods to be private (
_adapt_inputs,_adapt_attributes,_adapt_outputs) and removed theuse_graph_attributemethod along with its associated conditional logic
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxscript/_internal/autocast.py | Updated to use OpSignature instead of OpSchema, including parameter filtering and type constraint access changes |
| onnxscript/_internal/converter.py | Changed to pass op_signature instead of op_schema to autocast functions |
| onnxscript/_internal/evaluator.py | Made adapter methods private, removed use_graph_attribute method, and simplified _adapt_attributes to always use graph attributes |
Comments suppressed due to low confidence (1)
onnxscript/_internal/evaluator.py:548
- The
use_graph_attributemethod inORTMixedEvaluatoris now dead code since it's no longer called after removing the conditional logic in_adapt_attributes. This method should be removed from theORTMixedEvaluatorclass.
def use_graph_attribute(self, schema: onnx.defs.OpSchema) -> bool:
return _schema_id(schema) not in self._python_ops
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
onnxscript/_internal/values.py:364
- The docstring still mentions a 'functions' parameter that was removed from the method signature. This outdated documentation should be removed.
functions: A list of functions to include in the model.
By default, all functions called at least once are included.
|
Is this ready? |
|
I thought it was but looks not. Will update |
|
Feel free to put in review comments though. Thanks! |
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
…xpression output Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
| assert op_signature is not None, f"Op {op.name} has no signature." | ||
| attributes = _unwrap_tensors_in_kwargs(kwargs) | ||
| attributes, closure = self._adapt_attributes(op_signature, attributes) | ||
| inputs = self._adapt_inputs(op_signature, args) | ||
| outputs = self._eval(op.op_schema, inputs, attributes, closure) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eval_op uses an assert to require op.op_signature and then calls _eval(op.op_schema, ...), but op.op_schema can be None (e.g., custom/unknown ops). This will raise an AssertionError (or pass None into _eval) instead of a user-facing exception. Please replace the assert with an explicit check that raises a clear RuntimeError/ValueError, and also validate op.op_schema is present (or change _eval to take the needed identifier/signature instead of an OpSchema).
| for func in ir_functions: | ||
| domain = func.domain | ||
| if domain is not None and domain not in opset_imports: | ||
| opset_imports[domain] = func.meta.get("opset_version", 1) | ||
|
|
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_to_model_proto updates opset_imports using only func.domain (from func.meta['opset_version']) and partially handles the default domain, but it does not merge the full func.opset_imports map for other domains used inside nested functions. This can produce a model missing required opset imports. Consider merging all domains/versions from each func.opset_imports (and resolving conflicts), and avoid relying solely on func.meta['opset_version'] when the version is available in func.opset_imports.
| fail(info.msg(str(e))) | ||
| attr = self._make_onnx_attr("value", tensor) | ||
|
|
||
| attr = ir.AttrTensor("value", ir.tensor(pyvalue, name=ovar)) |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_emit_const no longer wraps tensor construction in a try/except that reports a source-location-aware error via self.fail(...). If ir.tensor(pyvalue, ...) rejects an unsupported constant, the exception will bubble up without source context. Please restore error handling so conversion failures are surfaced with info (consistent with the prior behavior).
| attr = ir.AttrTensor("value", ir.tensor(pyvalue, name=ovar)) | |
| try: | |
| tensor = ir.tensor(pyvalue, name=ovar) | |
| except Exception as exc: # noqa: BLE001 | |
| self.fail( | |
| info, | |
| f"Failed to convert constant value {pyvalue!r} to ONNX tensor: {exc}", | |
| ) | |
| attr = ir.AttrTensor("value", tensor) |
|
|
||
| @pytest.mark.xfail( | ||
| strict=True, | ||
| strict=False, |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest.mark.xfail(strict=False, ...) will no longer fail the suite if this test unexpectedly starts passing (XPASS), which can hide progress/regressions. If the test is expected to fail until optional outputs are implemented, keep strict=True (or remove xfail once it passes).
| strict=False, | |
| strict=True, |
This pull request refactors how operator schemas are handled throughout the autocast, converter, and evaluator modules. The main change is replacing direct usage of
OpSchemawith a new_schemas.OpSignatureabstraction, leading to more consistent and modular code when dealing with operator signatures, especially for input casting and evaluation. Several related methods are renamed and refactored for clarity and encapsulation.Important changes
Evaluatorinterface now defineseval_opon onnx ops. The oldevalwas removed in favor of a more flexibleeval_op. The exporter's eval will continue to function with a compatible logic inclass Opop_schemaproperties from Functions are removedOperator signature abstraction and autocast refactor:
OpSchemawith_schemas.OpSignatureinonnxscript/_internal/autocast.py, updating all relevant function signatures and internal logic to use the new abstraction. This includes changing how input parameters are filtered and type constraints are accessed.AST Converter integration:
onnxscript/_internal/converter.py) to passop_signatureinstead ofop_schemato autocast functions, ensuring compatibility with the new signature abstraction.Evaluator refactor and encapsulation:
onnxscript/_internal/evaluator.py) to use_adapt_inputs,_adapt_attributes, and_adapt_outputsmethods, encapsulating the logic for adapting inputs/outputs and removing unused or redundant methods. Now, operator signatures are consistently adapted fromOpSchemausing_schemas.OpSignature.Addtionally: