-
Notifications
You must be signed in to change notification settings - Fork 71
Retire get_schema
in Op | chore!(api)
#698
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d3abfcb
Retire `get_schema` in Op | chore!(api)
justinchuby 4dbb375
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 89f8bb5
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 14a7bc9
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby f38e081
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby d7825d2
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 3a45755
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 81deba0
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby fd0757a
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 60b670b
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 9d89487
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby fb039d6
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby f12c353
Update base for Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby e4b8ebd
Update on "Retire `get_schema` in Op | chore!(api)"
justinchuby 0aea4df
Merge branch 'main' into gh/justinchuby/24/head
justinchuby 8525e38
Update converter.py
justinchuby e0f311a
Update values.py
justinchuby be5e013
Merge branch 'main' into gh/justinchuby/24/head
justinchuby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,7 @@ def opset(self) -> Opset: | |
... | ||
|
||
@property | ||
def opschema(self) -> Optional[onnx.defs.OpSchema]: | ||
def op_schema(self) -> Optional[onnx.defs.OpSchema]: | ||
... | ||
|
||
def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]: | ||
|
@@ -258,31 +258,39 @@ class Op(OpLike): | |
Attributes: | ||
opset: The Opset that this op belongs to. | ||
name: The name of the op. | ||
opschema: The ONNX OpSchema for the op. | ||
op_schema: The ONNX OpSchema for the op. | ||
""" | ||
|
||
def __init__( | ||
self, opset: Opset, opname: str, opschema: Optional[onnx.defs.OpSchema] = None | ||
self, opset: Opset, opname: str, op_schema: Optional[onnx.defs.OpSchema] = None | ||
) -> None: | ||
self._opset = opset | ||
self._name = opname | ||
self._opschema = opschema | ||
if op_schema is None: | ||
self._op_schema = self.opset[self.name] | ||
else: | ||
self._op_schema = op_schema | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
self._param_schemas: Optional[tuple[ParamSchema, ...]] = None | ||
|
||
if self._op_schema is None: | ||
logging.debug( | ||
"An OpSchema was not provided for Op '%s' and " | ||
"there is not one found in opset '%s'.", | ||
self.name, | ||
self.opset, | ||
) | ||
|
||
def __call__(self, *args, **kwargs): | ||
# FIXME(after #225): Move import to the top of the file. | ||
from onnxscript import evaluator # pylint: disable=import-outside-toplevel | ||
|
||
schema = self.get_schema() | ||
schema = self.op_schema | ||
if schema is None: | ||
raise RuntimeError( | ||
f"Op '{self.name}' does not have an OpSchema and cannot be evaluated." | ||
) | ||
return evaluator.default().eval(schema, args, kwargs) | ||
|
||
def is_single_op(self) -> bool: | ||
return isinstance(self.name, str) | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
@@ -292,25 +300,19 @@ def opset(self) -> Opset: | |
return self._opset | ||
|
||
@property | ||
def opschema(self) -> Optional[onnx.defs.OpSchema]: | ||
return self._opschema | ||
|
||
def get_schema(self) -> Optional[onnx.defs.OpSchema]: | ||
"""Returns the ONNX OpSchema for this op.""" | ||
if self.opschema is not None: | ||
return self.opschema | ||
return self.opset[self.name] | ||
def op_schema(self) -> Optional[onnx.defs.OpSchema]: | ||
return self._op_schema | ||
|
||
def has_schema(self) -> bool: | ||
"""Returns True if this op has an OpSchema.""" | ||
return self.get_schema() is not None | ||
return self.op_schema is not None | ||
|
||
def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]: | ||
"""Returns the parameter schemas for this op, if it has one.""" | ||
if self._param_schemas is not None: | ||
return self._param_schemas | ||
|
||
op_schema = self.get_schema() | ||
op_schema = self.op_schema | ||
if op_schema is None: | ||
return None | ||
|
||
|
@@ -437,7 +439,7 @@ class OnnxFunction(Op): | |
function_ir: Python code parsed as an :class:`irbuilder.IRFunction`. | ||
source: Source code used to generate the function. | ||
kwargs: Additional properties used to construct a ModelProto. | ||
opschema: Generated ONNX OpSchema for this op. | ||
op_schema: Generated ONNX OpSchema for this op. | ||
""" | ||
|
||
def __init__( | ||
|
@@ -465,20 +467,20 @@ def __init__( | |
self.source = source | ||
self.kwargs = kwargs | ||
self._param_schemas: Optional[tuple[ParamSchema, ...]] = None | ||
self._opschema: Optional[onnx.defs.OpSchema] = None | ||
self._op_schema: Optional[onnx.defs.OpSchema] = None | ||
|
||
@property | ||
def opschema(self) -> Optional[onnx.defs.OpSchema]: | ||
def op_schema(self) -> Optional[onnx.defs.OpSchema]: | ||
"""Construct an OpSchema from function_ir.""" | ||
if self._opschema is not None: | ||
return self._opschema | ||
if self._op_schema is not None: | ||
return self._op_schema | ||
|
||
if not _ONNX_OP_SCHEMA_WRITABLE: | ||
return None | ||
|
||
self._opschema = op_schema_from_function_ir(self.function_ir, self.opset) | ||
self._op_schema = op_schema_from_function_ir(self.function_ir, self.opset) | ||
|
||
return self._opschema | ||
return self._op_schema | ||
|
||
def __getitem__(self, instance): | ||
"""Returns a lambda to evaluate function using given evaluator instance. | ||
|
@@ -580,19 +582,19 @@ def function_ir(self) -> irbuilder.IRFunction: | |
return converter.translate_function_signature(func_ast) | ||
|
||
@property | ||
def opschema(self) -> Optional[onnx.defs.OpSchema]: | ||
"""Return the opschema.""" | ||
def op_schema(self) -> Optional[onnx.defs.OpSchema]: | ||
"""Return the OpSchema.""" | ||
|
||
if self._opschema is not None: | ||
return self._opschema | ||
if self._op_schema is not None: | ||
return self._op_schema | ||
|
||
if not _ONNX_OP_SCHEMA_WRITABLE: | ||
return None | ||
|
||
# FIXME(justinchuby): outputs are empty. Need to fix. | ||
self._opschema = op_schema_from_function_ir(self.function_ir, self._opset) | ||
self._op_schema = op_schema_from_function_ir(self.function_ir, self._opset) | ||
|
||
return self._opschema | ||
return self._op_schema | ||
|
||
def param_schemas(self) -> tuple[ParamSchema, ...]: | ||
"""Returns the parameter schemas of this function.""" | ||
|
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.
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.
@gramalingam
name
isOptional[Union[str, List[str]]]
. Should we change this or the type?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.
Change the type to
optional[str]
... that's what translation ofNone
seems to generateThere 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.
Do you mean changing the name's type to optional[str]?
__str__
always needs to return a string. should we do something to self.name when is it None in this function?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.
I guess we could do
"" if self.name is None else self.name
. Not sure if and where this is used.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.
I will add an assert for now since it looks like we don't expect it to be None or anything other than str.
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.
Done
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.
I have a recollection that this may be used in the translation of
None
... in other words, I suspect we might be creating a ConverterExpression that has no name (that is, self.name is None). However, we likely don't invoke the str method on it. So, it's fine in that sense. (Anyway, I suspect a bigger cleanup of ConverterExpression is due at some point, so that's another reason not to bother much for now.)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.
SG!