()
| 626 | |
| 627 | |
| 628 | def test_concat_mm_split(): |
| 629 | # Same as Figure 2(b) in TASO paper. |
| 630 | @tvm.script.ir_module |
| 631 | class CMS: |
| 632 | @R.function |
| 633 | def main( |
| 634 | a: R.Tensor((32, 32), "float32"), |
| 635 | b: R.Tensor((16, 32), "float32"), |
| 636 | c: R.Tensor((16, 32), "float32"), |
| 637 | ) -> R.Tensor: |
| 638 | with R.dataflow(): |
| 639 | lv0 = R.call_dps_packed("my_concat", (b, c), R.Tensor((32, 32), dtype="float32")) |
| 640 | lv1 = R.call_dps_packed("my_matmul", (a, lv0), R.Tensor((32, 32), dtype="float32")) |
| 641 | lv2 = R.call_dps_packed( |
| 642 | "my_split", |
| 643 | (lv1,), |
| 644 | [R.Tensor((16, 32), dtype="float32"), R.Tensor((16, 32), dtype="float32")], |
| 645 | ) |
| 646 | lv3 = R.TupleGetItem(lv2, 0) |
| 647 | lv4 = R.TupleGetItem(lv2, 1) |
| 648 | lv5 = R.add(lv3, lv4) |
| 649 | R.output(lv5) |
| 650 | return lv5 |
| 651 | |
| 652 | with PatternContext() as ctx: |
| 653 | ( |
| 654 | is_call_dps_packed("my_concat") |
| 655 | >> is_call_dps_packed("my_matmul") |
| 656 | >> is_call_dps_packed("my_split") |
| 657 | ) |
| 658 | dfb = CMS["main"].body.blocks[0] |
| 659 | assert ctx.match_dfb(dfb) |
| 660 | |
| 661 | with PatternContext() as ctx: |
| 662 | split = is_call_dps_packed("my_split") |
| 663 | lv3 = TupleGetItemPattern(split, 0).has_shape([16, 32]) |
| 664 | lv4 = TupleGetItemPattern(split, 1).has_shape([16, 32]) |
| 665 | split.fork_to(lv3, lv4) |
| 666 | add = is_op("relax.add")(lv3, lv4) |
| 667 | # TODO(@ganler): simplify this through implicit graph pattern. |
| 668 | lv3 >> add |
| 669 | lv4 >> add |
| 670 | |
| 671 | dfb = CMS["main"].body.blocks[0] |
| 672 | assert ctx.match_dfb(dfb) |
| 673 | |
| 674 | |
| 675 | def test_self_attention(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…