Skip to content

Commit 23898b0

Browse files
Run on device and compare outputs
For op test, add run_method_and_compare_outputs to make the test complete. The Exynos-backend-specific PTE file will be executed on device, and its outputs will be checked. Co-authored-by: chong-chen <[email protected]>
1 parent 31819f6 commit 23898b0

34 files changed

+66
-42
lines changed

backends/samsung/test/ops/test_add.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _test(self, module: torch.nn.Module, inputs):
4747
.check_not(["executorch_exir_dialects_edge__ops_aten_add_Tensor"])
4848
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4949
.to_executorch()
50+
.run_method_and_compare_outputs(inputs=inputs)
5051
)
5152

5253
def test_fp32_simple_add(self):

backends/samsung/test/ops/test_avg_pool2d.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,15 @@ def __init__(
3232
ceil_mode=False,
3333
).to(torch.float)
3434

35-
def get_example_inputs(self) -> tuple[torch.Tensor]:
36-
input_1 = torch.randn(1, 16, 24, 24)
37-
return (input_1,)
38-
3935
def forward(self, x: torch.Tensor) -> torch.Tensor:
4036
return self.avg_pool(x)
4137

4238

4339
class TestAvgPool2d(unittest.TestCase):
44-
def _test(self, module: torch.nn.Module):
40+
def _test(self, module: torch.nn.Module, inputs):
4541
tester = SamsungTester(
4642
module,
47-
module.get_example_inputs(),
43+
inputs,
4844
[gen_samsung_backend_compile_spec("E9955")],
4945
)
5046
(
@@ -54,13 +50,17 @@ def _test(self, module: torch.nn.Module):
5450
.check_not(["executorch_exir_dialects_edge__ops_aten_avg_pool2d_default"])
5551
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
5652
.to_executorch()
53+
.run_method_and_compare_outputs(inputs=inputs)
5754
)
5855

5956
def test_fp32_avg_pool2d(self):
60-
self._test(AvgPool2d())
57+
inputs = (torch.randn(1, 16, 24, 24),)
58+
self._test(AvgPool2d(), inputs)
6159

6260
def test_fp32_avg_pool2d_with_stride(self):
63-
self._test(AvgPool2d(stride=2))
61+
inputs = (torch.randn(1, 16, 24, 24),)
62+
self._test(AvgPool2d(stride=2), inputs)
6463

6564
def test_fp32_avg_pool2d_with_kernel_size(self):
66-
self._test(AvgPool2d(kernel_size=4))
65+
inputs = (torch.randn(1, 16, 24, 24),)
66+
self._test(AvgPool2d(kernel_size=4), inputs)

backends/samsung/test/ops/test_batch_norm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _test(self, module: torch.nn.Module, inputs):
4343
)
4444
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4545
.to_executorch()
46+
.run_method_and_compare_outputs(inputs=inputs)
4647
)
4748

4849
def test_fp32_batch_norm(self):

backends/samsung/test/ops/test_bmm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
3131

3232
class TestBatchMatmul(unittest.TestCase):
3333
def _test(self, module: torch.nn.Module):
34+
torch.manual_seed(8)
3435
inputs = module.get_example_inputs()
3536
tester = SamsungTester(
3637
module, inputs, [gen_samsung_backend_compile_spec("E9955")]
@@ -42,6 +43,7 @@ def _test(self, module: torch.nn.Module):
4243
.check_not(["executorch_exir_dialects_edge__ops_aten_bmm_default"])
4344
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4445
.to_executorch()
46+
.run_method_and_compare_outputs(inputs=inputs, atol=0.005, rtol=0.005)
4547
)
4648

4749
def test_fp32_bmm(self):

backends/samsung/test/ops/test_cat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def _test(self, module: torch.nn.Module, inputs):
3737
.check_not(["executorch_exir_dialects_edge__ops_aten_cat_default"])
3838
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
3939
.to_executorch()
40+
.run_method_and_compare_outputs(inputs=inputs)
4041
)
4142

4243
def test_fp32_concat_on_axis1(self):

backends/samsung/test/ops/test_clamp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def _test(self, module: torch.nn.Module, inputs):
4242
.check_not(["executorch_exir_dialects_edge__ops_aten_clamp_default"])
4343
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4444
.to_executorch()
45+
.run_method_and_compare_outputs(inputs=inputs)
4546
)
4647

4748
def test_fp32_clamp(self):

backends/samsung/test/ops/test_constant_pad_nd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _test(self, module: torch.nn.Module, inputs):
3838
)
3939
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4040
.to_executorch()
41+
.run_method_and_compare_outputs(inputs=inputs)
4142
)
4243

4344
def test_fp32_constant_pad_nd(self):

backends/samsung/test/ops/test_conv2d.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ def __init__(
4141

4242
self.in_channels = in_channels
4343

44-
def get_example_inputs(self) -> tuple[torch.Tensor]:
45-
input_1 = torch.randn(1, self.in_channels, 24, 24)
46-
return (input_1,)
47-
4844
def forward(self, x: torch.Tensor) -> torch.Tensor:
4945
return self.conv(x)
5046

@@ -62,19 +58,15 @@ def __init__(self) -> None:
6258
bias=True,
6359
)
6460

65-
def get_example_inputs(self) -> tuple[torch.Tensor]:
66-
input_1 = torch.randn(1, 32, 24, 24)
67-
return (input_1,)
68-
6961
def forward(self, x: torch.Tensor) -> torch.Tensor:
7062
return self.conv(x)
7163

7264

7365
class TestConv2d(unittest.TestCase):
74-
def _test(self, module: torch.nn.Module):
66+
def _test(self, module: torch.nn.Module, inputs):
7567
tester = SamsungTester(
7668
module,
77-
module.get_example_inputs(),
69+
inputs,
7870
[gen_samsung_backend_compile_spec("E9955")],
7971
)
8072
(
@@ -83,16 +75,21 @@ def _test(self, module: torch.nn.Module):
8375
.check_not(["executorch_exir_dialects_edge__ops_aten_convolution_default"])
8476
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
8577
.to_executorch()
78+
.run_method_and_compare_outputs(inputs=inputs)
8679
)
8780

8881
def test_fp32_conv2d_without_bias(self):
89-
self._test(Conv2d(bias=False))
82+
inputs = (torch.randn(1, 3, 24, 24),)
83+
self._test(Conv2d(bias=False), inputs)
9084

9185
def test_fp32_conv2d_with_bias(self):
92-
self._test(Conv2d(bias=True))
86+
inputs = (torch.randn(1, 3, 24, 24),)
87+
self._test(Conv2d(bias=True), inputs)
9388

9489
def test_fp32_depthwise_conv2d(self):
95-
self._test(Conv2d(in_channels=8, out_channels=8, groups=8))
90+
inputs = (torch.randn(1, 8, 24, 24),)
91+
self._test(Conv2d(in_channels=8, out_channels=8, groups=8), inputs)
9692

9793
def test_fp32_transpose_conv2d(self):
98-
self._test(TransposeConv2d())
94+
inputs = (torch.randn(1, 32, 24, 24),)
95+
self._test(TransposeConv2d(), inputs)

backends/samsung/test/ops/test_div.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _test(self, module: torch.nn.Module, inputs):
3838
.check_not(["executorch_exir_dialects_edge__ops_aten_div_Tensor"])
3939
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4040
.to_executorch()
41+
.run_method_and_compare_outputs(inputs=inputs)
4142
)
4243

4344
def test_fp32_simple_div(self):

backends/samsung/test/ops/test_embedding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def _test(self, module: torch.nn.Module, inputs):
3737
.check_not(["executorch_exir_dialects_edge__ops_aten_embedding_default"])
3838
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
3939
.to_executorch()
40+
.run_method_and_compare_outputs(inputs=inputs)
4041
)
4142

4243
def test_fp32_embedding(self):
4344
num_embeddings = 2048
44-
inputs = (torch.randint(0, num_embeddings, (1, 64), dtype=torch.int32),)
45+
inputs = (torch.randint(0, 12, (1, 64), dtype=torch.int32),)
4546
self._test(Embedding(num_embeddings=num_embeddings), inputs)

0 commit comments

Comments
 (0)