-
Notifications
You must be signed in to change notification settings - Fork 96
Migrate onnxscript converter to use onnx ir #2706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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>
| 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
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified lines R107-R108
| @@ -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. |
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Migrate onnxscript converter to use onnx ir.