Skip to content

Commit 349946c

Browse files
authored
Fix attribute handling in autocast (#2256)
In #2091, the call to helper was replaced with onnx ir attribute convertion. This was not properly handling when the attribute is a subgraph and when it uses values from the parent scope, which the ir doesn't have access to. The IR thus raises warnings of it not being able to find those values. This PR reverts the change.
1 parent 510fc28 commit 349946c

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

onnxscript/_internal/autocast.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import numpy as np
99
import onnx
10+
import onnx.helper # noqa: TID251
1011
from onnx.defs import OpSchema
1112

1213
from onnxscript import ir, tensor
@@ -68,13 +69,9 @@ def pyvalue_to_onnx_attribute(
6869
name=key, type=attr_type, t=pyvalue_to_onnx_tensor(name_generator(), value)
6970
)
7071
else:
71-
attr = ir.convenience.convert_attribute(
72-
key,
73-
value,
74-
attr_type=ir.AttributeType(attr_type) if attr_type is not None else None,
75-
)
76-
assert isinstance(attr, ir.Attr)
77-
return ir.serde.serialize_attribute(attr)
72+
# When the value is a subgraph, ONNX IR will complain that some values are
73+
# not found from the scope.
74+
return onnx.helper.make_attribute(key, value) # noqa: TID251
7875

7976

8077
# Utilities to convert python values into onnxscript tensors.

0 commit comments

Comments
 (0)