Skip to content

Conversation

@justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Aug 27, 2025

  • Genrate opset24 from onnx 1.19
  • Minior tweaks on style to enable newer versions of the ruff linter

Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Comment on lines +1229 to +1237
def Pad(
self,
data: T_Pad,
pads: INT64,
constant_value: Optional[T_Pad] = None,
axes: Optional[Tind_Pad] = None,
*,
mode: str = "constant",
) -> T_Pad:

Check warning

Code scanning / CodeQL

Signature mismatch in overriding method Warning

This method requires at least 3 positional arguments, whereas overridden
Opset1.Pad
requires 2.
This method requires at least 3 positional arguments, whereas overridden
Opset2.Pad
requires 2.

Copilot Autofix

AI 2 months ago

To fix the signature mismatch in the overriding method, we need to ensure that Opset24.Pad accepts all the parameters that are legal for Opset23.Pad. Specifically, we should:

  • Obtain the exact signature of Pad in Opset23.
  • Edit the definition of Pad in Opset24 (beginning on line 1229) to match the parameter names, types, order, default values, and kinds (positional/keyword).
  • Ideally, the docstring should also reflect or extend the parent method's description, and type annotations should be consistent.
  • The implementation within Opset24.Pad should preserve existing functionality and call the super method as needed.

Since the only code shown is in onnxscript/onnx_opset/_impl/opset24.py, and only the signature in Opset24 is available, all changes must remain within this region. We'll:

  • Change the signature of Pad in Opset24 to match that of Opset23 (using reasonable inference).
  • If the base method accepted additional parameters, e.g., extra positional or keyword arguments (*args, **kwargs), we should add them here.
  • No new imports or dependencies are needed.

Suggested changeset 1
onnxscript/onnx_opset/_impl/opset24.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/onnx_opset/_impl/opset24.py b/onnxscript/onnx_opset/_impl/opset24.py
--- a/onnxscript/onnx_opset/_impl/opset24.py
+++ b/onnxscript/onnx_opset/_impl/opset24.py
@@ -1234,6 +1234,8 @@
         axes: Optional[Tind_Pad] = None,
         *,
         mode: str = "constant",
+        *args,
+        **kwargs,
     ) -> T_Pad:
         r"""[🌐 Pad(24)](https://onnx.ai/onnx/operators/onnx__Pad.html#pad-24 "Online Documentation")
 
EOF
@@ -1234,6 +1234,8 @@
axes: Optional[Tind_Pad] = None,
*,
mode: str = "constant",
*args,
**kwargs,
) -> T_Pad:
r"""[🌐 Pad(24)](https://onnx.ai/onnx/operators/onnx__Pad.html#pad-24 "Online Documentation")

Copilot is powered by AI and may make mistakes. Always verify output.
UINT8,
)

def Reshape(self, data: T_Reshape, shape: INT64, *, allowzero: int = 0) -> T_Reshape:

Check warning

Code scanning / CodeQL

Signature mismatch in overriding method Warning

This method requires 3 positional arguments, whereas overridden
Opset1.Reshape
requires 2.

Copilot Autofix

AI 2 months ago

To resolve a signature mismatch in an overriding method, the Reshape method in Opset24 must accept all the argument signatures accepted by the Reshape method in Opset23. The best way is to change the Reshape method of Opset24 to match exactly the signature from the base class, which likely does not use the *-based keyword-only arguments, and instead uses regular positional or optional arguments.

Steps:

  1. Verify the base method signature: Since only this file is shown, but assuming the pattern matches, the most reasonable fix is to change from the current:
    def Reshape(self, data: T_Reshape, shape: INT64, *, allowzero: int = 0) -> T_Reshape:
    to
    def Reshape(self, data: T_Reshape, shape: INT64, allowzero: int = 0) -> T_Reshape:
    i.e., make allowzero a normal (not keyword-only) parameter, accepting positional or keyword calls.
  2. Update the body accordingly: The call to the operator should remain valid.
  3. No other code or imports need changing.

Edit file:

  • onnxscript/onnx_opset/_impl/opset24.py, at the definition of Reshape (def Reshape(self, data: T_Reshape, shape: INT64, *, allowzero: int = 0)): Remove the * so that allowzero is not keyword-only and signature matches base.

Suggested changeset 1
onnxscript/onnx_opset/_impl/opset24.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/onnx_opset/_impl/opset24.py b/onnxscript/onnx_opset/_impl/opset24.py
--- a/onnxscript/onnx_opset/_impl/opset24.py
+++ b/onnxscript/onnx_opset/_impl/opset24.py
@@ -1524,7 +1524,7 @@
         UINT8,
     )
 
-    def Reshape(self, data: T_Reshape, shape: INT64, *, allowzero: int = 0) -> T_Reshape:
+    def Reshape(self, data: T_Reshape, shape: INT64, allowzero: int = 0) -> T_Reshape:
         r"""[🌐 Reshape(24)](https://onnx.ai/onnx/operators/onnx__Reshape.html#reshape-24 "Online Documentation")
 
 
EOF
@@ -1524,7 +1524,7 @@
UINT8,
)

def Reshape(self, data: T_Reshape, shape: INT64, *, allowzero: int = 0) -> T_Reshape:
def Reshape(self, data: T_Reshape, shape: INT64, allowzero: int = 0) -> T_Reshape:
r"""[🌐 Reshape(24)](https://onnx.ai/onnx/operators/onnx__Reshape.html#reshape-24 "Online Documentation")


Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +2190 to +2192
def TopK(
self, X: T_TopK, K: INT64, *, axis: int = -1, largest: int = 1, sorted: int = 1
) -> Tuple[T_TopK, I_TopK]:

Check warning

Code scanning / CodeQL

Signature mismatch in overriding method Warning

This method requires 3 positional arguments, whereas overridden
Opset1.TopK
requires 2.

Copilot Autofix

AI 2 months ago

To fix this issue, align the signature of the overriding TopK method in Opset24 with that of its predecessor in Opset23. Specifically, inspect the TopK signature in Opset23 and update Opset24.TopK to match positional and keyword arguments exactly (defaults, order, and presence). This usually means allowing the same positional arguments, keyword arguments, and *args/**kwargs if present. Make changes only in onnxscript/onnx_opset/_impl/opset24.py, in the shown region of the TopK method header.

If the only difference is the use of the * to force keyword-only parameters, remove or adjust it in the overriding method signature to match the base method. If there are extra parameters or differences in parameter names or order, adjust to match the base.

Steps:

  1. Obtain the exact signature of Opset23.TopK.
  2. Edit line 2190 of onnxscript/onnx_opset/_impl/opset24.py so Opset24.TopK has the exact same parameter list.
  3. Leave the rest of the logic unchanged.

Suggested changeset 1
onnxscript/onnx_opset/_impl/opset24.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/onnx_opset/_impl/opset24.py b/onnxscript/onnx_opset/_impl/opset24.py
--- a/onnxscript/onnx_opset/_impl/opset24.py
+++ b/onnxscript/onnx_opset/_impl/opset24.py
@@ -2188,7 +2188,7 @@
     I_TopK: TypeAlias = INT64
 
     def TopK(
-        self, X: T_TopK, K: INT64, *, axis: int = -1, largest: int = 1, sorted: int = 1
+        self, X: T_TopK, K: INT64, axis: int = -1, largest: int = 1, sorted: int = 1
     ) -> Tuple[T_TopK, I_TopK]:
         r"""[🌐 TopK(24)](https://onnx.ai/onnx/operators/onnx__TopK.html#topk-24 "Online Documentation")
 
EOF
@@ -2188,7 +2188,7 @@
I_TopK: TypeAlias = INT64

def TopK(
self, X: T_TopK, K: INT64, *, axis: int = -1, largest: int = 1, sorted: int = 1
self, X: T_TopK, K: INT64, axis: int = -1, largest: int = 1, sorted: int = 1
) -> Tuple[T_TopK, I_TopK]:
r"""[🌐 TopK(24)](https://onnx.ai/onnx/operators/onnx__TopK.html#topk-24 "Online Documentation")

Copilot is powered by AI and may make mistakes. Always verify output.
UINT8,
)

def Unsqueeze(self, data: T_Unsqueeze, axes: INT64) -> T_Unsqueeze:

Check warning

Code scanning / CodeQL

Signature mismatch in overriding method Warning

This method requires 3 positional arguments, whereas overridden
Opset1.Unsqueeze
requires 2.
This method requires 3 positional arguments, whereas overridden
Opset11.Unsqueeze
requires 2.

Copilot Autofix

AI 2 months ago

To fix this problem, we need to ensure that Opset24.Unsqueeze's method signature is compatible with the overridden base method in Opset23. Typically, this means matching all legal parameters, including optional and keyword arguments. The safest fix is to mirror the parent method's signature: if the base method specifies Unsqueeze(self, data, axes=None), then the overriding method must do likewise. Because we are only allowed to edit what we've been shown, we should update the signature of Unsqueeze in Opset24 to

def Unsqueeze(self, data: T_Unsqueeze, axes: Optional[INT64] = None) -> T_Unsqueeze:

so it will accept the same calls as any version in the base class, covering both positional and keyword usage, and remain backwards compatible.

For the internal logic, we must account for the fact that axes may be None. The call to _prepare_inputs(schema, data, axes) should be adjusted so that, if axes is None, it's not passed to _prepare_inputs, or that method can accept None. Since we are only shown this single code snippet, the best option is to ensure it works if axes is None, likely by filtering it out of the call.

Suggested changeset 1
onnxscript/onnx_opset/_impl/opset24.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/onnx_opset/_impl/opset24.py b/onnxscript/onnx_opset/_impl/opset24.py
--- a/onnxscript/onnx_opset/_impl/opset24.py
+++ b/onnxscript/onnx_opset/_impl/opset24.py
@@ -2313,7 +2313,7 @@
         UINT8,
     )
 
-    def Unsqueeze(self, data: T_Unsqueeze, axes: INT64) -> T_Unsqueeze:
+    def Unsqueeze(self, data: T_Unsqueeze, axes: Optional[INT64] = None) -> T_Unsqueeze:
         r"""[🌐 Unsqueeze(24)](https://onnx.ai/onnx/operators/onnx__Unsqueeze.html#unsqueeze-24 "Online Documentation")
 
 
@@ -2339,4 +2339,7 @@
 
         schema = get_schema("Unsqueeze", 24, "")
         op = Op(self, "Unsqueeze", schema)
-        return op(*self._prepare_inputs(schema, data, axes))
+        if axes is not None:
+            return op(*self._prepare_inputs(schema, data, axes))
+        else:
+            return op(*self._prepare_inputs(schema, data))
EOF
@@ -2313,7 +2313,7 @@
UINT8,
)

def Unsqueeze(self, data: T_Unsqueeze, axes: INT64) -> T_Unsqueeze:
def Unsqueeze(self, data: T_Unsqueeze, axes: Optional[INT64] = None) -> T_Unsqueeze:
r"""[🌐 Unsqueeze(24)](https://onnx.ai/onnx/operators/onnx__Unsqueeze.html#unsqueeze-24 "Online Documentation")


@@ -2339,4 +2339,7 @@

schema = get_schema("Unsqueeze", 24, "")
op = Op(self, "Unsqueeze", schema)
return op(*self._prepare_inputs(schema, data, axes))
if axes is not None:
return op(*self._prepare_inputs(schema, data, axes))
else:
return op(*self._prepare_inputs(schema, data))
Copilot is powered by AI and may make mistakes. Always verify output.
@codecov
Copy link

codecov bot commented Aug 27, 2025

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
9840 3 9837 3394
View the top 3 failed test(s) by shortest run time
onnxscript.converter_test.TestConverter::test_function_opset_import
Stack Traces | 0.003s run time
onnxscript/converter_test.py:703: in test_function_opset_import
    @script()
     ^^^^^^^^
onnxscript/main.py:94: in transform
    result = script_check(f_ast, opset, env, src, default_opset=default_opset)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/main.py:38: in script_check
    return convert.translate_function_def(f)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/converter.py:1452: in translate_function_def
    fn_ir = self._translate_function_def_common(stmt)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/converter.py:1439: in _translate_function_def_common
    self._translate_stmt(s, index_of_stmt=i)
onnxscript/converter.py:966: in _translate_stmt
    return self._translate_return_stmt(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/converter.py:1089: in _translate_return_stmt
    return ret(val, 0, "")
           ^^^^^^^^^^^^^^^
onnxscript/converter.py:1065: in ret
    return_var = self._translate_expr(exp, preferred_name).name
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/converter.py:546: in _translate_expr
    r = self._translate_call_expr(node)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/converter.py:832: in _translate_call_expr
    args = autocast.static_cast_inputs(self, callee.op_schema, args)
                                             ^^^^^^^^^^^^^^^^
onnxscript/values.py:527: in op_schema
    self._op_schema = _op_schema_from_function_ir(self.function_ir, self.opset)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript/values.py:435: in _op_schema_from_function_ir
    return onnx.defs.OpSchema(
E   ValueError: DataTypeUtils::FromDataTypeString - Received invalid data type string 'float8e8m0'.
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0561_test_less_equal_bcast
Stack Traces | 0.004s run time
onnxscript\backend\onnx_export_test.py:132: in extract_functions
    mod = importlib.import_module(import_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_less_equal_bcast'

The above exception was the direct cause of the following exception:
.nox\test_onnx_ir_git\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export_test.py:266: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export_test.py:134: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_less_equal_bcast' (e=No module named 'tests.onnx_backend_test_code.test_less_equal_bcast') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_less_equal_bcast.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_less_equal_bcast.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy as np
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import BOOL, FLOAT
E   from onnxscript.onnx_opset import opset16
E   
E   @script()
E   def bck_test_less_equal_bcast(x: FLOAT[3,4,5], y: FLOAT[5]) -> (BOOL[3,4,5]):
E       less_equal = opset16.LessOrEqual(x, y)
E       return less_equal
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0265_test_concat_2d_axis_0
Stack Traces | 0.005s run time
onnxscript\backend\onnx_export_test.py:132: in extract_functions
    mod = importlib.import_module(import_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_concat_2d_axis_0'

The above exception was the direct cause of the following exception:
.nox\test_onnx_ir_git\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export_test.py:266: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxscript\backend\onnx_export_test.py:134: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_concat_2d_axis_0' (e=No module named 'tests.onnx_backend_test_code.test_concat_2d_axis_0') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_concat_2d_axis_0.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_concat_2d_axis_0.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy as np
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_concat_2d_axis_0(value0: FLOAT[2,2], value1: FLOAT[2,2]) -> (FLOAT[4,2]):
E       output = opset13.Concat(value0, value1, axis=0)
E       return output

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: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby enabled auto-merge (squash) August 27, 2025 22:25
@justinchuby justinchuby merged commit 1a7f3bd into main Aug 28, 2025
21 of 32 checks passed
@justinchuby justinchuby deleted the justinchu/opset24 branch August 28, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants