Skip to content

Conversation

@gramalingam
Copy link
Collaborator

@gramalingam gramalingam commented Nov 15, 2025

Migrate onnxscript converter to use onnx ir.

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

codecov bot commented Nov 15, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
11830 1 11829 2253
View the top 1 failed test(s) by shortest run time
onnxscript.rewriter.ort_fusions.rms_normalization_test.TestRmsNormalization::test_smollm
Stack Traces | 8.65s run time
onnxscript\rewriter\ort_fusions\rms_normalization_test.py:19: in test_smollm
    original_outputs = ort_run("original", model, inputs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\rewriter\ort_fusions\_test_utils.py:19: in ort_run
    model_proto.SerializeToString(), options, providers=providers
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   MemoryError

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

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@titaiwangms titaiwangms changed the title Migrate onnxscript converter to use onnx ir [Do Not Merge]Migrate onnxscript converter to use onnx ir Nov 21, 2025
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@justinchuby justinchuby added this to the 0.6.0 milestone Dec 12, 2025
@gramalingam gramalingam changed the title [Do Not Merge]Migrate onnxscript converter to use onnx ir Migrate onnxscript converter to use onnx ir Dec 18, 2025
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
nparray = np.array(val)
elem_type = onnx.helper.np_dtype_to_tensor_dtype(nparray.dtype) # noqa: TID251
return ir.TensorType(elem_type), []
raise ValueError(f"Value of type {type(val)} is invalid as an ONNX input/output.")

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'type' may be used before it is initialized.

Copilot Autofix

AI 1 day ago

In general, this class of problem is fixed by ensuring that any local variable is always initialized before being read, or by removing/renaming suspicious locals so the analysis is straightforward. Here, the simplest, behavior‑preserving fix is to avoid using the name type as a local variable in value_to_type. That variable is only used as the element type for a sequence (ir.SequenceType(type)), and analogous code elsewhere uses names like elem_type. We can rename the variable to elem_type and update its single use. This does not change logic or outputs, it only clarifies intent and ensures static analysis no longer thinks there is a potentially uninitialized local.

Concretely, in onnxscript/_internal/utils.py within value_to_type, in the elif isinstance(val, list) branch, update the line type, shape = value_to_type(val[0]) to elem_type, shape = value_to_type(val[0]) and the following return ir.SequenceType(type), shape to return ir.SequenceType(elem_type), shape. No imports or additional definitions are required, and no other parts of the file need to change.

Suggested changeset 1
onnxscript/_internal/utils.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/onnxscript/_internal/utils.py b/onnxscript/_internal/utils.py
--- a/onnxscript/_internal/utils.py
+++ b/onnxscript/_internal/utils.py
@@ -104,8 +104,8 @@
         return (ir.TensorType(elem_type), shape)
     elif isinstance(val, list):
         if len(val) > 0:
-            type, shape = value_to_type(val[0])
-            return ir.SequenceType(type), shape
+            elem_type, shape = value_to_type(val[0])
+            return ir.SequenceType(elem_type), shape
         # Edge-case. Cannot determine a suitable ONNX type for an empty list.
         # Should be using a typed-value instead.
         # Treated as a sequence of tensors of float-type.
EOF
@@ -104,8 +104,8 @@
return (ir.TensorType(elem_type), shape)
elif isinstance(val, list):
if len(val) > 0:
type, shape = value_to_type(val[0])
return ir.SequenceType(type), shape
elem_type, shape = value_to_type(val[0])
return ir.SequenceType(elem_type), shape
# Edge-case. Cannot determine a suitable ONNX type for an empty list.
# Should be using a typed-value instead.
# Treated as a sequence of tensors of float-type.
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@justinchuby justinchuby merged commit 8f06364 into main Dec 19, 2025
29 of 31 checks passed
@justinchuby justinchuby deleted the rama/converter branch December 19, 2025 17:42
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.

4 participants