Skip to content

Commit 999e061

Browse files
committed
Update
[ghstack-poisoned]
1 parent 32f66ca commit 999e061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+6202
-7022
lines changed

backends/test/suite/operators/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def dtype_test(func):
6161
return func
6262

6363

64+
parameterize_by_dtype = pytest.mark.parametrize(
65+
"dtype", DTYPES, ids=lambda s: str(s)[6:]
66+
)
67+
68+
6469
class OperatorTest(unittest.TestCase):
6570
pass
6671

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
s/self\, flow\: TestFlow/test_runner/g
2+
s/self\._test_op/test_runner.lower_and_run_model/g
3+
s/, flow//g
4+
/@operator_test/d
5+
/(OperatorTest):/d
6+
s/dtype_test/parameterize_by_dtype/g
7+
/flow,/d
8+
/import TestFlow/d
9+
/operator_test,/d
10+
/OperatorTest,/d

backends/test/suite/operators/test_abs.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010
import unittest
1111

1212
import torch
13-
from executorch.backends.test.suite.flow import TestFlow
1413

15-
from executorch.backends.test.suite.operators import (
16-
dtype_test,
17-
operator_test,
18-
OperatorTest,
19-
)
14+
from executorch.backends.test.suite.operators import parameterize_by_dtype
2015

2116

2217
class AbsModel(torch.nn.Module):
@@ -27,34 +22,34 @@ def forward(self, x):
2722
return torch.abs(x)
2823

2924

30-
@operator_test
31-
class TestAbs(OperatorTest):
32-
@dtype_test
33-
def test_abs_dtype(self, flow: TestFlow, dtype) -> None:
34-
# Test with different dtypes
35-
model = AbsModel().to(dtype)
36-
self._test_op(model, (torch.rand(10, 10).to(dtype) * 2 - 1,), flow)
25+
@parameterize_by_dtype
26+
def test_abs_dtype(test_runner, dtype) -> None:
27+
# Test with different dtypes
28+
model = AbsModel().to(dtype)
29+
test_runner.lower_and_run_model(model, (torch.rand(10, 10).to(dtype) * 2 - 1,))
3730

38-
def test_abs_shapes(self, flow: TestFlow) -> None:
39-
# Test with different tensor shapes
4031

41-
# 1D tensor
42-
self._test_op(AbsModel(), (torch.randn(20),), flow)
32+
def test_abs_shapes(test_runner) -> None:
33+
# Test with different tensor shapes
4334

44-
# 2D tensor
45-
self._test_op(AbsModel(), (torch.randn(5, 10),), flow)
35+
# 1D tensor
36+
test_runner.lower_and_run_model(AbsModel(), (torch.randn(20),))
4637

47-
# 3D tensor
48-
self._test_op(AbsModel(), (torch.randn(3, 4, 5),), flow)
38+
# 2D tensor
39+
test_runner.lower_and_run_model(AbsModel(), (torch.randn(5, 10),))
4940

50-
@unittest.skip("NaN and Inf are not enforced for backends.")
51-
def test_abs_edge_cases(self, flow: TestFlow) -> None:
52-
# Test edge cases
41+
# 3D tensor
42+
test_runner.lower_and_run_model(AbsModel(), (torch.randn(3, 4, 5),))
5343

54-
# Tensor with infinity
55-
x = torch.tensor([float("inf"), float("-inf"), 1.0, -1.0])
56-
self._test_op(AbsModel(), (x,), flow, generate_random_test_inputs=False)
5744

58-
# Tensor with NaN
59-
x = torch.tensor([float("nan"), 1.0, -1.0])
60-
self._test_op(AbsModel(), (x,), flow, generate_random_test_inputs=False)
45+
@unittest.skip("NaN and Inf are not enforced for backends.")
46+
def test_abs_edge_cases(test_runner) -> None:
47+
# Test edge cases
48+
49+
# Tensor with infinity
50+
x = torch.tensor([float("inf"), float("-inf"), 1.0, -1.0])
51+
test_runner.lower_and_run_model(AbsModel(), (x,), generate_random_test_inputs=False)
52+
53+
# Tensor with NaN
54+
x = torch.tensor([float("nan"), 1.0, -1.0])
55+
test_runner.lower_and_run_model(AbsModel(), (x,), generate_random_test_inputs=False)

backends/test/suite/operators/test_adaptive_avgpool1d.py

Lines changed: 57 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88

99

1010
import torch
11-
from executorch.backends.test.suite.flow import TestFlow
1211

13-
from executorch.backends.test.suite.operators import (
14-
dtype_test,
15-
operator_test,
16-
OperatorTest,
17-
)
12+
from executorch.backends.test.suite.operators import parameterize_by_dtype
1813

1914

2015
class Model(torch.nn.Module):
@@ -31,72 +26,62 @@ def forward(self, x):
3126
return self.adaptive_avgpool(x)
3227

3328

34-
@operator_test
35-
class AdaptiveAvgPool1d(OperatorTest):
36-
@dtype_test
37-
def test_adaptive_avgpool1d_dtype(self, flow: TestFlow, dtype) -> None:
38-
# Input shape: (batch_size, channels, length)
39-
self._test_op(
40-
Model().to(dtype),
41-
((torch.rand(1, 8, 100) * 10).to(dtype),),
42-
flow,
43-
)
29+
@parameterize_by_dtype
30+
def test_adaptive_avgpool1d_dtype(test_runner, dtype) -> None:
31+
# Input shape: (batch_size, channels, length)
32+
test_runner.lower_and_run_model(
33+
Model().to(dtype),
34+
((torch.rand(1, 8, 100) * 10).to(dtype),),
35+
)
4436

45-
def test_adaptive_avgpool1d_output_size(self, flow: TestFlow) -> None:
46-
# Test with different output sizes
47-
self._test_op(
48-
Model(output_size=1),
49-
(torch.randn(1, 8, 100),),
50-
flow,
51-
)
52-
self._test_op(
53-
Model(output_size=10),
54-
(torch.randn(1, 8, 100),),
55-
flow,
56-
)
57-
self._test_op(
58-
Model(output_size=50),
59-
(torch.randn(1, 8, 100),),
60-
flow,
61-
)
6237

63-
def test_adaptive_avgpool1d_batch_sizes(self, flow: TestFlow) -> None:
64-
# Test with batch inputs
65-
self._test_op(
66-
Model(),
67-
(torch.randn(2, 8, 100),),
68-
flow,
69-
)
70-
self._test_op(
71-
Model(),
72-
(torch.randn(8, 8, 100),),
73-
flow,
74-
)
75-
self._test_op(
76-
Model(),
77-
(torch.randn(16, 8, 100),),
78-
flow,
79-
)
38+
def test_adaptive_avgpool1d_output_size(test_runner) -> None:
39+
# Test with different output sizes
40+
test_runner.lower_and_run_model(
41+
Model(output_size=1),
42+
(torch.randn(1, 8, 100),),
43+
)
44+
test_runner.lower_and_run_model(
45+
Model(output_size=10),
46+
(torch.randn(1, 8, 100),),
47+
)
48+
test_runner.lower_and_run_model(
49+
Model(output_size=50),
50+
(torch.randn(1, 8, 100),),
51+
)
8052

81-
def test_adaptive_avgpool1d_input_sizes(self, flow: TestFlow) -> None:
82-
# Test with different input sizes
83-
self._test_op(
84-
Model(),
85-
(torch.randn(1, 4, 100),),
86-
flow,
87-
)
88-
self._test_op(
89-
Model(),
90-
(torch.randn(1, 16, 100),),
91-
flow,
92-
)
93-
self._test_op(
94-
Model(),
95-
(torch.randn(1, 8, 50),),
96-
flow,
97-
)
98-
self._test_op(
99-
Model(),
100-
(torch.randn(1, 8, 200),),
101-
flow,
102-
)
53+
54+
def test_adaptive_avgpool1d_batch_sizes(test_runner) -> None:
55+
# Test with batch inputs
56+
test_runner.lower_and_run_model(
57+
Model(),
58+
(torch.randn(2, 8, 100),),
59+
)
60+
test_runner.lower_and_run_model(
61+
Model(),
62+
(torch.randn(8, 8, 100),),
63+
)
64+
test_runner.lower_and_run_model(
65+
Model(),
66+
(torch.randn(16, 8, 100),),
67+
)
68+
69+
70+
def test_adaptive_avgpool1d_input_sizes(test_runner) -> None:
71+
# Test with different input sizes
72+
test_runner.lower_and_run_model(
73+
Model(),
74+
(torch.randn(1, 4, 100),),
75+
)
76+
test_runner.lower_and_run_model(
77+
Model(),
78+
(torch.randn(1, 16, 100),),
79+
)
80+
test_runner.lower_and_run_model(
81+
Model(),
82+
(torch.randn(1, 8, 50),),
83+
)
84+
test_runner.lower_and_run_model(
85+
Model(),
86+
(torch.randn(1, 8, 200),),
87+
)

0 commit comments

Comments
 (0)