Skip to content
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

Introduce OpSignature to IR #1838

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Introduce OpSignature to IR #1838

wants to merge 9 commits into from

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Aug 30, 2024

Introduce OpSignature accessible from the .signature property of all OpLike objects (traced function, onnx function and op). The OpSignature class leverages the IR to represent the signature of an operator, preserving ordering of all inputs and provides easy to work with type representations.

The PR also deprecates the ParamSchema class and properties.

Fixes #1697

The next PR will replace param_schemas usage.

@justinchuby justinchuby added topic: api topic: IR Intermediate representation labels Aug 30, 2024
@justinchuby justinchuby marked this pull request as draft August 30, 2024 22:59
@@ -259,7 +260,7 @@
@property
def op_schema(self) -> Optional[onnx.defs.OpSchema]: ...

def param_schemas(self) -> Optional[tuple[ParamSchema, ...]]: ...
def signature(self) -> Optional[_schemas.OpSignature]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
Copy link

codecov bot commented Aug 30, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
14189 1 14188 2656
View the top 1 failed tests by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd test_export2python_produces_correct_onnx_script_model_0043_test_argmax_keepdims_random_select_last_index
Stack Traces | 0.004s run time
onnxscript\backend\onnx_export_test.py:137: 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_argmax_keepdims_random_select_last_index'

The above exception was the direct cause of the following exception:
.nox\test\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_argmax_keepdims_random_select_last_index' (e=No module named 'tests.onnx_backend_test_code.test_argmax_keepdims_random_select_last_index') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_argmax_keepdims_random_select_last_index.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_argmax_keepdims_random_select_last_index.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
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, INT64
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_argmax_keepdims_random_select_last_index(data: FLOAT[2,3,4]) -> (INT64[2,1,4]):
E       result = opset13.ArgMax(data, axis=1, keepdims=1, select_last_index=1)
E       return result

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

onnxscript/ir/_schemas_test.py Fixed Show fixed Hide fixed
onnxscript/ir/_schemas_test.py Fixed Show fixed Hide fixed
onnxscript/values.py Fixed Show fixed Hide fixed
onnxscript/values.py Fixed Show fixed Hide fixed
Copy link

github-actions bot commented Aug 30, 2024

Test Results

     24 files  ±  0      24 suites  ±0   2h 44m 6s ⏱️ + 4m 1s
 14 152 tests + 34  11 778 ✅ + 36    2 336 💤 ±0   32 ❌  - 2   6 🔥 ±0 
355 111 runs  +238  81 240 ✅ +240  273 617 💤 ±0  212 ❌  - 2  42 🔥 ±0 

For more details on these failures and errors, see this check.

Results for commit ff1aaa5. ± Comparison against base commit fac4825.

♻️ This comment has been updated with latest results.

@justinchuby justinchuby changed the title Introduce OpSignature and deprecate ParamSchema Introduce OpSignature Oct 23, 2024
@justinchuby justinchuby changed the title Introduce OpSignature Introduce OpSignature to IR Oct 23, 2024
@justinchuby justinchuby marked this pull request as ready for review October 23, 2024 23:04
@titaiwangms titaiwangms self-assigned this Oct 23, 2024
@@ -0,0 +1,548 @@
# Copyright (c) Microsoft Corporation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put a comment saying this should align to torch _schema.py until we move it to here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we only have the test for this file, which means that torch's _schema.py should be following this one.

@justinchuby
Copy link
Collaborator Author

When the signature property is defined, PyTorch onnx exporter will not generate a new signature, and instead use what is here. However, since it is doing isinstance checks on the signature the exporter itself defines, we get isinstance errors there.

@justinchuby justinchuby added the hold on merging Don't merge yet label Oct 23, 2024
@titaiwangms titaiwangms removed their assignment Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold on merging Don't merge yet topic: api topic: IR Intermediate representation
Projects
Development

Successfully merging this pull request may close these issues.

[core] Migrate OpSignature to ONNX Script
2 participants