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

Unify the two pattern-matchers #1495

Merged
merged 5 commits into from
May 3, 2024
Merged

Unify the two pattern-matchers #1495

merged 5 commits into from
May 3, 2024

Conversation

gramalingam
Copy link
Collaborator

Update generic pattern matcher to support the unified API.

  • Update generic_pattern_test cases to use unified API.
  • Update the generic_pattern implementation.

Still todo:

  • generic_pattern doesn't support attributes yet
  • pattern hasn't been updated yet to support extra first-parameter for pattern-builder and checker-function
  • unify PatternMatchResult and MatchResult
  • More redundancies to be eliminated between the two matchers. Eg., generic-pattern doesn't yet update opset-imports (unlike pattern)

Comment on lines +651 to +656
# if replacement is not None:
# TODO(Rama)
# assert len(replacement.new_outputs) == len(match_result.pattern_outputs), (
# f"Not the same number of outputs, matched "
# f"outputs={match_result.pattern_outputs}, "
# f"got {replacement.new_outputs} in the applied pattern."

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Comment on lines +439 to +442
# def transpose_transpose_pattern(op, X, perm0, perm1):
# xt = op.Transpose(X, perm=perm0)
# Y = op.Transpose(xt, perm=perm1)
# return Y

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Copy link

codecov bot commented May 3, 2024

Codecov Report

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

Project coverage is 76.82%. Comparing base (a1e46e4) to head (fd7731b).

Files Patch % Lines
onnxscript/rewriter/generic_pattern_test.py 86.84% 5 Missing and 5 partials ⚠️
onnxscript/rewriter/generic_pattern.py 85.71% 4 Missing and 3 partials ⚠️
onnxscript/rewriter/pattern.py 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1495      +/-   ##
==========================================
- Coverage   76.87%   76.82%   -0.05%     
==========================================
  Files         207      207              
  Lines       22345    22271      -74     
  Branches     3798     3775      -23     
==========================================
- Hits        17177    17110      -67     
+ Misses       4443     4440       -3     
+ Partials      725      721       -4     

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

Copy link

github-actions bot commented May 3, 2024

Test Results

     30 files  ±     0      30 suites  ±0   3h 12m 40s ⏱️ + 4m 17s
  3 904 tests  -  2 027   2 422 ✅  - 1 619    1 479 💤  -    407   3 ❌  - 1 
564 362 runs  +16 787  88 062 ✅ +1 360  476 243 💤 +15 428  57 ❌  - 1 

For more details on these failures, see this check.

Results for commit fd7731b. ± Comparison against base commit a1e46e4.

This pull request removes 2027 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.

@@ -46,7 +42,7 @@ def __init__(
self.pattern_outputs = pattern_outputs
self.kwargs: dict[str, Any] = {}

matched_pattern_to_model_value: dict[ir.Value, ir.Value] = {}
matched_pattern_to_model_value: dict[str, ir.Value] = {}
Copy link
Collaborator

@justinchuby justinchuby May 3, 2024

Choose a reason for hiding this comment

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

Is it possible when the name is None, or if the names of two values collide?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question. For now, there is an assert. May be better to make it conditional update to map. Eventually, this should be replaced by the pattern IR (instead of onnx IR).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the end, we care about binding only users want, for which they will give a name


# There should be a better way.
sig = inspect.signature(match_pattern_function)
for i, p in enumerate(sig.parameters.values()):
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
for i, p in enumerate(sig.parameters.values()):
for i, parameter in enumerate(sig.parameters.values()):

@titaiwangms titaiwangms requested a review from xadupre May 3, 2024 16:43
if isinstance(outputs, Sequence):
value.name = outputs[0]
return value
values = self._tape.op_multi_output(
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Do we have multi-outputs with pattern.py now? If so, should we remove generic_pattern.py to avoid the potential confusion that users might have?

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. This is different (it's about creating nodes with multiple outputs).

@gramalingam gramalingam merged commit e0a7c9a into main May 3, 2024
34 of 43 checks passed
@gramalingam gramalingam deleted the rama/unify branch May 3, 2024 17:37
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