-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -188,39 +188,39 @@ | |||||||||||||||||||||||||||||||||
| inputs: The ONNX inputs to the op. | ||||||||||||||||||||||||||||||||||
| attributes: The ONNX attributes to the op. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| op_signature = _schemas.OpSignature.from_op_schema(schema) | ||||||||||||||||||||||||||||||||||
| attributes = _unwrap_tensors_in_kwargs(attributes) | ||||||||||||||||||||||||||||||||||
| attributes, closure = self.adapt_attributes(schema, attributes) | ||||||||||||||||||||||||||||||||||
| inputs = self.adapt_inputs(schema, inputs) | ||||||||||||||||||||||||||||||||||
| attributes, closure = self._adapt_attributes(op_signature, attributes) | ||||||||||||||||||||||||||||||||||
| inputs = self._adapt_inputs(op_signature, inputs) | ||||||||||||||||||||||||||||||||||
| outputs = self._eval(schema, inputs, attributes, closure) | ||||||||||||||||||||||||||||||||||
| return self.adapt_outputs(schema, outputs) | ||||||||||||||||||||||||||||||||||
| return self._adapt_outputs(outputs) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def adapt_inputs(self, schema: onnx.defs.OpSchema, inputs: Sequence[ExtendedModeValue]): | ||||||||||||||||||||||||||||||||||
| def _adapt_inputs( | ||||||||||||||||||||||||||||||||||
| self, op_signature: _schemas.OpSignature, inputs: Sequence[ExtendedModeValue] | ||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||
| """Transform inputs to the expected format for the evaluator. | ||||||||||||||||||||||||||||||||||
| Enables some syntactic sugar, such as the use of Python scalars, | ||||||||||||||||||||||||||||||||||
| in a manner consistent with the translator. See autocast.py for details. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| return autocast.dynamic_cast_inputs(schema, inputs) | ||||||||||||||||||||||||||||||||||
| return autocast.dynamic_cast_inputs(op_signature, inputs) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def adapt_attributes( | ||||||||||||||||||||||||||||||||||
| self, schema: onnx.defs.OpSchema, attributes: Mapping[str, ExtendedModeValue] | ||||||||||||||||||||||||||||||||||
| def _adapt_attributes( | ||||||||||||||||||||||||||||||||||
| self, op_signature, attributes: Mapping[str, ExtendedModeValue] | ||||||||||||||||||||||||||||||||||
Check warningCode scanning / lintrunner PYLINT/W0613 Warning
Unused argument 'op_signature' (unused-argument)
See unused-argument. To disable, use # pylint: disable=unused-argument |
||||||||||||||||||||||||||||||||||
| ) -> tuple[dict[str, ExtendedModeValue], dict[str, ExtendedModeValue]]: | ||||||||||||||||||||||||||||||||||
| """Transform attributes to the expected format for the evaluator. | ||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||
| A closure that can be used to evaluate graph-valued attributes. | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| use_graph_attribute = self.use_graph_attribute(schema) | ||||||||||||||||||||||||||||||||||
| use_graph_attribute = self.use_graph_attribute(op_singature) | ||||||||||||||||||||||||||||||||||
|
Check warning on line 216 in onnxscript/_internal/evaluator.py
|
||||||||||||||||||||||||||||||||||
Check failureCode scanning / lintrunner PYLINT/E0602 Error
Undefined variable 'op_singature' (undefined-variable)
See undefined-variable. To disable, use # pylint: disable=undefined-variable Check failureCode scanning / lintrunner RUFF/F821 Error
Undefined name op_singature.
See https://docs.astral.sh/ruff/rules/undefined-name Check warningCode scanning / lintrunner PYLINT/W0612 Warning
Unused variable 'use_graph_attribute' (unused-variable)
See unused-variable. To disable, use # pylint: disable=unused-variable Check warningCode scanning / lintrunner RUFF/F841 Warning
Local variable use_graph_attribute is assigned to but never used.
See https://docs.astral.sh/ruff/rules/unused-variable |
||||||||||||||||||||||||||||||||||
| closure: dict[Any, Any] = {} | ||||||||||||||||||||||||||||||||||
| adapted_attributes = {} | ||||||||||||||||||||||||||||||||||
| for k, v in attributes.items(): | ||||||||||||||||||||||||||||||||||
| if isinstance(v, values.OnnxClosure): | ||||||||||||||||||||||||||||||||||
| if use_graph_attribute: | ||||||||||||||||||||||||||||||||||
| adapted_attributes[k] = v.function_ir.to_graph_proto() | ||||||||||||||||||||||||||||||||||
| for pyvar, onnxvar in v.function_ir.outer_scope_variables: | ||||||||||||||||||||||||||||||||||
| closure[onnxvar.value.name] = v.frame.f_locals[pyvar] | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| adapted_attributes[k] = v.function | ||||||||||||||||||||||||||||||||||
| adapted_attributes[k] = v.function_ir.to_graph_proto() | ||||||||||||||||||||||||||||||||||
| for pyvar, onnxvar in v.function_ir.outer_scope_variables: | ||||||||||||||||||||||||||||||||||
| closure[onnxvar.value.name] = v.frame.f_locals[pyvar] | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+221
to
+223
|
||||||||||||||||||||||||||||||||||
| adapted_attributes[k] = v.function_ir.to_graph_proto() | |
| for pyvar, onnxvar in v.function_ir.outer_scope_variables: | |
| closure[onnxvar.value.name] = v.frame.f_locals[pyvar] | |
| # If the closure captures outer-scope variables, we must materialize | |
| # a graph proto and populate the closure mapping so that evaluators | |
| # can rebind these values when executing the attribute. | |
| if v.function_ir.outer_scope_variables: | |
| adapted_attributes[k] = v.function_ir.to_graph_proto() | |
| for pyvar, onnxvar in v.function_ir.outer_scope_variables: | |
| closure[onnxvar.value.name] = v.frame.f_locals[pyvar] | |
| else: | |
| # For closures without captured outer-scope variables, avoid | |
| # forcing a graph-valued attribute so that evaluators such as | |
| # ORTMixedEvaluator can continue to use the underlying function | |
| # implementation directly (e.g., for registered python ops). | |
| adapted_attributes[k] = v.function_ir |
Check warning
Code scanning / lintrunner
PYLINT/W0613 Warning
See unused-argument. To disable, use # pylint: disable=unused-argument
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.
This TODO indicates that the previous
is_homogeneoushandling was removed but needs to be reimplemented. The old code had logic to handle non-homogeneous variadic parameters. This unfinished work could lead to bugs if non-homogeneous variadic parameters are encountered.