Skip to content

Commit d7140fb

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

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-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: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,13 @@ def __call__(self, *args, **kwargs):
273273
# FIXME(after #225): Move import to the top of the file.
274274
from onnxscript import evaluator # pylint: disable=import-outside-toplevel
275275

276-
schema = self.get_schema()
276+
schema = self.opschema
277277
if schema is None:
278278
raise RuntimeError(
279279
f"Op '{self.name}' does not have an OpSchema and cannot be evaluated."
280280
)
281281
return evaluator.default().eval(schema, args, kwargs)
282282

283-
def is_single_op(self) -> bool:
284-
return isinstance(self.name, str)
285-
286283
@property
287284
def name(self) -> str:
288285
return self._name
@@ -295,22 +292,16 @@ def opset(self) -> Opset:
295292
def opschema(self) -> Optional[onnx.defs.OpSchema]:
296293
return self._opschema
297294

298-
def get_schema(self) -> Optional[onnx.defs.OpSchema]:
299-
"""Returns the ONNX OpSchema for this op."""
300-
if self.opschema is not None:
301-
return self.opschema
302-
return self.opset[self.name]
303-
304295
def has_schema(self) -> bool:
305296
"""Returns True if this op has an OpSchema."""
306-
return self.get_schema() is not None
297+
return self.opschema is not None
307298

308299
def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]:
309300
"""Returns the parameter schemas for this op, if it has one."""
310301
if self._param_schemas is not None:
311302
return self._param_schemas
312303

313-
op_schema = self.get_schema()
304+
op_schema = self.opschema
314305
if op_schema is None:
315306
return None
316307

0 commit comments

Comments
 (0)