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

[BugFix] Support rewrite_once when the number of callbacks > 1 #14344

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

sisleyli
Copy link
Contributor

The rewrite_once of the current PatternRewriter rewrites once only when the last callback in the callbacks list is rewrite_once. I don't think this is as expected.
I think the rewrite_once strategy should be that the callback marked with rewrite_once is rewritten only once, and the rest of the callbacks are still rewritten multiple times.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Mar 20, 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.

  • No users to tag found in teams: bugfix See #10317 for details

Generated by tvm-bot

@sisleyli
Copy link
Contributor Author

What do you think @masahi ? Thank you!

@@ -796,24 +796,38 @@ Expr PatternRewriter::Rewrite(const Array<DFPatternCallback>& callbacks, const E
bool equal = true;
static auto* structural_equal = runtime::Registry::Get("node.StructuralEqual");
ICHECK(structural_equal) << "node.StructuralEqual is not registered.";
// Use the callback until the callback's attribute is rewrite_once=true and has been rewritten
std::unordered_map<DFPatternCallback, bool, ObjectPtrHash, ObjectPtrEqual> callbacks_map;
Copy link
Member

Choose a reason for hiding this comment

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

callbacks_map -> done, swapping false and true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please take another look. Thank you!

@@ -796,24 +796,38 @@ Expr PatternRewriter::Rewrite(const Array<DFPatternCallback>& callbacks, const E
bool equal = true;
static auto* structural_equal = runtime::Registry::Get("node.StructuralEqual");
ICHECK(structural_equal) << "node.StructuralEqual is not registered.";
// Use the callback until the callback's attribute is rewrite_once=true and has been rewritten
Copy link
Member

Choose a reason for hiding this comment

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

// Keep track of callbacks that have finished rewriting

@sisleyli sisleyli force-pushed the feat_rewrite_once branch from 429c287 to d274784 Compare March 20, 2023 23:56
@sisleyli
Copy link
Contributor Author

It seems that CI has passed, could you please help me merge this PR? Thanks @masahi !

@sisleyli sisleyli force-pushed the feat_rewrite_once branch from d274784 to 22f86d9 Compare March 21, 2023 09:10
@sisleyli
Copy link
Contributor Author

It seems that CI has passed, could you please help me merge this PR? Thanks @masahi !

I don't know whether our repo will automatically rebase when it merges PR, so I just performed a rebase operation myself, do I need to do this every time the main branch is updated?

@masahi
Copy link
Member

masahi commented Mar 21, 2023

No you don't have to do that. You now have to wait for another 4h :)

@sisleyli
Copy link
Contributor Author

Thanks masahi, I should have consulted before performing the rebase operation :(

@sisleyli
Copy link
Contributor Author

CI passed again...I won't do redundant operations this time.hhhh

@masahi masahi merged commit d4ca123 into apache:main Mar 21, 2023
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.

3 participants