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

Cleanup new-IR based constant propagation #1739

Merged
merged 7 commits into from
Jul 24, 2024
Merged

Cleanup new-IR based constant propagation #1739

merged 7 commits into from
Jul 24, 2024

Conversation

gramalingam
Copy link
Collaborator

Factor out some common logic between rewriter and constant-propagation into a utility function, and other minor cleanup.

onnxscript/optimizer/_constant_folding.py Fixed Show fixed Hide fixed
onnxscript/optimizer/_constant_folding.py Fixed Show fixed Hide fixed
onnxscript/rewriter/pattern.py Fixed Show fixed Hide fixed
onnxscript/rewriter/pattern.py Fixed Show fixed Hide fixed
onnxscript/rewriter/pattern.py Fixed Show fixed Hide fixed
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.95%. Comparing base (c37e98b) to head (324300a).

Files Patch % Lines
onnxscript/optimizer/_constant_folding.py 55.55% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1739      +/-   ##
==========================================
- Coverage   74.98%   74.95%   -0.04%     
==========================================
  Files         245      245              
  Lines       26393    26384       -9     
  Branches     4804     4803       -1     
==========================================
- Hits        19792    19777      -15     
- Misses       5679     5684       +5     
- Partials      922      923       +1     

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

Copy link

github-actions bot commented Jul 19, 2024

Test Results

     24 files  ±     0      24 suites  ±0   3h 16m 37s ⏱️ + 10m 31s
 13 387 tests  -  3 625  11 819 ✅  - 3 185    1 538 💤  -    433   30 ❌  - 7 
477 208 runs  +17 846  99 962 ✅ +2 631  376 978 💤 +15 222  268 ❌  - 7 

For more details on these failures, see this check.

Results for commit 324300a. ± Comparison against base commit c37e98b.

This pull request removes 3625 tests.
onnxscript._internal.analysis_test.TestAssignedVarAnalysis ‑ test_basic_defs
onnxscript._internal.analysis_test.TestAssignedVarAnalysis ‑ test_doc_string
onnxscript._internal.analysis_test.TestAssignedVarAnalysis ‑ test_if_defs
onnxscript._internal.analysis_test.TestAssignedVarAnalysis ‑ test_if_loop_defs
onnxscript._internal.analysis_test.TestAssignedVarAnalysis ‑ test_loop_defs
onnxscript._internal.analysis_test.TestExposedUses ‑ test_basic
onnxscript._internal.analysis_test.TestExposedUses ‑ test_called_function
onnxscript._internal.analysis_test.TestExposedUses ‑ test_doc_string
onnxscript._internal.analysis_test.TestExposedUses ‑ test_for_loop
onnxscript._internal.analysis_test.TestExposedUses ‑ test_if
…

♻️ This comment has been updated with latest results.



def replace_nodes_and_values(
graph_or_function: _core.Graph | _core.Function,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
graph_or_function: _core.Graph | _core.Function,
graph_or_function: _core.Graph | _core.Function,
/,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done (but not pushed yet). But is there a specific principle being used here, to distinguish between the two classes of parameters? Except for the name, which is admittedly not great (we could do with a better alternative to graph_or_function ... how does container sound? or graph_like ?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like graph_like!

is there a specific principle being used here, to distinguish between the two classes of parameters

not sure what you mean? could you say 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.

I mean, why do you prefer that graph_or_function be positional, while the others are allowed to be positional or by keyword?

Copy link
Collaborator

Choose a reason for hiding this comment

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

allowing graph_or_function by keyword can restrict our ability to change the name of the variable (which we have done: graph -> graph_or_function); but other options have more stable names.

@@ -395,3 +395,44 @@ def create_value_mapping(graph: _core.Graph) -> dict[str, _core.Value]:
continue
values[value.name] = value
return values


def replace_nodes_and_values(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Helpful to have a test?

old_values: list[_core.Value],
new_values: list[_core.Value],
):
"""Replaces nodes and values in the graph or function.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Helpful to describe the invariance this function maintains?

@justinchuby
Copy link
Collaborator

justinchuby commented Jul 24, 2024

Is there a way to copy the metadata_props from old nodes as well, to preserve namespace and source information?

@gramalingam gramalingam merged commit 712aa87 into main Jul 24, 2024
33 of 43 checks passed
@gramalingam gramalingam deleted the rama/cp_cleanup branch July 24, 2024 15:09
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.

2 participants