comaniac opened a new issue #5647:
URL: https://github.com/apache/incubator-tvm/issues/5647


   In the unit test of pattern language, the pattern `conv2d -> 
optional(bias_add) -> relu` can match `conv2d -> bias_add -> relu`, and the 
partitioned function does include 3 ops.
   
   On the other hand, I tried to modify the pattern to `conv2d -> bias_add -> 
optional(relu)` and found the following issue:
   
   1. Graph: `conv2d->bias_add`.
   
       * Match: True
       * Partition: Correct.
   
   2. Graph: `conv2d->bias_add->relu`:
   
       * Match: True
       * Partition: The function only includes 2 ops (`conv2d` and `bias_add`) 
without `relu`.
   
   Accordingly, I guess the last `optional` might be ignored during the 
matching process. After all, the last optional is useless for `match` 
operation, but we need to include it for partition.
   
   ```python
   import tvm
   from tvm import relay
   from tvm.relay.dataflow_pattern import *
   
   def test_match_option():
       x = relay.var('x')
       w = relay.var('w')
       b = relay.var('b')
   
       conv2d = is_op('nn.conv2d')(wildcard(), wildcard())
       bias = conv2d.optional(lambda x: is_op('nn.bias_add')(x, wildcard()))
       pattern1 = is_op('nn.relu')(bias)
   
       conv2d = is_op('nn.conv2d')(wildcard(), wildcard())
       bias = is_op('nn.bias_add')(conv2d, wildcard())
       pattern2 = bias.optional(lambda x: is_op('nn.relu')(x))
   
       conv2d = relay.op.nn.conv2d(x, w)
       bias_add = relay.op.nn.bias_add(conv2d, b)
       relu = relay.op.nn.relu(bias_add)
   
       assert pattern1.match(relu)
       print(pattern1.partition(relu))
   
       assert pattern2.match(relu)
       print(pattern2.partition(relu))
   
   test_match_option()
   ```
   cc @mbrookhart 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to