[Unity][Graph matching] Automatically add used-by constraints for is_op pattern#14439
[Unity][Graph matching] Automatically add used-by constraints for is_op pattern#14439cyx-6 merged 2 commits intoapache:unityfrom
used-by constraints for is_op pattern#14439Conversation
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
| inline tvm::runtime::Map<DFPattern, Var> MatchGraphDefault(const DataflowBlock& dfb, | ||
| Optional<Var> start_hint = NullOpt, | ||
| bool must_include_hint = false) { | ||
| return MatchGraph(PatternContext::Current(), dfb, start_hint, must_include_hint); |
There was a problem hiding this comment.
This gets removed since it is not used anywhere but it touches PatternContext::Current() (which is now Optional)
| Q_weight_pat.only_used_by(matmul1, 1) | ||
| K_weight_pat.only_used_by(matmul2, 1) | ||
| V_weight_pat.only_used_by(matmul3, 1) |
There was a problem hiding this comment.
I understand used_by can be removed now as it is implied by a function call. However, only_used_by is a stronger constraint that cannot be implied via a fn call right?
There was a problem hiding this comment.
But yeah I guess you meant oftentimes we don't fold Q, K, and V so it is fine if they are being used by others at the same time.
ganler
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the improvement!
…is_op` pattern (#14439) * Automatically add used-by constraints for is_op pattern * [DOC fix] pass context -> constraint context
…is_op` pattern (#14439) * Automatically add used-by constraints for is_op pattern * [DOC fix] pass context -> constraint context
…is_op` pattern (#14439) * Automatically add used-by constraints for is_op pattern * [DOC fix] pass context -> constraint context
Compared to the typical, structural matching (e.g. matching
is_opbased pattern againstCallNode), graph pattern matching requires additionally specifyingused_byconstraints. This leads to an obvious redundancy in the usage:This PR hacks
is_opconstructor by automatically adding suchused_byconstraints between caller and callee patterns. See the simplified test case for QOL improvement.@ganler @sunggg