Skip to content

[IR] Support specifying output value in Tape #2225

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

Merged
merged 6 commits into from
Apr 29, 2025
Merged

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Apr 24, 2025

When a user wants to specify names for output values, they can initialize the value first then supply them to tape op() call.

Also renamed symbolic_multi_output to symblic_multi_out to match https://pytorch.org/docs/main/onnx_ops.html#torch.onnx.ops.symbolic_multi_out

When a user wants to specify names for output values, they can initialize the value first then supply them to tape op() call.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for specifying output values in Tape operations by allowing users to initialize and supply output values explicitly.

  • Added an optional output parameter to op() to allow a single output value specification.
  • Extended op_multi_output() with optional outputs in addition to num_outputs, with validation to ensure at least one is provided.

Copy link

codecov bot commented Apr 24, 2025

❌ 17 Tests Failed:

Tests completed Failed Passed Skipped
14452 17 14435 1881
View the top 3 failed test(s) by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_1282_test_xor4d
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\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_xor4d'

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_xor4d' (e=No module named 'tests.onnx_backend_test_code.test_xor4d') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_xor4d.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_xor4d.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 BOOL
E   from onnxscript.onnx_opset import opset7
E   
E   @script()
E   def bck_test_xor4d(x: BOOL[3,4,5,6], y: BOOL[3,4,5,6]) -> (BOOL[3,4,5,6]):
E       xor = opset7.Xor(x, y)
E       return xor
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0125_test_bitwise_or_i32_2d
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.10.11\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_bitwise_or_i32_2d'

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_bitwise_or_i32_2d' (e=No module named 'tests.onnx_backend_test_code.test_bitwise_or_i32_2d') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_bitwise_or_i32_2d.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_bitwise_or_i32_2d.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 INT32
E   from onnxscript.onnx_opset import opset18
E   
E   @script()
E   def bck_test_bitwise_or_i32_2d(x: INT32[3,4], y: INT32[3,4]) -> (INT32[3,4]):
E       bitwiseor = opset18.BitwiseOr(x, y)
E       return bitwiseor
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0139_test_castlike_DOUBLE_to_FLOAT16
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.10.11\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_castlike_DOUBLE_to_FLOAT16'

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_castlike_DOUBLE_to_FLOAT16' (e=No module named 'tests.onnx_backend_test_code.test_castlike_DOUBLE_to_FLOAT16') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_castlike_DOUBLE_to_FLOAT16.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_castlike_DOUBLE_to_FLOAT16.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 DOUBLE, FLOAT16
E   from onnxscript.onnx_opset import opset21
E   
E   @script()
E   def bck_test_castlike_DOUBLE_to_FLOAT16(input: DOUBLE[3,4], like: FLOAT16[1]) -> (FLOAT16[3,4]):
E       output = opset21.CastLike(input, like)
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.

@justinchuby justinchuby requested a review from titaiwangms April 25, 2025 14:36
Copy link
Collaborator

@gramalingam gramalingam left a comment

Choose a reason for hiding this comment

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

Are there any examples/documentation illustrating the creation of output value and then using it to create an op?

@justinchuby justinchuby marked this pull request as draft April 29, 2025 15:42
@justinchuby
Copy link
Collaborator Author

Are there any examples/documentation illustrating the creation of output value and then using it to create an op?

Will create as a follow up, thanks!

@justinchuby justinchuby marked this pull request as ready for review April 29, 2025 15:48
@justinchuby justinchuby enabled auto-merge (squash) April 29, 2025 15:48
@justinchuby justinchuby merged commit 02cf905 into main Apr 29, 2025
26 of 30 checks passed
@justinchuby justinchuby deleted the justinchu/tape-output branch April 29, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: IR Intermediate representation
Projects
Development

Successfully merging this pull request may close these issues.

3 participants