[Bugfix] Support tree-like subgraph matching#58
Merged
chhzh123 merged 5 commits intoawslabs:mainfrom Feb 15, 2023
Merged
Conversation
Contributor
Author
|
Thanks @comaniac |
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.
Description
For the following tree-like subgraph with multiple inputs, if we use the
patternto match the+,-, and*operators, only+and*will be returned. This is because the current implementation of subgraph matching starts from the first instruction of the original subgraph and target subgraph, and test if users of the instruction are the same. The process is iterative and basically is a DFS. However, this process may ignore instructionbsincebis not the user ofa.To solve this problem, we can simply traverse the graph node from top to bottom following the order of the link list (i.e., visiting the successors in a topological order), and compare the nodes in the original and target subgraph, so that all the
+,-, and*operators will be matched. Notice this fix still cannot support commutativity between operands, so pattern(y - z) * (x + y)cannot match any subgraphs. This feature may need more engineering efforts in the future.Also, this PR adds
concrete_argsto.replace_module()for the case that the user-defined module has different numbers of arguments with the arguments in the original subgraph.Checklist