From db863e39520dcbaa5b1181e1ac46444ef189d42a Mon Sep 17 00:00:00 2001 From: Ganesan Ramalingam Date: Fri, 26 Dec 2025 14:08:24 -0800 Subject: [PATCH 1/4] Fix unicode issue Signed-off-by: Ganesan Ramalingam --- onnxscript/backend/onnx_export.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py index 94e673be69..87e2c01ab0 100644 --- a/onnxscript/backend/onnx_export.py +++ b/onnxscript/backend/onnx_export.py @@ -152,7 +152,10 @@ def _translate_value_info(value_info: ValueInfoProto) -> str: def _to_str(s): if isinstance(s, bytes): - return s.decode("utf-8") + try: + return s.decode("utf-8") + except UnicodeDecodeError: + return s.decode("latin1") # or "cp1252" or other fallback return s From f4837c2dedb99bc9d14d60b76a4c4dd221459ac0 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Tue, 30 Dec 2025 12:27:47 -0800 Subject: [PATCH 2/4] Refactor string decoding and attribute value handling Updated string decoding logic and attribute value check. --- onnxscript/backend/onnx_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py index 87e2c01ab0..4f3f3e6aa2 100644 --- a/onnxscript/backend/onnx_export.py +++ b/onnxscript/backend/onnx_export.py @@ -155,7 +155,7 @@ def _to_str(s): try: return s.decode("utf-8") except UnicodeDecodeError: - return s.decode("latin1") # or "cp1252" or other fallback + pass return s @@ -394,7 +394,7 @@ def _translate_attributes(self, node): attributes.append((at.name, at.ref_attr_name)) continue value = _attribute_value(at) - if isinstance(value, str): + if isinstance(value, str, bytes): attributes.append((at.name, f"{value!r}")) continue if isinstance(value, np.ndarray): From 02c956888e9e0aab352bb3f68122a3e832a96fcb Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Tue, 30 Dec 2025 12:29:08 -0800 Subject: [PATCH 3/4] Apply suggestion from @justinchuby --- onnxscript/backend/onnx_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py index 4f3f3e6aa2..b9e4e92e30 100644 --- a/onnxscript/backend/onnx_export.py +++ b/onnxscript/backend/onnx_export.py @@ -395,7 +395,7 @@ def _translate_attributes(self, node): continue value = _attribute_value(at) if isinstance(value, str, bytes): - attributes.append((at.name, f"{value!r}")) + attributes.append((at.name, repr(value))) continue if isinstance(value, np.ndarray): onnx_dtype = at.t.data_type From c494888f8f33e9fb2ca27947c63ae5b211915c55 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Tue, 30 Dec 2025 20:30:58 -0800 Subject: [PATCH 4/4] Update onnx_export.py --- onnxscript/backend/onnx_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxscript/backend/onnx_export.py b/onnxscript/backend/onnx_export.py index b9e4e92e30..1c26313c0f 100644 --- a/onnxscript/backend/onnx_export.py +++ b/onnxscript/backend/onnx_export.py @@ -394,7 +394,7 @@ def _translate_attributes(self, node): attributes.append((at.name, at.ref_attr_name)) continue value = _attribute_value(at) - if isinstance(value, str, bytes): + if isinstance(value, (str, bytes)): attributes.append((at.name, repr(value))) continue if isinstance(value, np.ndarray):