Skip to content

Update autocast.py to fix attribute creation error #2365

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 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onnxscript/_internal/autocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pyvalue_to_onnx_attribute(
key: str,
value: Any,
name_generator: Callable[[], str],
attr_type: Optional[onnx.AttributeProto.AttributeType] = None,
attr_type: onnx.AttributeProto.AttributeType | None = None,
) -> onnx.AttributeProto:
"""Helper function to create an ONNX AttributeProto.

Expand Down
6 changes: 3 additions & 3 deletions onnxscript/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def generate_unique_name(self, candidate: str = "tmp") -> str:
return r

def _make_onnx_attr(
self, attrname: str, attrval: Any, attrtype: Optional[int] = None
self, attrname: str, attrval: Any, attrtype: int | None = None
) -> irbuilder.IRAttributeValue:
def tensor_name_generator() -> str:
"""Return name to be used for tensor, if we need to create one."""
Expand Down Expand Up @@ -518,8 +518,8 @@ def _translate_attr(
if attr_meta and attr_meta.required:
self.fail(expr, f"Attribute '{attr_name}' is required.")
return None
attr_type = attr_meta.type if attr_meta else None
attr = self._make_onnx_attr(attr_name, val, attr_type)
attr_type = int(attr_meta.type) if attr_meta else None
attr = self._make_onnx_attr(attr_name, val, attrtype=attr_type)
if attr_meta and (attr.type != attr_meta.type):
self.fail(
expr,
Expand Down
2 changes: 1 addition & 1 deletion onnxscript/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def make_tensor_name() -> str:
return f"attr_{key}"

return autocast.pyvalue_to_onnx_attribute(
key, value, make_tensor_name, schema.attributes[key].type
key, value, make_tensor_name, int(schema.attributes[key].type)
)

# Construct ONNX model with a single op call:
Expand Down
Loading