Skip to content

Commit b6e9878

Browse files
Fix unicode issue (#2747)
This copilot-suggested fix enabled converting a recent onnx model to onnxscript. --------- Signed-off-by: Ganesan Ramalingam <[email protected]> Co-authored-by: Justin Chu <[email protected]>
1 parent 3690885 commit b6e9878

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

onnxscript/backend/onnx_export.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ def _translate_value_info(value_info: ValueInfoProto) -> str:
152152

153153
def _to_str(s):
154154
if isinstance(s, bytes):
155-
return s.decode("utf-8")
155+
try:
156+
return s.decode("utf-8")
157+
except UnicodeDecodeError:
158+
pass
156159
return s
157160

158161

@@ -391,8 +394,8 @@ def _translate_attributes(self, node):
391394
attributes.append((at.name, at.ref_attr_name))
392395
continue
393396
value = _attribute_value(at)
394-
if isinstance(value, str):
395-
attributes.append((at.name, f"{value!r}"))
397+
if isinstance(value, (str, bytes)):
398+
attributes.append((at.name, repr(value)))
396399
continue
397400
if isinstance(value, np.ndarray):
398401
onnx_dtype = at.t.data_type

0 commit comments

Comments
 (0)