From 9d9fe1cfa6bcc6741783370e2174008cbc8d9ebc Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 21 Aug 2025 12:48:01 -0700 Subject: [PATCH 1/3] Default attribute type to INTS Signed-off-by: Justin Chu --- src/onnx_ir/_convenience/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/onnx_ir/_convenience/__init__.py b/src/onnx_ir/_convenience/__init__.py index 5c27a2c5..63419bc5 100644 --- a/src/onnx_ir/_convenience/__init__.py +++ b/src/onnx_ir/_convenience/__init__.py @@ -70,9 +70,11 @@ def _infer_attribute_type(attr: SupportedAttrTypes) -> _enums.AttributeType: return _enums.AttributeType.TYPE_PROTO if isinstance(attr, Sequence): if not attr: - raise ValueError( - "Cannot infer type of empty sequence. Please create an Attr with an explicit type." + logger.warning( + "Attribute type is ambiguous because it is an empty sequence. " + "Please create an Attr with an explicit type. Defaulted to INTS" ) + return _enums.AttributeType.INTS if all(isinstance(x, int) for x in attr): return _enums.AttributeType.INTS if all(isinstance(x, float) for x in attr): From ce1eb92904b4bdeeb6e65cfaaf12c35cbb341396 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 21 Aug 2025 12:51:48 -0700 Subject: [PATCH 2/3] docs Signed-off-by: Justin Chu --- src/onnx_ir/_convenience/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/onnx_ir/_convenience/__init__.py b/src/onnx_ir/_convenience/__init__.py index 63419bc5..f1296fae 100644 --- a/src/onnx_ir/_convenience/__init__.py +++ b/src/onnx_ir/_convenience/__init__.py @@ -255,15 +255,17 @@ def convert_attributes( len()=0 )]), Attr('type_proto', TYPE_PROTO, Tensor(FLOAT)), Attr('type_protos', TYPE_PROTOS, [Tensor(FLOAT), Tensor(FLOAT)])] + .. important:: + An empty sequence should be created with an + explicit type by initializing an Attr object with an attribute type. + Args: attrs: A dictionary of {: } to convert. Returns: - A list of _core.Attr objects. + A list of :class:`_core.Attr` objects. Raises: - ValueError: If an attribute is an empty sequence. It should be created with an - explicit type by initializing an Attr object with an attribute type. TypeError: If an attribute type is not supported. """ attributes: list[_core.Attr] = [] From f77808e3b24723d5f0461e445d497bd693bee163 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 21 Aug 2025 12:52:48 -0700 Subject: [PATCH 3/3] docs Signed-off-by: Justin Chu --- src/onnx_ir/_convenience/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/onnx_ir/_convenience/__init__.py b/src/onnx_ir/_convenience/__init__.py index f1296fae..7842859d 100644 --- a/src/onnx_ir/_convenience/__init__.py +++ b/src/onnx_ir/_convenience/__init__.py @@ -256,8 +256,10 @@ def convert_attributes( )]), Attr('type_proto', TYPE_PROTO, Tensor(FLOAT)), Attr('type_protos', TYPE_PROTOS, [Tensor(FLOAT), Tensor(FLOAT)])] .. important:: - An empty sequence should be created with an - explicit type by initializing an Attr object with an attribute type. + An empty sequence should be created with an explicit type by initializing + an Attr object with an attribute type to avoid type ambiguity. For example:: + + ir.Attr("empty", [], type=ir.AttributeType.INTS) Args: attrs: A dictionary of {: } to convert.