Skip to content

Conversation

@masahi
Copy link
Member

@masahi masahi commented Mar 15, 2023

Currently, dataflow pattern matching in Relax only supports matching with boolean result and doesn't support rewriting matched expressions. This PR adds such utility following the Relay counterpart below (with a simpler API).

def rewrite(callbacks, expr: Expr, mod: Optional[_ir.IRModule] = None) -> Expr:

This is useful for, for example, rewriting a sequence of matmul -> softmax -> matmul into an attention op introduced in #14150.

@cyx-6 @sunggg @vinx13 @yelite @MasterJH5574 @spectrometerHBH @ganler

@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 15, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@masahi masahi force-pushed the pattern-rewriting branch from 9514dc9 to a9a6885 Compare March 15, 2023 19:47
Copy link
Contributor

@ganler ganler left a comment

Choose a reason for hiding this comment

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

LGTM. Just small comments on documentation improvements.

@ganler
Copy link
Contributor

ganler commented Mar 15, 2023

Thanks for providing more examples and documentation. It looks great now!

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

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

Really useful tools, thanks @masahi

Copy link
Contributor

@sunggg sunggg left a comment

Choose a reason for hiding this comment

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

Thank you so much for filling the missing piece!
LGTM.
One question. What happens if we try to rewrite to something invalid?

@masahi
Copy link
Member Author

masahi commented Mar 16, 2023

One question. What happens if we try to rewrite to something invalid?

Well, you'd just get an error somewhere, as with any other ExprMutator passes.

@masahi masahi merged commit cb6efae into apache:unity Mar 16, 2023
tqchen pushed a commit that referenced this pull request Mar 20, 2023
* stub

* wip

* works

* restore binding

* attention test work

* use RemoveAllUnused

* simplified callback api

* pass original call node to callback

* clean test

* add doc

* add test for the case where the original call is returned

* callback -> rewriter and other doc improvement
tqchen pushed a commit that referenced this pull request Apr 1, 2023
* stub

* wip

* works

* restore binding

* attention test work

* use RemoveAllUnused

* simplified callback api

* pass original call node to callback

* clean test

* add doc

* add test for the case where the original call is returned

* callback -> rewriter and other doc improvement
tqchen pushed a commit that referenced this pull request Apr 1, 2023
* stub

* wip

* works

* restore binding

* attention test work

* use RemoveAllUnused

* simplified callback api

* pass original call node to callback

* clean test

* add doc

* add test for the case where the original call is returned

* callback -> rewriter and other doc improvement
tqchen pushed a commit that referenced this pull request Apr 1, 2023
* stub

* wip

* works

* restore binding

* attention test work

* use RemoveAllUnused

* simplified callback api

* pass original call node to callback

* clean test

* add doc

* add test for the case where the original call is returned

* callback -> rewriter and other doc improvement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants