Skip to content

Commit 28a24a9

Browse files
committed
Retire get_schema in Op | chore!(api)
ghstack-source-id: 771b415 Pull Request resolved: #698 Signed-off-by: Justin Chu <[email protected]>
1 parent 6c99d9a commit 28a24a9

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

onnxscript/converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(self, name: Optional[Union[str, List[str]]], kind: ConverterExpress
135135
def is_const(self):
136136
return self.kind == ConverterExpressionKind.CONST
137137

138-
def __str__(self):
138+
def __str__(self) -> str:
139139
return self.name
140140

141141

@@ -777,7 +777,7 @@ def translate_call_expr(self, node):
777777
else:
778778
args = [self.translate_opt_expr(x) for x in node.args]
779779
attrs = [self.translate_attr(x.arg, x.value) for x in node.keywords]
780-
args = autocast.static_cast_inputs(self, callee.get_schema(), *args)
780+
args = autocast.static_cast_inputs(self, callee.opschema, *args)
781781

782782
# In ONNX, there is no way to explicitly specify a None value for an attribute.
783783
# Instead, the attribute must be omitted from the attribute list.
@@ -786,7 +786,7 @@ def translate_call_expr(self, node):
786786
return callee, args, attrs
787787

788788
def _cast_like_binary_expression(self, op, left, right):
789-
schema = op.get_schema()
789+
schema = op.opschema
790790
return autocast.static_cast_inputs(self, schema, left, right)
791791

792792
def translate_bool_op_expr(self, node: ast.BoolOp) -> ConverterExpression:

onnxscript/values.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Opset:
5353
Only a single instance of Opset is created for a given (domain, version) pair.
5454
"""
5555

56+
domain: str
57+
version: int
5658
cache: dict[tuple[type, str, int], Opset] = {}
5759

5860
def __new__(cls, domain: str, version: int):
@@ -271,16 +273,13 @@ def __call__(self, *args, **kwargs):
271273
# FIXME(after #225): Move import to the top of the file.
272274
from onnxscript import evaluator # pylint: disable=import-outside-toplevel
273275

274-
schema = self.get_schema()
276+
schema = self.opschema
275277
if schema is None:
276278
raise RuntimeError(
277279
f"Op '{self.name}' does not have an OpSchema and cannot be evaluated."
278280
)
279281
return evaluator.default().eval(schema, args, kwargs)
280282

281-
def is_single_op(self) -> bool:
282-
return isinstance(self.opname, str)
283-
284283
@property
285284
def name(self) -> str:
286285
return self._name
@@ -293,22 +292,16 @@ def opset(self) -> Opset:
293292
def opschema(self) -> Optional[onnx.defs.OpSchema]:
294293
return self._opschema
295294

296-
def get_schema(self) -> Optional[onnx.defs.OpSchema]:
297-
"""Returns the ONNX OpSchema for this op."""
298-
if self.opschema is not None:
299-
return self.opschema
300-
return self.opset[self.opname]
301-
302295
def has_schema(self) -> bool:
303296
"""Returns True if this op has an OpSchema."""
304-
return self.get_schema() is not None
297+
return self.opschema is not None
305298

306299
def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]:
307300
"""Returns the parameter schemas for this op, if it has one."""
308301
if self._param_schemas is not None:
309302
return self._param_schemas
310303

311-
op_schema = self.get_schema()
304+
op_schema = self.opschema
312305
if op_schema is None:
313306
return None
314307

0 commit comments

Comments
 (0)