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

[IR] Implement replace_all_uses_with #1414

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Apr 20, 2024

Create a convenience function replace_all_uses_with to replace uses of values. Test with doctest.

Rename convenience to _convenience. We should expose some of the methods once they are proven to be useful.

Copy link

codecov bot commented Apr 20, 2024

Codecov Report

Attention: Patch coverage is 38.46154% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 76.88%. Comparing base (5a0cd8e) to head (796b46c).

Files Patch % Lines
onnxscript/ir/_convenience.py 27.27% 21 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1414      +/-   ##
==========================================
- Coverage   76.90%   76.88%   -0.03%     
==========================================
  Files         209      209              
  Lines       22406    22414       +8     
  Branches     3795     3797       +2     
==========================================
  Hits        17232    17232              
- Misses       4463     4468       +5     
- Partials      711      714       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Test Results

     28 files  ±     0      28 suites  ±0   3h 47m 28s ⏱️ - 10m 29s
  5 840 tests  -  1 281   3 955 ✅  -   950    1 877 💤  -    331   8 ❌ ± 0 
508 973 runs  +16 999  80 590 ✅ +1 372  428 350 💤 +15 612  33 ❌ +15 

For more details on these failures, see this check.

Results for commit 796b46c. ± Comparison against base commit 5a0cd8e.

This pull request removes 1282 and adds 1 tests. Note that renamed tests count towards both.
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0000_test_abs
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0001_test_acos
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0002_test_acosh
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0003_test_acosh_example
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0004_test_acos_example
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0005_test_adagrad
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0006_test_adagrad_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0007_test_adam
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0008_test_adam_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0009_test_add
…
onnxscript.ir._convenience ‑ onnxscript.ir._convenience.replace_all_uses_with

@justinchuby justinchuby added topic: IR Intermediate representation topic: rewriter labels Apr 20, 2024
from onnxscript.ir import _core, _protocols


def convert_attributes(attrs: Mapping[str, Any]) -> list[_core.Attr]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the same as the one in _tape.py ? We can presumably use this there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! I will create a follow up

replacements = (replacements,)
if len(values) != len(replacements):
raise ValueError("The number of values and replacements must match.")
for value, replacement in zip(values, replacements):
Copy link
Collaborator

Choose a reason for hiding this comment

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

A question about the IR: how is a (missing) optional output represented? Does it have a corresponding Value object or is it represented as None in the node's outputs? Wondering if we should handle the possibility of None being here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't aware that an empty output was possible, so I didn't handle them anywhere. I will create a pr to implement empty output support.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correction: an empty output is represented as a Value whose name is "". It will not have any users so we don't need to do anything about it.

@justinchuby justinchuby merged commit 669a37e into main Apr 22, 2024
36 of 43 checks passed
@justinchuby justinchuby deleted the justinchu/replace-all-uses-with branch April 22, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: IR Intermediate representation topic: rewriter
Projects
Development

Successfully merging this pull request may close these issues.

2 participants