|
16 | 16 | from executorch.backends.samsung.test.utils.utils import TestConfig |
17 | 17 |
|
18 | 18 |
|
19 | | -class Pow(torch.nn.Module): |
| 19 | +class PowScalar(torch.nn.Module): |
20 | 20 | def __init__(self) -> None: |
21 | 21 | super().__init__() |
22 | 22 |
|
23 | 23 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
24 | 24 | return x**2.0 |
25 | 25 |
|
26 | 26 |
|
| 27 | +class PowTensor(torch.nn.Module): |
| 28 | + def __init__(self) -> None: |
| 29 | + super().__init__() |
| 30 | + |
| 31 | + def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: |
| 32 | + return torch.pow(x, y) |
| 33 | + |
| 34 | + |
27 | 35 | class TestPow(unittest.TestCase): |
28 | | - def _test(self, module: torch.nn.Module, inputs): |
| 36 | + def _test(self, module: torch.nn.Module, inputs, expected_op: str): |
29 | 37 | tester = SamsungTester( |
30 | 38 | module, |
31 | 39 | inputs, |
32 | 40 | [gen_samsung_backend_compile_spec(TestConfig.chipset)], |
33 | 41 | ) |
34 | 42 | ( |
35 | 43 | tester.export() |
36 | | - .check_count({"torch.ops.aten.pow.Tensor_Scalar": 1}) |
| 44 | + .check_count({expected_op: 1}) |
37 | 45 | .to_edge_transform_and_lower() |
38 | 46 | .check_not(["executorch_exir_dialects_edge__ops_aten_pow_default"]) |
39 | 47 | .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) |
40 | 48 | .to_executorch() |
41 | 49 | .run_method_and_compare_outputs() |
42 | 50 | ) |
43 | 51 |
|
44 | | - def test_fp32_pow(self): |
| 52 | + def test_fp32_pow_scalar(self): |
45 | 53 | inputs = (torch.randn(1, 1, 16, 8),) |
46 | | - self._test(Pow(), inputs) |
| 54 | + self._test(PowScalar(), inputs, "torch.ops.aten.pow.Tensor_Scalar") |
| 55 | + |
| 56 | + def test_fp32_pow_tensor(self): |
| 57 | + inputs = (torch.randn(1, 1, 16, 8), torch.randn(1, 1, 16, 8)) |
| 58 | + self._test(PowTensor(), inputs, "torch.ops.aten.pow.Tensor_Tensor") |
0 commit comments