Dear community,
I encountered a problem when I trying with fuzzy path matching. I want to match arbitrary number of any type of node (i.e., node can be any type, and the path length is vary, using wildcard(None)) between a parent node and a post-dominate child node. One sample computation want to match is:
input1 input2
\ /
conv2d input3
\ /
add input4
\ /
multiply
|
relu
I am trying to match this pattern using a fuzzy path with only parent and child node specified. Match is successful when the parent node is add and child node is relu
# parent node is add, child node is nn.relu
fuzzy_pat = dominates(is_op('add')(wildcard(), wildcard()), wildcard()(None), is_op('nn.relu')(wildcard()))
input1 = relay.var("input1")
input2 = relay.var("input2")
input3 = relay.var("input3")
input4 = relay.var("input4")
conv2d = relay.op.nn.conv2d(input1, input2)
buf1 = conv2d + input3
buf2 = relay.op.multiply(buf1, input4)
relu = relay.op.nn.relu(buf2)
assert fuzzy_pat.match(relu) # assert True
However, the matching is failed when the parent node is conv2d:
# parent node is conv2d, child node is nn.relu
fuzzy_pat = dominates(is_op('nn.conv2d')(wildcard(), wildcard()), wildcard()(None), is_op('nn.relu')(wildcard()))
input1 = relay.var("input1")
input2 = relay.var("input2")
input3 = relay.var("input3")
input4 = relay.var("input4")
conv2d = relay.op.nn.conv2d(input1, input2)
buf1 = conv2d + input3
buf2 = relay.op.multiply(buf1, input4)
relu = relay.op.nn.relu(buf2)
assert fuzzy_pat.match(relu) # assert is False
I did not notice any fundamental differences between above two cases, why the second matching is failed and how could I match arbitrary number and type of nodes between a parent node and a post-dominate child node?
Many thanks in advance~!