Skip to content

Commit dcb773f

Browse files
authored
Update autocast.py to fix attribute creation error (#2365)
This change should fix the type of errors like below (reported in pytorch/pytorch#153214 (comment)):
1 parent 5293005 commit dcb773f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

onnxscript/_internal/autocast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def pyvalue_to_onnx_attribute(
4545
key: str,
4646
value: Any,
4747
name_generator: Callable[[], str],
48-
attr_type: Optional[onnx.AttributeProto.AttributeType] = None,
48+
attr_type: onnx.AttributeProto.AttributeType | None = None,
4949
) -> onnx.AttributeProto:
5050
"""Helper function to create an ONNX AttributeProto.
5151

onnxscript/converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def generate_unique_name(self, candidate: str = "tmp") -> str:
298298
return r
299299

300300
def _make_onnx_attr(
301-
self, attrname: str, attrval: Any, attrtype: Optional[int] = None
301+
self, attrname: str, attrval: Any, attrtype: int | None = None
302302
) -> irbuilder.IRAttributeValue:
303303
def tensor_name_generator() -> str:
304304
"""Return name to be used for tensor, if we need to create one."""
@@ -518,8 +518,8 @@ def _translate_attr(
518518
if attr_meta and attr_meta.required:
519519
self.fail(expr, f"Attribute '{attr_name}' is required.")
520520
return None
521-
attr_type = attr_meta.type if attr_meta else None
522-
attr = self._make_onnx_attr(attr_name, val, attr_type)
521+
attr_type = int(attr_meta.type) if attr_meta else None
522+
attr = self._make_onnx_attr(attr_name, val, attrtype=attr_type)
523523
if attr_meta and (attr.type != attr_meta.type):
524524
self.fail(
525525
expr,

onnxscript/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def make_tensor_name() -> str:
420420
return f"attr_{key}"
421421

422422
return autocast.pyvalue_to_onnx_attribute(
423-
key, value, make_tensor_name, schema.attributes[key].type
423+
key, value, make_tensor_name, int(schema.attributes[key].type)
424424
)
425425

426426
# Construct ONNX model with a single op call:

0 commit comments

Comments
 (0)