masahi opened a new pull request, #14417:
URL: https://github.com/apache/tvm/pull/14417

   Graph pattern matching uses `std::map` and `std::set` keyed on pointers, 
which leads to non-deterministic matching result. This PR removed all 
non-determinism. 
   
   For example, consider matching against QKV projection before attention. 
Given a sequence of bindings,
   ```
   with R.dataflow():
       lv0 = R.matmul(x, w0)
       lv1 = R.matmul(x, w1)
       lv2 = R.matmul(x, w2)
       ...
   ```
   
   and patterns,
   ```
   with PatternContext() as ctx:
       inp_pat = wildcard()
       Q_weight_pat = wildcard()
       K_weight_pat = wildcard()
       V_weight_pat = wildcard()
   
       matmul1 = is_op("relax.matmul")(inp_pat, Q_weight_pat)
       matmul2 = is_op("relax.matmul")(inp_pat, K_weight_pat)
       matmul3 = is_op("relax.matmul")(inp_pat, V_weight_pat)
   ```
   
   intuitively I expect the following matching result:
   ```
   Q_weight_pat - w0
   K_weight_pat - w1
   V_weight_pat - w2
   ```
   
   But since three matmul patterns are independent of each other, each pattern 
can match any of three matmuls in the bindings. And since graph pattern 
matching processes patterns and variables in the bindings in a 
non-deterministic order, matching result becomes non deterministic as well. 


-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to