Skip to content

Commit 577e592

Browse files
committed
Update
[ghstack-poisoned]
2 parents d85863c + 88b3441 commit 577e592

File tree

7 files changed

+100
-13
lines changed

7 files changed

+100
-13
lines changed

.ci/scripts/unittest-linux.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
4141

4242
.ci/scripts/unittest-linux-cmake.sh
4343
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
44-
# XXX: check whether this is sufficient to unbreak sccache
44+
# Removing this breaks sccache in the Buck build, apparently
45+
# because TMPDIR gets messed up? Please feel free to fix this and
46+
# speed up this CI job!
4547
PYTHON_EXECUTABLE=python \
4648
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
4749

backends/arm/test/TARGETS

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
2+
load(":targets.bzl", "define_arm_tests")
3+
4+
5+
oncall("executorch")
26

37
python_library(
48
name = "conftest",
59
srcs = ["conftest.py"],
610
deps = [
711
"//executorch/exir:lib",
12+
"//executorch/exir/backend:compile_spec_schema",
13+
"fbsource//third-party/pypi/pytest:pytest",
814
]
915
)
1016

@@ -33,6 +39,19 @@ python_library(
3339
]
3440
)
3541

42+
python_library(
43+
name = "common",
44+
srcs = ["common.py"],
45+
deps = [
46+
":runner_utils",
47+
"//executorch/backends/xnnpack/test/tester:tester",
48+
"//executorch/backends/arm:arm_backend",
49+
"//executorch/exir:lib",
50+
"//executorch/exir/backend:compile_spec_schema",
51+
"fbsource//third-party/pypi/pytest:pytest",
52+
]
53+
)
54+
3655
python_library(
3756
name = "arm_tester",
3857
srcs = glob(["tester/*.py"]),
@@ -42,7 +61,10 @@ python_library(
4261
"//executorch/backends/arm:tosa_mapping",
4362
"//executorch/backends/arm:tosa_specification",
4463
"//executorch/backends/arm/quantizer:arm_quantizer",
64+
"//executorch/backends/arm:arm_partitioner",
4565
"//executorch/devtools/backend_debug:delegation_info",
4666
"fbsource//third-party/pypi/tabulate:tabulate",
4767
]
4868
)
69+
70+
define_arm_tests()

backends/arm/test/conftest.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
from typing import Any
1414

1515
import pytest
16-
import torch
16+
17+
try:
18+
import tosa_reference_model
19+
except ImportError:
20+
logging.warning("tosa_reference_model not found, can't run reference model tests")
21+
tosa_reference_model = None
1722

1823
"""
1924
This file contains the pytest hooks, fixtures etc. for the Arm test suite.
@@ -24,18 +29,29 @@
2429

2530

2631
def pytest_configure(config):
27-
2832
pytest._test_options = {} # type: ignore[attr-defined]
29-
30-
if config.option.arm_run_corstoneFVP:
33+
pytest._test_options["corstone_fvp"] = False # type: ignore[attr-defined]
34+
if (
35+
getattr(config.option, "arm_run_corestoneFVP", False)
36+
and config.option.arm_run_corstoneFVP
37+
):
3138
corstone300_exists = shutil.which("FVP_Corstone_SSE-300_Ethos-U55")
3239
corstone320_exists = shutil.which("FVP_Corstone_SSE-320")
3340
if not (corstone300_exists and corstone320_exists):
3441
raise RuntimeError(
3542
"Tests are run with --arm_run_corstoneFVP but corstone FVP is not installed."
3643
)
44+
# Only enable if we also have the TOSA reference model available.
3745
pytest._test_options["corstone_fvp"] = True # type: ignore[attr-defined]
38-
pytest._test_options["fast_fvp"] = config.option.fast_fvp # type: ignore[attr-defined]
46+
47+
pytest._test_options["fast_fvp"] = False # type: ignore[attr-defined]
48+
if getattr(config.option, "fast_fvp", False):
49+
pytest._test_options["fast_fvp"] = config.option.fast_fvp # type: ignore[attr-defined]
50+
51+
# TODO: remove this flag once we have a way to run the reference model tests with Buck
52+
pytest._test_options["tosa_ref_model"] = False # type: ignore[attr-defined]
53+
if tosa_reference_model is not None:
54+
pytest._test_options["tosa_ref_model"] = True # type: ignore[attr-defined]
3955
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
4056

4157

@@ -44,9 +60,15 @@ def pytest_collection_modifyitems(config, items):
4460

4561

4662
def pytest_addoption(parser):
47-
parser.addoption("--arm_quantize_io", action="store_true", help="Deprecated.")
48-
parser.addoption("--arm_run_corstoneFVP", action="store_true")
49-
parser.addoption("--fast_fvp", action="store_true")
63+
def try_addoption(*args, **kwargs):
64+
try:
65+
parser.addoption(*args, **kwargs)
66+
except Exception:
67+
pass
68+
69+
try_addoption("--arm_quantize_io", action="store_true", help="Deprecated.")
70+
try_addoption("--arm_run_corstoneFVP", action="store_true", help="Deprecated.")
71+
try_addoption("--fast_fvp", action="store_true")
5072

5173

5274
def pytest_sessionstart(session):
@@ -78,6 +100,8 @@ def set_random_seed():
78100
Rerun with a specific seed found under a random seed test
79101
ARM_TEST_SEED=3478246 pytest --config-file=/dev/null --verbose -s --color=yes backends/arm/test/ops/test_avg_pool.py -k <TESTCASE>
80102
"""
103+
import torch
104+
81105
if os.environ.get("ARM_TEST_SEED", "RANDOM") == "RANDOM":
82106
random.seed() # reset seed, in case any other test has fiddled with it
83107
seed = random.randint(0, 2**32 - 1)
@@ -161,6 +185,8 @@ def _load_libquantized_ops_aot_lib():
161185
res = subprocess.run(find_lib_cmd, capture_output=True)
162186
if res.returncode == 0:
163187
library_path = res.stdout.decode().strip()
188+
import torch
189+
164190
torch.ops.load_library(library_path)
165191
else:
166192
raise RuntimeError(

backends/arm/test/passes/test_rescale_pass.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _test_rescale_pipeline(
116116
):
117117
"""Tests a model with many ops that requires rescales. As more ops are quantized to int32 and
118118
need the InsertRescalesPass, make sure that they play nicely together."""
119-
(
119+
tester = (
120120
ArmTester(
121121
module,
122122
example_inputs=test_data,
@@ -126,8 +126,9 @@ def _test_rescale_pipeline(
126126
.export()
127127
.to_edge_transform_and_lower()
128128
.to_executorch()
129-
.run_method_and_compare_outputs(test_data)
130129
)
130+
if conftest.is_option_enabled("tosa_ref_model"):
131+
tester.run_method_and_compare_outputs(test_data)
131132

132133

133134
def _test_rescale_pipeline_ethosu(
@@ -152,6 +153,7 @@ def _test_rescale_pipeline_ethosu(
152153
class TestRescales(unittest.TestCase):
153154

154155
@parameterized.expand(RescaleNetwork.test_parameters)
156+
@pytest.mark.tosa_ref_model
155157
def test_quantized_rescale(self, x, y):
156158
_test_rescale_pipeline(RescaleNetwork(), (x, y))
157159

backends/arm/test/pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
addopts = --strict-markers
33
markers =
44
slow: Tests that take long time
5-
corstone_fvp: Tests that use Corstone300 or Corstone320 FVP
5+
corstone_fvp: Tests that use Corstone300 or Corstone320 FVP # And also uses TOSA reference model
6+
tosa_ref_model: Tests that use TOSA reference model # Temporary!

backends/arm/test/runner_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
try:
2323
import tosa_reference_model
2424
except ImportError:
25-
logger.warning("tosa_reference_model not found, can't run reference model tests")
2625
tosa_reference_model = None
2726
from executorch.backends.arm.arm_backend import get_tosa_spec, is_tosa
2827

backends/arm/test/targets.bzl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# load("//caffe2/test/fb:defs.bzl", "define_tests")
2+
load("@fbcode_macros//build_defs:python_pytest.bzl", "python_pytest")
3+
load("@bazel_skylib//lib:paths.bzl", "paths")
4+
5+
def define_arm_tests():
6+
# TODO Add more tests
7+
test_files = native.glob(["passes/test_*.py"])
8+
9+
# https://github.com/pytorch/executorch/issues/8606
10+
test_files.remove("passes/test_ioquantization_pass.py")
11+
12+
TESTS = {}
13+
14+
for test_file in test_files:
15+
test_file_name = paths.basename(test_file)
16+
test_name = test_file_name.replace("test_", "").replace(".py", "")
17+
18+
python_pytest(
19+
name = test_name,
20+
srcs = [test_file],
21+
pytest_config = "pytest.ini",
22+
resources = ["conftest.py"],
23+
compile = "with-source",
24+
typing = False,
25+
preload_deps = [
26+
"//executorch/kernels/quantized:custom_ops_generated_lib",
27+
],
28+
deps = [
29+
":arm_tester",
30+
":conftest",
31+
"//executorch/exir:lib",
32+
"fbsource//third-party/pypi/pytest:pytest",
33+
"fbsource//third-party/pypi/parameterized:parameterized",
34+
],
35+
)

0 commit comments

Comments
 (0)