Skip to content

Commit 364d063

Browse files
committed
Remove --quantize_io pytest option
In most test cases we need the quantized_ops_aot lib which this flag toggles loading. Instead, always load the quantized_ops_aot lib, unless we are only doing collection. Signed-off-by: Erik Lundell <[email protected]> Change-Id: I820b5decdf12a5825f4e52a0c0412bbfaf959761
1 parent 79d1b27 commit 364d063

File tree

7 files changed

+39
-56
lines changed

7 files changed

+39
-56
lines changed

backends/arm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ backends/arm/test/setup_testing.sh
119119
The you can run the tests with
120120

121121
```
122-
pytest -c /dev/null -v -n auto backends/arm/test --arm_quantize_io --arm_run_corstoneFVP
122+
pytest -c /dev/null -v -n auto backends/arm/test --arm_run_corstoneFVP
123123
```
124124

125125
### Code coverage

backends/arm/test/common.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
# All rights reserved.
33
#
44
# This source code is licensed under the BSD-style license found in the
@@ -12,8 +12,6 @@
1212
from pathlib import Path
1313

1414
from executorch.backends.arm.arm_backend import ArmCompileSpecBuilder
15-
16-
from executorch.backends.arm.test.conftest import is_option_enabled
1715
from executorch.exir.backend.compile_spec_schema import CompileSpec
1816

1917

@@ -90,7 +88,7 @@ def get_tosa_compile_spec_unbuilt(
9088

9189
def get_u55_compile_spec(
9290
permute_memory_to_nhwc=True,
93-
quantize_io=False,
91+
quantize_io=True,
9492
custom_path=None,
9593
reorder_inputs=None,
9694
) -> list[CompileSpec]:
@@ -107,7 +105,7 @@ def get_u55_compile_spec(
107105

108106
def get_u85_compile_spec(
109107
permute_memory_to_nhwc=True,
110-
quantize_io=False,
108+
quantize_io=True,
111109
custom_path=None,
112110
reorder_inputs=None,
113111
) -> list[CompileSpec]:
@@ -124,7 +122,7 @@ def get_u85_compile_spec(
124122

125123
def get_u55_compile_spec_unbuilt(
126124
permute_memory_to_nhwc=True,
127-
quantize_io=False,
125+
quantize_io=True,
128126
custom_path=None,
129127
reorder_inputs=None,
130128
) -> ArmCompileSpecBuilder:
@@ -142,7 +140,7 @@ def get_u55_compile_spec_unbuilt(
142140
memory_mode="Shared_Sram",
143141
extra_flags="--debug-force-regor --output-format=raw",
144142
)
145-
.set_quantize_io(is_option_enabled("quantize_io") or quantize_io)
143+
.set_quantize_io(quantize_io)
146144
.set_permute_memory_format(permute_memory_to_nhwc)
147145
.dump_intermediate_artifacts_to(artifact_path)
148146
.set_input_order(reorder_inputs)
@@ -152,7 +150,7 @@ def get_u55_compile_spec_unbuilt(
152150

153151
def get_u85_compile_spec_unbuilt(
154152
permute_memory_to_nhwc=True,
155-
quantize_io=False,
153+
quantize_io=True,
156154
custom_path=None,
157155
reorder_inputs=None,
158156
) -> list[CompileSpec]:
@@ -168,7 +166,7 @@ def get_u85_compile_spec_unbuilt(
168166
memory_mode="Shared_Sram",
169167
extra_flags="--output-format=raw",
170168
)
171-
.set_quantize_io(is_option_enabled("quantize_io") or quantize_io)
169+
.set_quantize_io(quantize_io)
172170
.set_permute_memory_format(permute_memory_to_nhwc)
173171
.dump_intermediate_artifacts_to(artifact_path)
174172
.set_input_order(reorder_inputs)

backends/arm/test/conftest.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
77
import os
88
import platform
99
import random
10-
import re
1110
import shutil
1211
import subprocess
1312
import sys
@@ -25,46 +24,34 @@
2524

2625

2726
def pytest_configure(config):
28-
pytest._test_options = {}
2927

30-
if config.option.arm_quantize_io:
31-
_load_libquantized_ops_aot_lib()
32-
pytest._test_options["quantize_io"] = True
28+
pytest._test_options = {} # type: ignore[attr-defined]
29+
3330
if config.option.arm_run_corstoneFVP:
3431
corstone300_exists = shutil.which("FVP_Corstone_SSE-300_Ethos-U55")
3532
corstone320_exists = shutil.which("FVP_Corstone_SSE-320")
3633
if not (corstone300_exists and corstone320_exists):
3734
raise RuntimeError(
3835
"Tests are run with --arm_run_corstoneFVP but corstone FVP is not installed."
3936
)
40-
pytest._test_options["corstone_fvp"] = True
41-
pytest._test_options["fast_fvp"] = config.option.fast_fvp
37+
pytest._test_options["corstone_fvp"] = True # type: ignore[attr-defined]
38+
pytest._test_options["fast_fvp"] = config.option.fast_fvp # type: ignore[attr-defined]
4239
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
4340

4441

4542
def pytest_collection_modifyitems(config, items):
46-
"""
47-
Skip all tests that require run on Ethos-U if the option arm_quantize_io is
48-
not set.
49-
"""
50-
if not config.option.arm_quantize_io:
51-
skip_if_aot_lib_not_loaded = pytest.mark.skip(
52-
"Ethos-U tests can only run on FVP with quantize_io=True."
53-
)
54-
55-
for item in items:
56-
if re.search(r"u55|u65|u85", item.name, re.IGNORECASE):
57-
item.add_marker(skip_if_aot_lib_not_loaded)
43+
pass
5844

5945

6046
def pytest_addoption(parser):
61-
parser.addoption("--arm_quantize_io", action="store_true")
47+
parser.addoption("--arm_quantize_io", action="store_true", help="Deprecated.")
6248
parser.addoption("--arm_run_corstoneFVP", action="store_true")
6349
parser.addoption("--fast_fvp", action="store_true")
6450

6551

6652
def pytest_sessionstart(session):
67-
pass
53+
if not session.config.option.collectonly:
54+
_load_libquantized_ops_aot_lib()
6855

6956

7057
def pytest_sessionfinish(session, exitstatus):
@@ -128,15 +115,12 @@ def is_option_enabled(option: str, fail_if_not_enabled: bool = False) -> bool:
128115
"""
129116
Returns whether an option is successfully enabled, i.e. if the flag was
130117
given to pytest and the necessary requirements are available.
131-
Implemented options are:
132-
- corstone_fvp.
133-
- quantize_io.
134118
135119
The optional parameter 'fail_if_not_enabled' makes the function raise
136120
a RuntimeError instead of returning False.
137121
"""
138122

139-
if option in pytest._test_options and pytest._test_options[option]:
123+
if option in pytest._test_options and pytest._test_options[option]: # type: ignore[attr-defined]
140124
return True
141125
else:
142126
if fail_if_not_enabled:
@@ -152,15 +136,14 @@ def get_option(option: str) -> Any | None:
152136
Args:
153137
option (str): The option to check for.
154138
"""
155-
if option in pytest._test_options:
156-
return pytest._test_options[option]
139+
if option in pytest._test_options: # type: ignore[attr-defined]
140+
return pytest._test_options[option] # type: ignore[attr-defined]
157141
return None
158142

159143

160144
def _load_libquantized_ops_aot_lib():
161145
"""
162-
Load the libquantized_ops_aot_lib shared library. It's required when
163-
arm_quantize_io is set.
146+
Find and load the libquantized_ops_aot_lib shared library.
164147
"""
165148
so_ext = {
166149
"Darwin": "dylib",
@@ -181,5 +164,5 @@ def _load_libquantized_ops_aot_lib():
181164
torch.ops.load_library(library_path)
182165
else:
183166
raise RuntimeError(
184-
f"Failed to load libquantized_ops_aot_lib.{so_ext}. Did you build it?"
167+
f"Did not find libquantized_ops_aot_lib.{so_ext} in cmake-out-aot-lib. Did you build it?"
185168
)

backends/arm/test/ops/test_depthwise_conv.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Arm Limited and/or its affiliates.
1+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
22
# All rights reserved.
33
#
44
# This source code is licensed under the BSD-style license found in the
@@ -265,7 +265,7 @@ def test_dw_conv_tosa_BI(self, test_name: str, model: torch.nn.Module):
265265
@pytest.mark.corstone_fvp
266266
@unittest.expectedFailure
267267
def test_dw_conv2d_u55_BI(
268-
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False
268+
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = True
269269
):
270270
self._test_dw_conv_ethos_BI_pipeline(
271271
model,
@@ -281,7 +281,7 @@ def test_dw_conv2d_u55_BI(
281281
@pytest.mark.corstone_fvp
282282
@unittest.expectedFailure
283283
def test_dw_conv1d_u55_BI(
284-
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False
284+
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = True
285285
):
286286
self._test_dw_conv_ethos_BI_pipeline(
287287
model,
@@ -294,7 +294,7 @@ def test_dw_conv1d_u55_BI(
294294
@parameterized.expand(testsuite_conv1d + testsuite_conv2d_u85)
295295
@pytest.mark.corstone_fvp
296296
def test_dw_conv_u85_BI(
297-
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False
297+
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = True
298298
):
299299
self._test_dw_conv_ethos_BI_pipeline(
300300
model,
@@ -309,7 +309,7 @@ def test_dw_conv_u85_BI(
309309
@pytest.mark.corstone_fvp
310310
@conftest.expectedFailureOnFVP
311311
def test_dw_conv_u85_BI_xfails(
312-
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False
312+
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = True
313313
):
314314
self._test_dw_conv_ethos_BI_pipeline(
315315
model,

backends/arm/test/ops/test_maximum.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# Copyright 2024 Arm Limited and/or its affiliates.
2+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
33
# All rights reserved.
44
#
55
# This source code is licensed under the BSD-style license found in the
@@ -10,7 +10,7 @@
1010
from typing import Tuple
1111

1212
import torch
13-
from executorch.backends.arm.test import common
13+
from executorch.backends.arm.test import common, conftest
1414
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1515
from executorch.exir import EdgeCompileConfig
1616
from executorch.exir.backend.compile_spec_schema import CompileSpec
@@ -120,7 +120,7 @@ def test_maximum_u55_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
120120
tester = self._test_maximum_ethos_BI_pipeline(
121121
self.Maximum(), common.get_u55_compile_spec(), test_data
122122
)
123-
if common.is_option_enabled("corstone_fvp"):
123+
if conftest.is_option_enabled("corstone_fvp"):
124124
tester.run_method_and_compare_outputs(
125125
qtol=1, inputs=test_data, target_board="corstone-300"
126126
)
@@ -131,7 +131,7 @@ def test_maximum_u85_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
131131
tester = self._test_maximum_ethos_BI_pipeline(
132132
self.Maximum(), common.get_u85_compile_spec(), test_data
133133
)
134-
if common.is_option_enabled("corstone_fvp"):
134+
if conftest.is_option_enabled("corstone_fvp"):
135135
tester.run_method_and_compare_outputs(
136136
qtol=1, inputs=test_data, target_board="corstone-320"
137137
)

backends/arm/test/ops/test_minimum.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# Copyright 2024 Arm Limited and/or its affiliates.
2+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
33
# All rights reserved.
44
#
55
# This source code is licensed under the BSD-style license found in the
@@ -10,7 +10,7 @@
1010
from typing import Tuple
1111

1212
import torch
13-
from executorch.backends.arm.test import common
13+
from executorch.backends.arm.test import common, conftest
1414
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1515
from executorch.exir import EdgeCompileConfig
1616
from executorch.exir.backend.compile_spec_schema import CompileSpec
@@ -120,7 +120,7 @@ def test_minimum_u55_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
120120
tester = self._test_minimum_ethos_BI_pipeline(
121121
self.Minimum(), common.get_u55_compile_spec(), test_data
122122
)
123-
if common.is_option_enabled("corstone_fvp"):
123+
if conftest.is_option_enabled("corstone_fvp"):
124124
tester.run_method_and_compare_outputs(
125125
qtol=1, inputs=test_data, target_board="corstone-300"
126126
)
@@ -131,7 +131,7 @@ def test_minimum_u85_BI(self, operand1: torch.Tensor, operand2: torch.Tensor):
131131
tester = self._test_minimum_ethos_BI_pipeline(
132132
self.Minimum(), common.get_u85_compile_spec(), test_data
133133
)
134-
if common.is_option_enabled("corstone_fvp"):
134+
if conftest.is_option_enabled("corstone_fvp"):
135135
tester.run_method_and_compare_outputs(
136136
qtol=1, inputs=test_data, target_board="corstone-320"
137137
)

backends/arm/test/test_arm_baremetal.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2024 Arm Limited and/or its affiliates.
2+
# Copyright 2024-2025 Arm Limited and/or its affiliates.
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
@@ -63,6 +63,8 @@ test_pytest() { # Test ops and other things
6363
echo "${TEST_SUITE_NAME}: Run pytest"
6464
cd "${et_root_dir}"
6565
source examples/arm/ethos-u-scratch/setup_path.sh
66+
#TODO: only quantized_op_aot lib is needed here.
67+
examples/arm/run.sh --model_name=add --build_only
6668

6769
# Run arm baremetal pytest tests without FVP
6870
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/
@@ -78,7 +80,7 @@ test_pytest_ethosu_fvp() { # Same as test_pytest but also sometime verify using
7880
backends/arm/test/setup_testing.sh
7981

8082
# Run arm baremetal pytest tests with FVP
81-
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/ --arm_quantize_io --arm_run_corstoneFVP
83+
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/ --arm_run_corstoneFVP
8284
}
8385

8486
test_run_ethosu_fvp() { # End to End model tests

0 commit comments

Comments
 (0)