tvm
tvm copied to clipboard
[BugFix][Relay] skip leaf args when matching 'path' part for dominator pattern
This is a patch for PR https://github.com/apache/tvm/pull/15473 That PR tried to solve the issues described in RFC, but introduced another issue, probably unintentionally. The new issue occurs, when there are some leaf args of some OPs along the path during matching 'path' part for dominator pattern. For example, suppose we have a dominator pattern as follows:
conv2d_pat = is_op("nn.conv2d")(wildcard(), wildcard())
eltwise_pat = (wildcard().has_attr({"TOpPattern": K_ELEMWISE}))(None)
broadcast_pat = (wildcard().has_attr({"TOpPattern": K_BROADCAST}))(None)
path_pat = eltwise_pat | broadcast_pat
injective_pat = (wildcard().has_attr({"TOpPattern": K_INJECTIVE}))(wildcard())
pattern = DominatorPattern(conv2d_pat, path_pat, injective_pat)
and we want to match the graph:
input weight
\ /
\ /
conv2d bias
\ /
\ /
bias_add
|
relu
|
reshape
The pattern should match this graph since conv2d dominates reshape along bias_add+relu, provided that we accept the original definition of "dominator" in TVM. But the change in PR https://github.com/apache/tvm/pull/15473 makes the matching fail because it treats bias as an addtional path.
This is fixed by skipping the leaf arguments when matching the 'path' part of the dominator pattern.
The issue may be rooted in some confusion of the definition of "dominator" in TVM, as described in this post. But at present, since the original definition of "dominator" remains unchanged in the real codebase, I think my patch may still make sense.
Some changes are made to fix an issue of matching dominator pattern. Could you help review this? cc @wrongtest-intellif @kfeng123