Skip to content

Commit 21d346f

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

File tree

3 files changed

+389
-0
lines changed

3 files changed

+389
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
return_indices=False,
24+
):
25+
super().__init__()
26+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool1d(
27+
output_size=output_size,
28+
return_indices=return_indices,
29+
)
30+
31+
def forward(self, x):
32+
return self.adaptive_maxpool(x)
33+
34+
@operator_test
35+
class AdaptiveMaxPool1d(OperatorTest):
36+
@dtype_test
37+
def test_adaptive_maxpool1d_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+
)
44+
45+
def test_adaptive_maxpool1d_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+
)
62+
63+
def test_adaptive_maxpool1d_return_indices(self, flow: TestFlow) -> None:
64+
# Test with return_indices=True
65+
class ModelWithIndices(torch.nn.Module):
66+
def __init__(self):
67+
super().__init__()
68+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool1d(
69+
output_size=5,
70+
return_indices=True,
71+
)
72+
73+
def forward(self, x):
74+
return self.adaptive_maxpool(x)
75+
76+
input_tensor = torch.randn(1, 8, 100)
77+
78+
self._test_op(
79+
ModelWithIndices(),
80+
(input_tensor,),
81+
flow,
82+
)
83+
84+
def test_adaptive_maxpool1d_batch_sizes(self, flow: TestFlow) -> None:
85+
# Test with batch inputs
86+
self._test_op(
87+
Model(),
88+
(torch.randn(2, 8, 100),),
89+
flow,
90+
)
91+
self._test_op(
92+
Model(),
93+
(torch.randn(8, 8, 100),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(16, 8, 100),),
99+
flow,
100+
)
101+
102+
def test_adaptive_maxpool1d_input_sizes(self, flow: TestFlow) -> None:
103+
# Test with different input sizes
104+
self._test_op(
105+
Model(),
106+
(torch.randn(1, 4, 100),),
107+
flow,
108+
)
109+
self._test_op(
110+
Model(),
111+
(torch.randn(1, 16, 100),),
112+
flow,
113+
)
114+
self._test_op(
115+
Model(),
116+
(torch.randn(1, 8, 50),),
117+
flow,
118+
)
119+
self._test_op(
120+
Model(),
121+
(torch.randn(1, 8, 200),),
122+
flow,
123+
)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
return_indices=False,
24+
):
25+
super().__init__()
26+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool2d(
27+
output_size=output_size,
28+
return_indices=return_indices,
29+
)
30+
31+
def forward(self, x):
32+
return self.adaptive_maxpool(x)
33+
34+
@operator_test
35+
class AdaptiveMaxPool2d(OperatorTest):
36+
@dtype_test
37+
def test_adaptive_maxpool2d_dtype(self, flow: TestFlow, dtype) -> None:
38+
# Input shape: (batch_size, channels, height, width)
39+
self._test_op(
40+
Model().to(dtype),
41+
((torch.rand(1, 8, 20, 20) * 10).to(dtype),),
42+
flow,
43+
)
44+
45+
def test_adaptive_maxpool2d_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, 20, 20),),
50+
flow,
51+
)
52+
self._test_op(
53+
Model(output_size=(1, 1)),
54+
(torch.randn(1, 8, 20, 20),),
55+
flow,
56+
)
57+
self._test_op(
58+
Model(output_size=(10, 10)),
59+
(torch.randn(1, 8, 20, 20),),
60+
flow,
61+
)
62+
self._test_op(
63+
Model(output_size=(5, 10)),
64+
(torch.randn(1, 8, 20, 20),),
65+
flow,
66+
)
67+
68+
def test_adaptive_maxpool2d_return_indices(self, flow: TestFlow) -> None:
69+
# Test with return_indices=True
70+
class ModelWithIndices(torch.nn.Module):
71+
def __init__(self):
72+
super().__init__()
73+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool2d(
74+
output_size=(5, 5),
75+
return_indices=True,
76+
)
77+
78+
def forward(self, x):
79+
return self.adaptive_maxpool(x)
80+
81+
input_tensor = torch.randn(1, 8, 20, 20)
82+
83+
self._test_op(
84+
ModelWithIndices(),
85+
(input_tensor,),
86+
flow,
87+
)
88+
89+
def test_adaptive_maxpool2d_batch_sizes(self, flow: TestFlow) -> None:
90+
# Test with batch inputs
91+
self._test_op(
92+
Model(),
93+
(torch.randn(2, 8, 20, 20),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(8, 8, 20, 20),),
99+
flow,
100+
)
101+
self._test_op(
102+
Model(),
103+
(torch.randn(16, 8, 20, 20),),
104+
flow,
105+
)
106+
107+
def test_adaptive_maxpool2d_input_sizes(self, flow: TestFlow) -> None:
108+
# Test with different input sizes
109+
self._test_op(
110+
Model(),
111+
(torch.randn(1, 4, 20, 20),),
112+
flow,
113+
)
114+
self._test_op(
115+
Model(),
116+
(torch.randn(1, 16, 20, 20),),
117+
flow,
118+
)
119+
self._test_op(
120+
Model(),
121+
(torch.randn(1, 8, 10, 10),),
122+
flow,
123+
)
124+
self._test_op(
125+
Model(),
126+
(torch.randn(1, 8, 30, 30),),
127+
flow,
128+
)
129+
self._test_op(
130+
Model(),
131+
(torch.randn(1, 8, 15, 25),),
132+
flow,
133+
)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
return_indices=False,
24+
):
25+
super().__init__()
26+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool3d(
27+
output_size=output_size,
28+
return_indices=return_indices,
29+
)
30+
31+
def forward(self, x):
32+
return self.adaptive_maxpool(x)
33+
34+
@operator_test
35+
class AdaptiveMaxPool3d(OperatorTest):
36+
@dtype_test
37+
def test_adaptive_maxpool3d_dtype(self, flow: TestFlow, dtype) -> None:
38+
# Input shape: (batch_size, channels, depth, height, width)
39+
self._test_op(
40+
Model().to(dtype),
41+
((torch.rand(1, 4, 8, 8, 8) * 10).to(dtype),),
42+
flow,
43+
)
44+
45+
def test_adaptive_maxpool3d_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, 4, 8, 8, 8),),
50+
flow,
51+
)
52+
self._test_op(
53+
Model(output_size=(1, 1, 1)),
54+
(torch.randn(1, 4, 8, 8, 8),),
55+
flow,
56+
)
57+
self._test_op(
58+
Model(output_size=(6, 6, 6)),
59+
(torch.randn(1, 4, 8, 8, 8),),
60+
flow,
61+
)
62+
self._test_op(
63+
Model(output_size=(2, 4, 6)),
64+
(torch.randn(1, 4, 8, 8, 8),),
65+
flow,
66+
)
67+
68+
def test_adaptive_maxpool3d_return_indices(self, flow: TestFlow) -> None:
69+
# Test with return_indices=True
70+
class ModelWithIndices(torch.nn.Module):
71+
def __init__(self):
72+
super().__init__()
73+
self.adaptive_maxpool = torch.nn.AdaptiveMaxPool3d(
74+
output_size=(4, 4, 4),
75+
return_indices=True,
76+
)
77+
78+
def forward(self, x):
79+
return self.adaptive_maxpool(x)
80+
81+
input_tensor = torch.randn(1, 4, 8, 8, 8)
82+
83+
self._test_op(
84+
ModelWithIndices(),
85+
(input_tensor,),
86+
flow,
87+
)
88+
89+
def test_adaptive_maxpool3d_batch_sizes(self, flow: TestFlow) -> None:
90+
# Test with batch inputs
91+
self._test_op(
92+
Model(),
93+
(torch.randn(2, 4, 8, 8, 8),),
94+
flow,
95+
)
96+
self._test_op(
97+
Model(),
98+
(torch.randn(8, 4, 8, 8, 8),),
99+
flow,
100+
)
101+
self._test_op(
102+
Model(),
103+
(torch.randn(16, 4, 8, 8, 8),),
104+
flow,
105+
)
106+
107+
def test_adaptive_maxpool3d_input_sizes(self, flow: TestFlow) -> None:
108+
# Test with different input sizes
109+
self._test_op(
110+
Model(),
111+
(torch.randn(1, 2, 8, 8, 8),),
112+
flow,
113+
)
114+
self._test_op(
115+
Model(),
116+
(torch.randn(1, 8, 8, 8, 8),),
117+
flow,
118+
)
119+
self._test_op(
120+
Model(),
121+
(torch.randn(1, 4, 6, 6, 6),),
122+
flow,
123+
)
124+
self._test_op(
125+
Model(),
126+
(torch.randn(1, 4, 10, 10, 10),),
127+
flow,
128+
)
129+
self._test_op(
130+
Model(),
131+
(torch.randn(1, 4, 7, 9, 11),),
132+
flow,
133+
)

0 commit comments

Comments
 (0)