Skip to content

Conversation

@gramalingam
Copy link
Collaborator

This copilot-suggested fix enabled converting a recent onnx model to onnxscript.

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@codecov
Copy link

codecov bot commented Dec 26, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
685 1 684 2953
View the top 1 failed test(s) by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python
Stack Traces | 0.004s run time
onnxscript\backend\onnx_export_test.py:220: in test_export2python
    code = onnx_export.export2python(proto, rename=True, use_operators=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:919: in export2python
    return exporter.export(model_onnx, function_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:825: in export
    translated_functions.append(self._translate_graph(proto, function_name))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:736: in _translate_graph
    add(self._translate_graph_body(graph, opsets, indent=indent_level))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:381: in _translate_graph_body
    pynode = self._translate_node(node, opsets, indent=indent)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:607: in _translate_node
    attributes_str = self._translate_attributes(node)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export.py:397: in _translate_attributes
    if isinstance(value, str, bytes):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   TypeError: isinstance expected 2 arguments, got 3

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

try:
return s.decode("utf-8")
except UnicodeDecodeError:
return s.decode("latin1") # or "cp1252" or other fallback
Copy link
Collaborator

@justinchuby justinchuby Dec 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen cases where the string attributes iare used to store binary data (e.g. in the custom Tokenizer op, even though this is invalid onnx). Is this trying to address those cases? If so, I would simply preserve the b-string to avoid accidental modifications.

Related: onnx/ir-py#184

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. All I know is that this enabled me to convert a recent model (Word Fluency) into onnxscript so that I could see the control-flow structure of the model in a compact readable format. I don't mind alternatives if they allow me to do this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - that's the same model I looked at. Making a suggestion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try the current change?

Updated string decoding logic and attribute value check.
value = _attribute_value(at)
if isinstance(value, str):
attributes.append((at.name, f"{value!r}"))
if isinstance(value, str, bytes):

Check failure

Code scanning / lintrunner

PYLINT/E1121 Error

Too many positional arguments for function call (too-many-function-args)
See too-many-function-args. To disable, use # pylint: disable=too-many-function-args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants