@@ -339,22 +339,20 @@ def tensor_name_generator() -> str:
339339 def _to_onnx_attr_ref (
340340 self , val : values .AttrRef , info : Optional [sourceinfo .SourceInfo ]
341341 ) -> ir .Attr :
342- pytype = val .typeinfo
343- attrtype = ta .pytype_to_attrtype (pytype )
342+ attrtype = val .value .type
344343 attrname = None
345- if attrtype is onnx .AttributeProto .FLOAT :
344+ if attrtype is ir . AttributeType . FLOAT : # onnx.AttributeProto.FLOAT:
346345 attrname = "value_float"
347- elif attrtype is onnx . AttributeProto .INT :
346+ elif attrtype is ir . AttributeType .INT :
348347 attrname = "value_int"
349- elif attrtype is onnx . AttributeProto .STRING :
348+ elif attrtype is ir . AttributeType .STRING :
350349 attrname = "value_string"
351- elif attrtype is onnx . AttributeProto .INTS :
350+ elif attrtype is ir . AttributeType .INTS :
352351 attrname = "value_ints"
353352 else :
354- msg = f"Unsupported attribute type { pytype !r} ."
353+ msg = f"Unsupported attribute type { attrtype !r} ."
355354 fail (info .msg (msg ) if info else msg )
356- attr_type = ir .AttributeType (ta .pytype_to_attrtype (pytype ))
357- return ir .Attr (attrname , attr_type , value = None , ref_attr_name = val .value .name )
355+ return ir .Attr (attrname , attrtype , value = None , ref_attr_name = val .value .name )
358356
359357 def _to_onnx_var (
360358 self ,
@@ -369,7 +367,7 @@ def _to_onnx_var(
369367 result = self .emit (
370368 [result_name ], values .Op (self .default_opset , "Constant" ), [], [attr ]
371369 )
372- if ta . base_type_is_bool ( val .typeinfo ) :
370+ if val .as_bool :
373371 # ONNX attributes use an int-encoding for bools, but ONNX tensor types
374372 # distinguish between int and bool. So we cast the int tensor to a bool tensor,
375373 # to promote a (python) bool attribute to a ONNX bool tensor.
@@ -1474,7 +1472,8 @@ def _translate_function_signature_common(
14741472 attribute_type = ta .pytype_to_attrtype (typeinfo )
14751473 attr = ir .Attr (x .arg , ir .AttributeType (attribute_type ), default_value , None )
14761474 self ._current_fn .append_parameter (attr )
1477- self ._bind (x .arg , values .AttrRef (attr , typeinfo , self ._source_of (x )))
1475+ as_bool = ta .base_type_is_bool (typeinfo )
1476+ self ._bind (x .arg , values .AttrRef (attr , as_bool , self ._source_of (x )))
14781477 else :
14791478 onnx_parameter = make_value (x .arg , typeinfo , self ._source_of (x ))
14801479 self ._current_fn .append_parameter (onnx_parameter )
0 commit comments