Skip to content

Commit 40bcf6f

Browse files
committed
Update
[ghstack-poisoned]
2 parents dce054b + 93838e8 commit 40bcf6f

File tree

14 files changed

+172
-82
lines changed

14 files changed

+172
-82
lines changed

backends/arm/operator_support/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# pyre-unsafe
77

88
from . import ( # noqa
9-
bitwise_support,
109
convolution_support,
1110
pool_2d_support,
1211
reduce_sum_support,

backends/arm/operator_support/bitwise_support.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

backends/arm/operator_support/tosa_supported_operators.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from typing import final, Optional, Sequence, Type
1212

1313
import torch
14-
1514
import torch.fx as fx
15+
1616
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
1717
from executorch.backends.arm._passes.fuse_quantized_activation_pass import (
1818
FuseQuantizedActivationPass,
1919
)
20-
from executorch.backends.arm.tosa_specification import TosaSpecification
20+
from executorch.backends.arm.tosa_specification import Tosa_0_80, TosaSpecification
2121
from executorch.exir.dialects._ops import ops as exir_ops
2222
from torch.fx.passes.operator_support import any_chain, chain, OperatorSupportBase
2323
from torch.fx.passes.utils.source_matcher_utils import get_source_partitions
@@ -90,6 +90,7 @@ def tosa_support_factory(
9090
if not tosa_spec.support_float():
9191
negative_checks.append(NeedsDecompositionCheck())
9292
negative_checks.append(CheckProperQuantization())
93+
negative_checks.append(EthosU55NotSupported(tosa_spec))
9394
return chain(
9495
any_chain(
9596
BaseTOSASupportList(),
@@ -111,6 +112,9 @@ def is_node_supported(
111112
supported = node.op == "call_function" and node.target in [
112113
exir_ops.edge.aten.abs.default,
113114
exir_ops.edge.aten.add.Tensor,
115+
exir_ops.edge.aten.bitwise_and.Tensor,
116+
exir_ops.edge.aten.bitwise_or.Tensor,
117+
exir_ops.edge.aten.bitwise_xor.Tensor,
114118
exir_ops.edge.aten.expand_copy.default,
115119
exir_ops.edge.aten.cat.default,
116120
exir_ops.edge.aten.clamp.default,
@@ -170,6 +174,31 @@ def is_node_supported(
170174
return supported
171175

172176

177+
class EthosU55NotSupported(OperatorSupportBase):
178+
"""
179+
Certain operators are not supported on U55. These are listed in `unsupported` in
180+
is_node_supported().
181+
"""
182+
183+
def __init__(self, tosa_spec: TosaSpecification):
184+
self.tosa_spec = tosa_spec
185+
186+
def is_node_supported(
187+
self, submodules: typing.Mapping[str, torch.nn.Module], node: fx.Node
188+
) -> bool:
189+
if isinstance(self.tosa_spec, Tosa_0_80) and self.tosa_spec.is_U55_subset:
190+
unsupported_ops = [
191+
exir_ops.edge.aten.bitwise_and.Tensor,
192+
exir_ops.edge.aten.bitwise_or.Tensor,
193+
exir_ops.edge.aten.bitwise_xor.Tensor,
194+
]
195+
196+
if node.target in unsupported_ops:
197+
return False
198+
199+
return True
200+
201+
173202
class NeedsDecompositionCheck(OperatorSupportBase):
174203
"""
175204
Targeted operators need to be decomposed prior to quantization in order to get a pair of q-dq-nodes surrounding

backends/arm/test/TARGETS

Lines changed: 36 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

@@ -32,3 +38,33 @@ python_library(
3238
"fbsource//third-party/pypi/pytest:pytest",
3339
]
3440
)
41+
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+
55+
python_library(
56+
name = "arm_tester",
57+
srcs = glob(["tester/*.py"]),
58+
deps = [
59+
":runner_utils",
60+
":common",
61+
"//executorch/backends/arm:tosa_mapping",
62+
"//executorch/backends/arm:tosa_specification",
63+
"//executorch/backends/arm/quantizer:arm_quantizer",
64+
"//executorch/backends/arm:arm_partitioner",
65+
"//executorch/devtools/backend_debug:delegation_info",
66+
"fbsource//third-party/pypi/tabulate:tabulate",
67+
]
68+
)
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+
)

docs/TARGETS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ python_binary(
99
par_style = "xar",
1010
deps = [
1111
"//caffe2:torch",
12-
"//executorch/exir:lib",
12+
"//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
1313
"//executorch/devtools:lib",
14+
"//executorch/exir:lib",
1415
"//executorch/exir/backend/test:backend_with_compiler_demo",
1516
"//executorch/exir/backend/test:op_partitioner_demo",
1617
"//executorch/devtools/bundled_program/serialize:lib",

docs/source/android-prebuilt-library.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
# Using Android prebuilt libraries (AAR)
1+
# Using Android prebuilt library (AAR)
22

3-
We provide two prebuilt Android libraries (AAR), `executorch.aar` for generic use case (image/audio processing) and `executorch_llama.aar` for LLAMA use case.
3+
We provide a prebuilt Android library (AAR), `executorch.aar` for both generic (image/audio processing) and LLAMA use case.
44

5-
## Contents of libraries
5+
## Contents of library
66
- `executorch.aar`
77
- [Java library](https://github.com/pytorch/executorch/tree/main/extension/android/src/main/java/org/pytorch/executorch)
8-
- JNI contains the JNI binding for [NativePeer.java](https://github.com/pytorch/executorch/blob/main/extension/android/src/main/java/org/pytorch/executorch/NativePeer.java) and ExecuTorch native library, including core ExecuTorch runtime libraries, XNNPACK backend, Portable kernels, Optimized kernels, and Quantized kernels.
9-
- Comes with two ABI variants, arm64-v8a and x86_64.
10-
- `executorch_llama.aar`
11-
- [Java library](https://github.com/pytorch/executorch/tree/main/extension/android/src/main/java/org/pytorch/executorch) (Note: it contains the same Java classes as the previous Java, but it does not contain the JNI binding for generic Module/NativePeer Java code).
12-
- JNI contains the JNI binding for [LlamaModule.java](https://github.com/pytorch/executorch/blob/main/extension/android/src/main/java/org/pytorch/executorch/LlamaModule.java) and ExecuTorch native library, including core ExecuTorch runtime libraries, XNNPACK backend, Portable kernels, Optimized kernels, Quantized kernels, and LLAMA-specific Custom ops library.
8+
- JNI contains the JNI binding for the corresponding Java code, and ExecuTorch native library, including core ExecuTorch runtime libraries, XNNPACK backend, Portable kernels, Optimized kernels, Quantized kernels, and LLAMA-specific Custom ops library.
139
- Comes with two ABI variants, arm64-v8a and x86_64.
1410

1511
## Downloading AAR

0 commit comments

Comments
 (0)