Skip to content

Conversation

@masahi
Copy link
Member

@masahi masahi commented Apr 11, 2023

Building on pattern-based binding rewriting work #14446, I'm adding a new pass for combining parallel matmul sharing the same LHS into one. In contrast to the equivalent Relay pass which is based on dedicated pattern-matching algorithm (completely separate from dataflow pattern matcher), this pass is implemented in terms of the generic binding rewriting infra.

When all matmul branches in a tree have the same set of fused ops, the fused ops are applied to the combined matmul output before slicing. So bias adds are also combined, for example. See the test cases.

Applied to the SD UNet from web-stable-diffusion, it reduces the number of R.matmul from 200 to 100. See below for the IR comparison.

Before combining: https://gist.github.com/masahi/0dab4b8f53115da9c33f4352c9175a87
After: https://gist.github.com/masahi/57ab925a43d2343cbfdb79a31c5b9946

@vinx13 @sunggg @psrivas2 @spectrometerHBH

@tvm-bot
Copy link
Collaborator

tvm-bot commented Apr 11, 2023

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

@masahi masahi force-pushed the combine-parallel-matmul branch from e4ad212 to ceee41c Compare April 11, 2023 19:12
Copy link
Contributor

@jwfromm jwfromm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this awesome PR Masa!

@vinx13 vinx13 merged commit a59c09d into apache:unity Apr 12, 2023
cyx-6 added a commit to cyx-6/tvm that referenced this pull request Apr 17, 2023
This PR expands the support for fused stacked attention patterns strating with `strided_slice`. Initially, we only support fused stacked attention pattern starting with `split` in apache#14608. But with the help of apache#14583, we may have similar patterns starting with `strided_slice` as well.
masahi pushed a commit that referenced this pull request Apr 18, 2023
* [Unity][BYOC] Fuse attention pattern with `strided_slice`

This PR expands the support for fused stacked attention patterns strating with `strided_slice`. Initially, we only support fused stacked attention pattern starting with `split` in #14608. But with the help of #14583, we may have similar patterns starting with `strided_slice` as well.

* remove useless code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants