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 apply_deltas #1464

Merged
merged 13 commits into from
Apr 26, 2024
Merged

Cleanup apply_deltas #1464

merged 13 commits into from
Apr 26, 2024

Conversation

gramalingam
Copy link
Collaborator

@gramalingam gramalingam commented Apr 26, 2024

Next step in cleanup of pattern-matcher:

  • Each rewrite-transformation is applied immediately when it is identified (since the IR now allows us to do this).
  • Eliminate the extra checks to avoid overlapping matches (because of above)
  • Use a structured representation of the delta
  • Enable function constructing the replacement to return None (failure of rewrite)
  • Cleanup MatchResult
  • Other naming cleanup

TODO:

  • Consider extending delta representation to capture old/new output-values

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

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

Project coverage is 76.97%. Comparing base (997beb2) to head (dd29020).

Files Patch % Lines
onnxscript/rewriter/pattern.py 88.23% 3 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1464      +/-   ##
==========================================
- Coverage   77.00%   76.97%   -0.03%     
==========================================
  Files         209      209              
  Lines       22440    22421      -19     
  Branches     3807     3802       -5     
==========================================
- Hits        17279    17259      -20     
+ Misses       4444     4443       -1     
- Partials      717      719       +2     

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

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

github-actions bot commented Apr 26, 2024

Test Results

     28 files  ±     0      28 suites  ±0   2h 39m 51s ⏱️ - 10m 29s
  5 881 tests + 2 022   3 994 ✅ +1 617    1 878 💤 +   403    9 ❌ + 2 
492 506 runs   - 33 786  79 290 ✅  - 2 716  413 115 💤  - 31 058  101 ❌  - 12 

For more details on these failures, see this check.

Results for commit 5543eb9. ± Comparison against base commit 997beb2.

This pull request removes 4 and adds 2026 tests. Note that renamed tests count towards both.
tests.ir.serde_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_01_torchscript_model_onnx
tests.ir.serde_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_02_mobilenetv2_100_dynamo_onnx
tests.ir.serde_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_03_resnet18_dynamo_onnx
tests.ir.serde_test.SerdeTest ‑ test_serialization_deserialization_produces_same_model_04_Speech2Text2ForCausalLM_dynamo_onnx
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.

Copy link
Contributor

@titaiwangms titaiwangms left a comment

Choose a reason for hiding this comment

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

LG with non-blocking comments

onnxscript/rewriter/pattern.py Outdated Show resolved Hide resolved
@@ -467,7 +462,7 @@ def matches_node(self, node: ir.Node, model: ir.Model) -> MatchResult:
return MatchResult.FAIL()
if not self.op.matches(node.op_type):
return MatchResult.FAIL()
match = MatchResult([])
match = MatchResult(success=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the usage is to assume it's a success in the begining, should we set a default to MatchResult?

def values(self) -> Sequence[Any] | None:
return self.matched_values
def nodes(self) -> Sequence[ir.Node]:
return self.matched_nodes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it mean match_nodes can be private?


def extend(self, other: MatchResult | bool):
if not self.success:
return
if not other:
self.fail()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious how fail() was designed and what are the thoughts for setting a boolean state instead? Just for my learning. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No deep thought here. Not sure about your question, I am not altering the behavior/approach here, merely inlining the definition of fail(). On second thoughts, retaining the method might be useful ... let me think, anyway, there's more to come, since I'd like to merge this with Xavier's MatchResult definition eventually.

Comment on lines +912 to +920
# Propagate relevant info from old value to new value
# TODO(Rama): Perhaps we should merge old and new types. As of now, new
# values don't have type information. Note that this could be a problem
# for semantics-altering rewrite-rules: we should allow users to override
# this for such rules.
new_value.type = old_value.type
new_value.shape = old_value.shape
new_value.const_value = old_value.const_value
new_value.name = old_value.name
Copy link
Collaborator

@justinchuby justinchuby Apr 26, 2024

Choose a reason for hiding this comment

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

Should we extract this as a helper for now?

onnxscript/rewriter/pattern.py Fixed Show fixed Hide fixed
onnxscript/rewriter/pattern.py Fixed Show fixed Hide fixed
@gramalingam gramalingam merged commit 8dba367 into main Apr 26, 2024
29 of 41 checks passed
@gramalingam gramalingam deleted the rama/apply-deltas branch April 26, 2024 20:49
justinchuby added a commit that referenced this pull request May 1, 2024
Next step in cleanup of pattern-matcher:

* Each rewrite-transformation is applied immediately when it is
identified (since the IR now allows us to do this).
* Eliminate the extra checks to avoid overlapping matches (because of
above)
* Use a structured representation of the delta
* Enable function constructing the replacement to return None (failure
of rewrite)
* Cleanup MatchResult
* Other naming cleanup

TODO:
* Consider extending delta representation to capture old/new
output-values

---------

Co-authored-by: Ti-Tai Wang <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
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.

3 participants