Skip to content

Commit 0c18fb7

Browse files
committed
Update
[ghstack-poisoned]
1 parent d3a5cd8 commit 0c18fb7

File tree

3 files changed

+320
-0
lines changed

3 files changed

+320
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
8+
9+
10+
import torch
11+
from executorch.backends.test.suite.flow import TestFlow
12+
13+
from executorch.backends.test.suite.operators import (
14+
dtype_test,
15+
operator_test,
16+
OperatorTest,
17+
)
18+
19+
class Model(torch.nn.Module):
20+
def __init__(
21+
self,
22+
output_size=5,
23+
):
24+
super().__init__()
25+
self.adaptive_avgpool = torch.nn.AdaptiveAvgPool1d(
26+
output_size=output_size,
27+
)
28+
29+
def forward(self, x):
30+
return self.adaptive_avgpool(x)
31+
32+
@operator_test
33+
class AdaptiveAvgPool1d(OperatorTest):
34+
@dtype_test
35+
def test_adaptive_avgpool1d_dtype(self, flow: TestFlow, dtype) -> None:
36+
# Input shape: (batch_size, channels, length)
37+
self._test_op(
38+
Model().to(dtype),
39+
((torch.rand(1, 8, 100) * 10).to(dtype),),
40+
flow,
41+
)
42+
43+
def test_adaptive_avgpool1d_output_size(self, flow: TestFlow) -> None:
44+
# Test with different output sizes
45+
self._test_op(
46+
Model(output_size=1),
47+
(torch.randn(1, 8, 100),),
48+
flow,
49+
)
50+
self._test_op(
51+
Model(output_size=10),
52+
(torch.randn(1, 8, 100),),
53+
flow,
54+
)
55+
self._test_op(
56+
Model(output_size=50),
57+
(torch.randn(1, 8, 100),),
58+
flow,
59+
)
60+
61+
def test_adaptive_avgpool1d_batch_sizes(self, flow: TestFlow) -> None:
62+
# Test with batch inputs
63+
self._test_op(
64+
Model(),
65+
(torch.randn(2, 8, 100),),
66+
flow,
67+
)
68+
self._test_op(
69+
Model(),
70+
(torch.randn(8, 8, 100),),
71+
flow,
72+
)
73+
self._test_op(
74+
Model(),
75+
(torch.randn(16, 8, 100),),
76+
flow,
77+
)
78+
79+
def test_adaptive_avgpool1d_input_sizes(self, flow: TestFlow) -> None:
80+
# Test with different input sizes
81+
self._test_op(
82+
Model(),
83+
(torch.randn(1, 4, 100),),
84+
flow,
85+
)
86+
self._test_op(
87+
Model(),
88+
(torch.randn(1, 16, 100),),
89+
flow,
90+
)
91+
self._test_op(
92+
Model(),
93+
(torch.randn(1, 8, 50),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(1, 8, 200),),
99+
flow,
100+
)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
8+
9+
10+
import torch
11+
from executorch.backends.test.suite.flow import TestFlow
12+
13+
from executorch.backends.test.suite.operators import (
14+
dtype_test,
15+
operator_test,
16+
OperatorTest,
17+
)
18+
19+
class Model(torch.nn.Module):
20+
def __init__(
21+
self,
22+
output_size=(5, 5),
23+
):
24+
super().__init__()
25+
self.adaptive_avgpool = torch.nn.AdaptiveAvgPool2d(
26+
output_size=output_size,
27+
)
28+
29+
def forward(self, x):
30+
return self.adaptive_avgpool(x)
31+
32+
@operator_test
33+
class AdaptiveAvgPool2d(OperatorTest):
34+
@dtype_test
35+
def test_adaptive_avgpool2d_dtype(self, flow: TestFlow, dtype) -> None:
36+
# Input shape: (batch_size, channels, height, width)
37+
self._test_op(
38+
Model().to(dtype),
39+
((torch.rand(1, 8, 20, 20) * 10).to(dtype),),
40+
flow,
41+
)
42+
43+
def test_adaptive_avgpool2d_output_size(self, flow: TestFlow) -> None:
44+
# Test with different output sizes
45+
self._test_op(
46+
Model(output_size=1),
47+
(torch.randn(1, 8, 20, 20),),
48+
flow,
49+
)
50+
self._test_op(
51+
Model(output_size=(1, 1)),
52+
(torch.randn(1, 8, 20, 20),),
53+
flow,
54+
)
55+
self._test_op(
56+
Model(output_size=(10, 10)),
57+
(torch.randn(1, 8, 20, 20),),
58+
flow,
59+
)
60+
self._test_op(
61+
Model(output_size=(5, 10)),
62+
(torch.randn(1, 8, 20, 20),),
63+
flow,
64+
)
65+
66+
def test_adaptive_avgpool2d_batch_sizes(self, flow: TestFlow) -> None:
67+
# Test with batch inputs
68+
self._test_op(
69+
Model(),
70+
(torch.randn(2, 8, 20, 20),),
71+
flow,
72+
)
73+
self._test_op(
74+
Model(),
75+
(torch.randn(8, 8, 20, 20),),
76+
flow,
77+
)
78+
self._test_op(
79+
Model(),
80+
(torch.randn(16, 8, 20, 20),),
81+
flow,
82+
)
83+
84+
def test_adaptive_avgpool2d_input_sizes(self, flow: TestFlow) -> None:
85+
# Test with different input sizes
86+
self._test_op(
87+
Model(),
88+
(torch.randn(1, 4, 20, 20),),
89+
flow,
90+
)
91+
self._test_op(
92+
Model(),
93+
(torch.randn(1, 16, 20, 20),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(1, 8, 10, 10),),
99+
flow,
100+
)
101+
self._test_op(
102+
Model(),
103+
(torch.randn(1, 8, 30, 30),),
104+
flow,
105+
)
106+
self._test_op(
107+
Model(),
108+
(torch.randn(1, 8, 15, 25),),
109+
flow,
110+
)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-unsafe
8+
9+
10+
import torch
11+
from executorch.backends.test.suite.flow import TestFlow
12+
13+
from executorch.backends.test.suite.operators import (
14+
dtype_test,
15+
operator_test,
16+
OperatorTest,
17+
)
18+
19+
class Model(torch.nn.Module):
20+
def __init__(
21+
self,
22+
output_size=(4, 4, 4),
23+
):
24+
super().__init__()
25+
self.adaptive_avgpool = torch.nn.AdaptiveAvgPool3d(
26+
output_size=output_size,
27+
)
28+
29+
def forward(self, x):
30+
return self.adaptive_avgpool(x)
31+
32+
@operator_test
33+
class AdaptiveAvgPool3d(OperatorTest):
34+
@dtype_test
35+
def test_adaptive_avgpool3d_dtype(self, flow: TestFlow, dtype) -> None:
36+
# Input shape: (batch_size, channels, depth, height, width)
37+
self._test_op(
38+
Model().to(dtype),
39+
((torch.rand(1, 4, 8, 8, 8) * 10).to(dtype),),
40+
flow,
41+
)
42+
43+
def test_adaptive_avgpool3d_output_size(self, flow: TestFlow) -> None:
44+
# Test with different output sizes
45+
self._test_op(
46+
Model(output_size=1),
47+
(torch.randn(1, 4, 8, 8, 8),),
48+
flow,
49+
)
50+
self._test_op(
51+
Model(output_size=(1, 1, 1)),
52+
(torch.randn(1, 4, 8, 8, 8),),
53+
flow,
54+
)
55+
self._test_op(
56+
Model(output_size=(6, 6, 6)),
57+
(torch.randn(1, 4, 8, 8, 8),),
58+
flow,
59+
)
60+
self._test_op(
61+
Model(output_size=(2, 4, 6)),
62+
(torch.randn(1, 4, 8, 8, 8),),
63+
flow,
64+
)
65+
66+
def test_adaptive_avgpool3d_batch_sizes(self, flow: TestFlow) -> None:
67+
# Test with batch inputs
68+
self._test_op(
69+
Model(),
70+
(torch.randn(2, 4, 8, 8, 8),),
71+
flow,
72+
)
73+
self._test_op(
74+
Model(),
75+
(torch.randn(8, 4, 8, 8, 8),),
76+
flow,
77+
)
78+
self._test_op(
79+
Model(),
80+
(torch.randn(16, 4, 8, 8, 8),),
81+
flow,
82+
)
83+
84+
def test_adaptive_avgpool3d_input_sizes(self, flow: TestFlow) -> None:
85+
# Test with different input sizes
86+
self._test_op(
87+
Model(),
88+
(torch.randn(1, 2, 8, 8, 8),),
89+
flow,
90+
)
91+
self._test_op(
92+
Model(),
93+
(torch.randn(1, 8, 8, 8, 8),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(1, 4, 6, 6, 6),),
99+
flow,
100+
)
101+
self._test_op(
102+
Model(),
103+
(torch.randn(1, 4, 10, 10, 10),),
104+
flow,
105+
)
106+
self._test_op(
107+
Model(),
108+
(torch.randn(1, 4, 7, 9, 11),),
109+
flow,
110+
)

0 commit comments

Comments
 (0)