Repository navigation
[Rewriter] Adopt missing ONNX Light optimization patterns - #3167
Open
Justin Chu (justinchuby) wants to merge 1 commit into
Open
Justin Chu (justinchuby) wants to merge 1 commit into
Justin Chu (justinchuby) wants to merge 1 commit into
Conversation
Inventory all 129 registered patterns at upstream revision 43c2ac6aa6a393dfb7b90527638d0c1f22139c1e and independently implement sound missing subsets. Preserve existing rotary and attention fusion opportunities after canonicalization. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| def pattern(self, op, x0, x1, axis): | ||
| return op.Concat(x0, x1, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, axis): |
| def check(self, context, x0, x1, axis): | ||
| return super().check(context, axis, x0=x0, x1=x1) | ||
|
|
||
| def rewrite(self, op, x0, x1, axis): |
| def pattern(self, op, x0, x1, x2, axis): | ||
| return op.Concat(x0, x1, x2, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, x2, axis): |
| def check(self, context, x0, x1, x2, axis): | ||
| return super().check(context, axis, x0=x0, x1=x1, x2=x2) | ||
|
|
||
| def rewrite(self, op, x0, x1, x2, axis): |
| def pattern(self, op, x0, x1, x2, x3, axis): | ||
| return op.Concat(x0, x1, x2, x3, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, x2, x3, axis): |
Comment on lines
+1009
to
+1025
| def check( | ||
| self, | ||
| context, | ||
| x, | ||
| s0, | ||
| e0, | ||
| a0, | ||
| st0, | ||
| s1, | ||
| e1, | ||
| a1, | ||
| st1, | ||
| s2, | ||
| e2, | ||
| a2, | ||
| st2, | ||
| ): |
Comment on lines
+1038
to
+1058
| def pattern( | ||
| self, | ||
| op, | ||
| x, | ||
| s0, | ||
| e0, | ||
| a0, | ||
| st0, | ||
| s1, | ||
| e1, | ||
| a1, | ||
| st1, | ||
| s2, | ||
| e2, | ||
| a2, | ||
| st2, | ||
| s3, | ||
| e3, | ||
| a3, | ||
| st3, | ||
| ): |
Comment on lines
+1066
to
+1086
| def check( | ||
| self, | ||
| context, | ||
| x, | ||
| s0, | ||
| e0, | ||
| a0, | ||
| st0, | ||
| s1, | ||
| e1, | ||
| a1, | ||
| st1, | ||
| s2, | ||
| e2, | ||
| a2, | ||
| st2, | ||
| s3, | ||
| e3, | ||
| a3, | ||
| st3, | ||
| ): |
| cast = next(node for node in optimized.graph if node.op_type == "Cast") | ||
| assert cast.attributes["to"].as_int() == 10 | ||
| assert cast.attributes["saturate"].as_int() == 0 | ||
| del original |
| assert op_types.index("Slice") < op_types.index("Cast") | ||
| cast = next(node for node in optimized.graph if node.op_type == "Cast") | ||
| assert cast.attributes["saturate"].as_int() == 0 | ||
| del original |
| def pattern(self, op, x0, x1, axis): | ||
| return op.Concat(x0, x1, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, axis): |
| def check(self, context, x0, x1, axis): | ||
| return super().check(context, axis, x0=x0, x1=x1) | ||
|
|
||
| def rewrite(self, op, x0, x1, axis): |
| def pattern(self, op, x0, x1, x2, axis): | ||
| return op.Concat(x0, x1, x2, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, x2, axis): |
| def check(self, context, x0, x1, x2, axis): | ||
| return super().check(context, axis, x0=x0, x1=x1, x2=x2) | ||
|
|
||
| def rewrite(self, op, x0, x1, x2, axis): |
| def pattern(self, op, x0, x1, x2, x3, axis): | ||
| return op.Concat(x0, x1, x2, x3, axis=axis) | ||
|
|
||
| def check(self, context, x0, x1, x2, x3, axis): |
| def check(self, context, x0, x1, x2, x3, axis): | ||
| return super().check(context, axis, x0=x0, x1=x1, x2=x2, x3=x3) | ||
|
|
||
| def rewrite(self, op, x0, x1, x2, x3, axis): |
|
|
||
|
|
||
| class GathersSplit3(GathersSplit2): | ||
| def pattern(self, op, x, i0, i1, i2, axis0, axis1, axis2): |
| op.Gather(x, i2, axis=axis2, _check=_gather_index_checker(2)), | ||
| ) | ||
|
|
||
| def check(self, context, x, i0, i1, i2, axis0, axis1, axis2): |
|
|
||
|
|
||
| class GathersSplit4(GathersSplit2): | ||
| def pattern(self, op, x, i0, i1, i2, i3, axis0, axis1, axis2, axis3): |
| op.Gather(x, i3, axis=axis3, _check=_gather_index_checker(3)), | ||
| ) | ||
|
|
||
| def check(self, context, x, i0, i1, i2, i3, axis0, axis1, axis2, axis3): |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs/articles/onnx_light_patterns.md.Validation: full
onnxscript/rewriterandonnxscript/optimizersuites: 867 passed, 3 existing skips, 107 subtests passed.lintrunner -aandgit diff --checkclean.