@@ -243,7 +243,7 @@ def opset(self) -> Opset:
243
243
...
244
244
245
245
@property
246
- def opschema (self ) -> Optional [onnx .defs .OpSchema ]:
246
+ def op_schema (self ) -> Optional [onnx .defs .OpSchema ]:
247
247
...
248
248
249
249
def param_schemas (self ) -> Optional [tuple [ParamSchema , ...]]:
@@ -258,31 +258,36 @@ class Op(OpLike):
258
258
Attributes:
259
259
opset: The Opset that this op belongs to.
260
260
name: The name of the op.
261
- opschema : The ONNX OpSchema for the op.
261
+ op_schema : The ONNX OpSchema for the op.
262
262
"""
263
263
264
264
def __init__ (
265
- self , opset : Opset , opname : str , opschema : Optional [onnx .defs .OpSchema ] = None
265
+ self , opset : Opset , opname : str , op_schema : Optional [onnx .defs .OpSchema ] = None
266
266
) -> None :
267
267
self ._opset = opset
268
268
self ._name = opname
269
- self ._opschema = opschema
269
+ self ._op_schema = op_schema or opset [ opname ]
270
270
self ._param_schemas : Optional [tuple [ParamSchema , ...]] = None
271
271
272
+ if self ._op_schema is None :
273
+ logging .debug (
274
+ "An OpSchema was not provided for Op '%s' and "
275
+ "there is not one found in opset '%s'." ,
276
+ opname ,
277
+ opset ,
278
+ )
279
+
272
280
def __call__ (self , * args , ** kwargs ):
273
281
# FIXME(after #225): Move import to the top of the file.
274
282
from onnxscript import evaluator # pylint: disable=import-outside-toplevel
275
283
276
- schema = self .get_schema ()
284
+ schema = self .op_schema
277
285
if schema is None :
278
286
raise RuntimeError (
279
287
f"Op '{ self .name } ' does not have an OpSchema and cannot be evaluated."
280
288
)
281
289
return evaluator .default ().eval (schema , args , kwargs )
282
290
283
- def is_single_op (self ) -> bool :
284
- return isinstance (self .name , str )
285
-
286
291
@property
287
292
def name (self ) -> str :
288
293
return self ._name
@@ -292,25 +297,19 @@ def opset(self) -> Opset:
292
297
return self ._opset
293
298
294
299
@property
295
- def opschema (self ) -> Optional [onnx .defs .OpSchema ]:
296
- return self ._opschema
297
-
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 ]
300
+ def op_schema (self ) -> Optional [onnx .defs .OpSchema ]:
301
+ return self ._op_schema
303
302
304
303
def has_schema (self ) -> bool :
305
304
"""Returns True if this op has an OpSchema."""
306
- return self .get_schema () is not None
305
+ return self .op_schema is not None
307
306
308
307
def param_schemas (self ) -> Optional [tuple [ParamSchema , ...]]:
309
308
"""Returns the parameter schemas for this op, if it has one."""
310
309
if self ._param_schemas is not None :
311
310
return self ._param_schemas
312
311
313
- op_schema = self .get_schema ()
312
+ op_schema = self .op_schema
314
313
if op_schema is None :
315
314
return None
316
315
@@ -437,7 +436,7 @@ class OnnxFunction(Op):
437
436
function_ir: Python code parsed as an :class:`irbuilder.IRFunction`.
438
437
source: Source code used to generate the function.
439
438
kwargs: Additional properties used to construct a ModelProto.
440
- opschema : Generated ONNX OpSchema for this op.
439
+ op_schema : Generated ONNX OpSchema for this op.
441
440
"""
442
441
443
442
def __init__ (
@@ -465,20 +464,20 @@ def __init__(
465
464
self .source = source
466
465
self .kwargs = kwargs
467
466
self ._param_schemas : Optional [tuple [ParamSchema , ...]] = None
468
- self ._opschema : Optional [onnx .defs .OpSchema ] = None
467
+ self ._op_schema : Optional [onnx .defs .OpSchema ] = None
469
468
470
469
@property
471
- def opschema (self ) -> Optional [onnx .defs .OpSchema ]:
470
+ def op_schema (self ) -> Optional [onnx .defs .OpSchema ]:
472
471
"""Construct an OpSchema from function_ir."""
473
- if self ._opschema is not None :
474
- return self ._opschema
472
+ if self ._op_schema is not None :
473
+ return self ._op_schema
475
474
476
475
if not _ONNX_OP_SCHEMA_WRITABLE :
477
476
return None
478
477
479
- self ._opschema = op_schema_from_function_ir (self .function_ir , self .opset )
478
+ self ._op_schema = op_schema_from_function_ir (self .function_ir , self .opset )
480
479
481
- return self ._opschema
480
+ return self ._op_schema
482
481
483
482
def __getitem__ (self , instance ):
484
483
"""Returns a lambda to evaluate function using given evaluator instance.
@@ -555,11 +554,6 @@ def __call__(self, *args, **kwargs):
555
554
def __repr__ (self ):
556
555
return f"{ self .__class__ .__name__ } ({ self .func !r} )"
557
556
558
- @property
559
- def name (self ) -> str :
560
- """Return the name of the op."""
561
- return self .func .__name__
562
-
563
557
@property
564
558
def function_ir (self ) -> irbuilder .IRFunction :
565
559
"""Return the function_ir.
@@ -580,19 +574,19 @@ def function_ir(self) -> irbuilder.IRFunction:
580
574
return converter .translate_function_signature (func_ast )
581
575
582
576
@property
583
- def opschema (self ) -> Optional [onnx .defs .OpSchema ]:
584
- """Return the opschema ."""
577
+ def op_schema (self ) -> Optional [onnx .defs .OpSchema ]:
578
+ """Return the OpSchema ."""
585
579
586
- if self ._opschema is not None :
587
- return self ._opschema
580
+ if self ._op_schema is not None :
581
+ return self ._op_schema
588
582
589
583
if not _ONNX_OP_SCHEMA_WRITABLE :
590
584
return None
591
585
592
586
# FIXME(justinchuby): outputs are empty. Need to fix.
593
- self ._opschema = op_schema_from_function_ir (self .function_ir , self ._opset )
587
+ self ._op_schema = op_schema_from_function_ir (self .function_ir , self ._opset )
594
588
595
- return self ._opschema
589
+ return self ._op_schema
596
590
597
591
def param_schemas (self ) -> tuple [ParamSchema , ...]:
598
592
"""Returns the parameter schemas of this function."""
0 commit comments