|
10 | 10 | from executorch.backends.arm._passes.fuse_equal_placeholders_pass import (
|
11 | 11 | FuseEqualPlaceholdersPass,
|
12 | 12 | )
|
13 |
| -from executorch.backends.arm.test.tester.test_pipeline import PassPipeline |
| 13 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 14 | + PassPipeline, |
| 15 | + TosaPipelineMI, |
| 16 | +) |
14 | 17 |
|
15 | 18 | input_t = Tuple[torch.Tensor] # Input x
|
16 | 19 |
|
@@ -54,6 +57,25 @@ def forward(self, x):
|
54 | 57 | return self.fc1(x) + self.fc2(x)
|
55 | 58 |
|
56 | 59 |
|
| 60 | +class NotFuseTensorWithDifferentType(torch.nn.Module): |
| 61 | + |
| 62 | + ops_before_pass = {} |
| 63 | + ops_after_pass = {} |
| 64 | + ops_not_after_pass = [] |
| 65 | + |
| 66 | + def forward(self, x: torch.Tensor, y: torch.Tensor): |
| 67 | + """ |
| 68 | + Args: |
| 69 | + x: A float tensor (dtype=torch.float32) |
| 70 | + y: An int tensor (dtype=torch.int32) |
| 71 | + """ |
| 72 | + a = torch.tensor(1.0, dtype=torch.float32) |
| 73 | + b = torch.tensor(1, dtype=torch.int32) |
| 74 | + m = x < a |
| 75 | + n = y > b |
| 76 | + return m, n |
| 77 | + |
| 78 | + |
57 | 79 | def test_fuse_equal_placeholders_constants_tosa_MI():
|
58 | 80 | module = FuseWeightsConstants()
|
59 | 81 | data = (torch.rand(1, 2, 8),)
|
@@ -94,3 +116,24 @@ def test_fuse_equal_placeholders_state_dict_tosa_MI():
|
94 | 116 | assert len(state_dict_keys) == 2, "FuseEqualPlaceholders state_dict failed"
|
95 | 117 | assert "_common" in state_dict_keys[0], "FuseEqualPlaceholders state_dict failed"
|
96 | 118 | assert "_common" in state_dict_keys[1], "FuseEqualPlaceholders state_dict failed"
|
| 119 | + |
| 120 | + |
| 121 | +def test_not_fuse_tensor_with_different_type_MI(): |
| 122 | + module = NotFuseTensorWithDifferentType() |
| 123 | + data = ( |
| 124 | + torch.rand( |
| 125 | + 1, |
| 126 | + ), |
| 127 | + torch.randint( |
| 128 | + 0, |
| 129 | + 10, |
| 130 | + (1,), |
| 131 | + dtype=torch.int, |
| 132 | + ), |
| 133 | + ) |
| 134 | + pipeline = TosaPipelineMI[input_t]( |
| 135 | + module, |
| 136 | + data, |
| 137 | + aten_op=[], |
| 138 | + ) |
| 139 | + pipeline.run() |
0 commit comments