Skip to content

Commit b132700

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr_conv_combos
Change-Id: Icc219071e99fbb86848d3f871feb12c67535f93c
2 parents 18c5c3c + bd6ceab commit b132700

Some content is hidden

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

44 files changed

+1531
-713
lines changed

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a52b4e22571507abc35c2d47de138497190d2e0a
1+
0a038cf0cff2d071b7359ac0491fd2ba7798a438

.github/workflows/_unittest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
# Setup MacOS dependencies as there is no Docker support on MacOS atm
3838
PYTHON_EXECUTABLE=python \
3939
EXECUTORCH_BUILD_PYBIND=ON \
40+
EXECUTORCH_BUILD_XNNPACK=ON \
4041
.ci/scripts/setup-linux.sh "${BUILD_TOOL}"
4142
4243
# Run pytest with coverage

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
# build module for executorch.extension.pybindings.portable_lib
233233
BUILD_TOOL=${{ matrix.build-tool }}
234234
PYTHON_EXECUTABLE=python \
235+
EXECUTORCH_BUILD_XNNPACK=ON \
235236
EXECUTORCH_BUILD_PYBIND=ON \
236237
bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
237238

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,9 @@ if(EXECUTORCH_BUILD_PYBIND)
508508
endif()
509509

510510
if(EXECUTORCH_BUILD_XNNPACK)
511-
set(PYBIND_LINK_XNNPACK "xnnpack_backend")
511+
# need to explicitly specify XNNPACK here
512+
# otherwise uses XNNPACK symbols from libtorch_cpu
513+
set(PYBIND_LINK_XNNPACK xnnpack_backend XNNPACK)
512514
endif()
513515

514516
# find pytorch lib, to allow pybind to take at::Tensor as input/output
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# Copyright 2024 Arm Limited and/or its affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
import logging
9+
import unittest
10+
11+
from typing import Tuple
12+
13+
import torch
14+
from executorch.backends.arm.test import common
15+
from executorch.backends.arm.test.test_models import TosaProfile
16+
from executorch.backends.arm.test.tester.arm_tester import ArmBackendSelector, ArmTester
17+
from parameterized import parameterized
18+
19+
logger = logging.getLogger(__name__)
20+
logger.setLevel(logging.INFO)
21+
22+
test_data_suite = [
23+
# (test_name, test_data, [kernel_size, stride, padding])
24+
("zeros", torch.zeros(20, 16, 50, 32), [4, 2, 0]),
25+
("ones", torch.zeros(20, 16, 50, 32), [4, 2, 0]),
26+
("rand", torch.rand(20, 16, 50, 32), [4, 2, 0]),
27+
("randn", torch.randn(20, 16, 50, 32), [4, 2, 0]),
28+
]
29+
30+
31+
class TestAvgPool2d(unittest.TestCase):
32+
class AvgPool2d(torch.nn.Module):
33+
def __init__(
34+
self,
35+
kernel_size: int | Tuple[int, int],
36+
stride: int | Tuple[int, int],
37+
padding: int | Tuple[int, int],
38+
):
39+
super().__init__()
40+
self.avg_pool_2d = torch.nn.AvgPool2d(
41+
kernel_size=kernel_size, stride=stride, padding=padding
42+
)
43+
44+
def forward(self, x):
45+
return self.avg_pool_2d(x)
46+
47+
def _test_avgpool2d_tosa_MI_pipeline(
48+
self, module: torch.nn.Module, test_data: Tuple[torch.tensor]
49+
):
50+
tester = (
51+
ArmTester(
52+
module,
53+
inputs=test_data,
54+
profile=TosaProfile.MI,
55+
backend=ArmBackendSelector.TOSA,
56+
permute_memory_to_nhwc=True,
57+
)
58+
.export()
59+
.check(["torch.ops.aten.avg_pool2d.default"])
60+
.check_not(["torch.ops.quantized_decomposed"])
61+
.to_edge()
62+
.partition()
63+
.check_not(["executorch_exir_dialects_edge__ops_aten_avg_pool2d_default"])
64+
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
65+
.to_executorch()
66+
)
67+
if common.TOSA_REF_MODEL_INSTALLED:
68+
tester.run_method().compare_outputs()
69+
else:
70+
logger.warning(
71+
"TOSA ref model tool not installed, skip numerical correctness tests"
72+
)
73+
74+
def _test_avgpool2d_tosa_BI_pipeline(
75+
self, module: torch.nn.Module, test_data: Tuple[torch.tensor]
76+
):
77+
tester = (
78+
ArmTester(
79+
module,
80+
inputs=test_data,
81+
profile=TosaProfile.BI,
82+
backend=ArmBackendSelector.TOSA,
83+
permute_memory_to_nhwc=True,
84+
)
85+
.quantize()
86+
.export()
87+
.check_count({"torch.ops.aten.avg_pool2d.default": 1})
88+
.check(["torch.ops.quantized_decomposed"])
89+
.to_edge()
90+
.partition()
91+
.check_not(["executorch_exir_dialects_edge__ops_aten_avg_pool2d_default"])
92+
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
93+
.to_executorch()
94+
)
95+
if common.TOSA_REF_MODEL_INSTALLED:
96+
tester.run_method().compare_outputs(qtol=1)
97+
else:
98+
logger.warning(
99+
"TOSA ref model tool not installed, skip numerical correctness tests"
100+
)
101+
102+
def _test_avgpool2d_tosa_u55_BI_pipeline(
103+
self, module: torch.nn.Module, test_data: Tuple[torch.tensor]
104+
):
105+
(
106+
ArmTester(
107+
module,
108+
inputs=test_data,
109+
profile=TosaProfile.BI,
110+
backend=ArmBackendSelector.ETHOS_U55,
111+
permute_memory_to_nhwc=True,
112+
)
113+
.quantize()
114+
.export()
115+
.check_count({"torch.ops.aten.avg_pool2d.default": 1})
116+
.check(["torch.ops.quantized_decomposed"])
117+
.to_edge()
118+
.partition()
119+
.check_not(["executorch_exir_dialects_edge__ops_aten_avg_pool2d_default"])
120+
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
121+
.to_executorch()
122+
)
123+
124+
@parameterized.expand(test_data_suite)
125+
def test_avgpool2d_tosa_MI(
126+
self,
127+
test_name: str,
128+
test_data: torch.Tensor,
129+
model_params: int | Tuple[int, int],
130+
):
131+
self._test_avgpool2d_tosa_MI_pipeline(
132+
self.AvgPool2d(*model_params), (test_data,)
133+
)
134+
135+
# Expected to fail since ArmQuantizer cannot quantize a AvgPool2D layer
136+
# TODO(MLETORCH-93)
137+
@parameterized.expand(test_data_suite)
138+
@unittest.expectedFailure
139+
def test_avgpool2d_tosa_BI(
140+
self,
141+
test_name: str,
142+
test_data: torch.Tensor,
143+
model_params: int | Tuple[int, int],
144+
):
145+
self._test_avgpool2d_tosa_BI_pipeline(
146+
self.AvgPool2d(*model_params), (test_data,)
147+
)
148+
149+
# Expected to fail since ArmQuantizer cannot quantize a AvgPool2D layer
150+
# TODO(MLETORCH-93)
151+
@parameterized.expand(test_data_suite)
152+
@unittest.skipIf(
153+
not common.VELA_INSTALLED,
154+
"There is no point in running U55 tests if the Vela tool is not installed",
155+
)
156+
@unittest.expectedFailure
157+
def test_avgpool2d_tosa_u55_BI(
158+
self,
159+
test_name: str,
160+
test_data: torch.Tensor,
161+
model_params: int | Tuple[int, int],
162+
):
163+
self._test_avgpool2d_tosa_u55_BI_pipeline(
164+
self.AvgPool2d(*model_params), (test_data,)
165+
)

backends/arm/test/ops/test_linear.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,42 @@
2020
logger.setLevel(logging.INFO)
2121

2222

23-
test_data_suite = [
23+
test_data_suite_rank1 = [
2424
# (test_name, test_data, out_features)
2525
(
2626
"model_linear_rank1_zeros",
27-
torch.zeros(10, 10),
27+
torch.zeros(10),
2828
10,
2929
),
3030
(
3131
"model_linear_rank1_ones",
32-
torch.ones(10, 10),
32+
torch.ones(10),
3333
10,
3434
),
3535
(
3636
"model_linear_rank1_negative_ones",
37-
torch.ones(10, 10) * (-1),
37+
torch.ones(10) * (-1),
3838
10,
3939
),
4040
(
4141
"model_linear_rank1_rand",
42-
torch.rand(10, 10),
42+
torch.rand(10),
4343
10,
4444
),
4545
(
4646
"model_linear_rank1_negative_large_rand",
47-
torch.rand(10, 10) * (-100),
47+
torch.rand(10) * (-100),
4848
10,
4949
),
5050
(
5151
"model_linear_rank1_large_randn",
52-
torch.randn(10, 10) * 100,
52+
torch.randn(10) * 100,
5353
10,
5454
),
55+
]
56+
57+
test_data_suite_rank4 = [
58+
# (test_name, test_data, out_features)
5559
(
5660
"model_linear_rank4_zeros",
5761
torch.zeros(5, 10, 25, 20),
@@ -174,7 +178,7 @@ def _test_linear_tosa_u55_BI_pipeline(
174178
.to_executorch()
175179
)
176180

177-
@parameterized.expand(test_data_suite)
181+
@parameterized.expand(test_data_suite_rank1 + test_data_suite_rank4)
178182
def test_linear_tosa_MI(
179183
self,
180184
test_name: str,
@@ -191,7 +195,7 @@ def test_linear_tosa_MI(
191195
test_data,
192196
)
193197

194-
@parameterized.expand(test_data_suite)
198+
@parameterized.expand(test_data_suite_rank1 + test_data_suite_rank4)
195199
def test_linear_tosa_BI(
196200
self,
197201
test_name: str,
@@ -204,8 +208,11 @@ def test_linear_tosa_BI(
204208
self.Linear(in_features=in_features, out_features=out_features), test_data
205209
)
206210

207-
@parameterized.expand(test_data_suite)
208-
@unittest.skip("This does not work as of now")
211+
@parameterized.expand(test_data_suite_rank1)
212+
@unittest.skipIf(
213+
not common.VELA_INSTALLED,
214+
"There is no point in running U55 tests if the Vela tool is not installed",
215+
)
209216
def test_linear_tosa_u55_BI(
210217
self,
211218
test_name: str,

0 commit comments

Comments
 (0)