Skip to content

Commit ce57d79

Browse files
Arm backend: Remove build_quantized_ops_aot_lib.sh (#10350)
This lib is built by default when installing executorch, so use that instead of building our own version. The the version built by executorch however has an extra dependency on _portable_lib.cpython-310, which needs to be loaded as well. Also removes all mentions of this script in related files. Signed-off-by: Adrian Lundell <[email protected]>
1 parent eb5fc61 commit ce57d79

File tree

11 files changed

+19
-180
lines changed

11 files changed

+19
-180
lines changed

backends/arm/quantizer/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@
1313

1414
# Used in tests
1515
from .arm_quantizer_utils import is_annotated # noqa
16+
17+
# Load quantized ops library.
18+
try:
19+
import executorch.extension.pybindings.portable_lib
20+
import executorch.kernels.quantized # noqa
21+
except:
22+
import logging
23+
24+
logging.info(
25+
"Failed to load portable_lib and quantized_aot_lib. To run quantized kernels AOT, either build "
26+
"Executorch with pybindings, or load your own custom built op library using torch.ops.load_library."
27+
)
28+
del logging

backends/arm/scripts/build_quantized_ops_aot_lib.sh

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

backends/arm/test/conftest.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
import logging
77
import os
8-
import platform
98
import random
109
import shutil
11-
import subprocess
1210
import sys
1311
from typing import Any
1412

@@ -81,8 +79,7 @@ def try_addoption(*args, **kwargs):
8179

8280

8381
def pytest_sessionstart(session):
84-
if not session.config.option.collectonly:
85-
_load_libquantized_ops_aot_lib()
82+
pass
8683

8784

8885
def pytest_sessionfinish(session, exitstatus):
@@ -172,32 +169,3 @@ def get_option(option: str) -> Any | None:
172169
if option in pytest._test_options: # type: ignore[attr-defined]
173170
return pytest._test_options[option] # type: ignore[attr-defined]
174171
return None
175-
176-
177-
def _load_libquantized_ops_aot_lib():
178-
"""
179-
Find and load the libquantized_ops_aot_lib shared library.
180-
"""
181-
so_ext = {
182-
"Darwin": "dylib",
183-
"Linux": "so",
184-
"Windows": "dll",
185-
}.get(platform.system(), None)
186-
187-
find_lib_cmd = [
188-
"find",
189-
"cmake-out-aot-lib",
190-
"-name",
191-
f"libquantized_ops_aot_lib.{so_ext}",
192-
]
193-
194-
res = subprocess.run(find_lib_cmd, capture_output=True)
195-
if res.returncode == 0:
196-
library_path = res.stdout.decode().strip()
197-
import torch
198-
199-
torch.ops.load_library(library_path)
200-
else:
201-
raise RuntimeError(
202-
f"Did not find libquantized_ops_aot_lib.{so_ext} in cmake-out-aot-lib. Did you build it?"
203-
)

backends/arm/test/setup_testing.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ function build_semihosting_executorch_runner() {
5252
find ${build_test_dir} -name "arm_executor_runner"
5353
}
5454

55-
cd $et_root_dir && backends/arm/scripts/build_quantized_ops_aot_lib.sh
56-
5755
# Use most optimal system_configs for testing
5856
build_semihosting_executorch_runner corstone-300 Ethos_U55_High_End_Embedded
5957

backends/arm/test/test_arm_baremetal.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ test_pytest() { # Test ops and other things
7474

7575
./examples/models/llama3_2_vision/install_requirements.sh
7676

77-
cd "${et_root_dir}"
78-
backends/arm/scripts/build_quantized_ops_aot_lib.sh
79-
8077
# Run arm baremetal pytest tests without FVP
8178
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/
8279
echo "${TEST_SUITE_NAME}: PASS"

backends/arm/test/test_model.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import argparse
77
import os
8-
import platform
98
import subprocess
109
import sys
1110

@@ -113,14 +112,6 @@ def build_libs(et_build_root: str, script_path: str):
113112
"--portable_kernels=aten::_softmax.out",
114113
]
115114
)
116-
run_external_cmd(
117-
[
118-
"bash",
119-
os.path.join(script_path, "build_quantized_ops_aot_lib.sh"),
120-
f"--et_build_root={et_build_root}",
121-
"--build_type=Release",
122-
]
123-
)
124115

125116

126117
def build_pte(
@@ -132,17 +123,6 @@ def build_pte(
132123
build_output: str,
133124
no_intermediate: bool,
134125
):
135-
soext = {"Darwin": "dylib", "Linux": "so", "Windows": "dll"}.get(
136-
platform.system(), None
137-
)
138-
solibs_path = os.path.join(
139-
et_build_root,
140-
"cmake-out-aot-lib",
141-
"kernels",
142-
"quantized",
143-
f"libquantized_ops_aot_lib.{soext}",
144-
)
145-
solibs = f"--so_library={solibs_path}"
146126

147127
intermediate = ""
148128
if not no_intermediate:
@@ -162,7 +142,6 @@ def build_pte(
162142
f"--output={build_output}",
163143
f"--system_config={system_config}",
164144
f"--memory_mode={memory_mode}",
165-
solibs,
166145
]
167146
)
168147

docs/source/backends-arm-ethos-u.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ To compile for the NPUs, the Ethos-U Vela compiler is needed. A target-specific
1717

1818
These dependencies can easily be downloaded using the script `examples/arm/setup.sh`.
1919

20-
To work with with quantized models, build the quantize_ops_aot library that contains kernels for quantization and dequantization. This can be done with the script
21-
`backends/arm/scripts/build_quantized_ops_aot_lib.sh`.
22-
2320
## Using the Arm Ethos-U backend
2421
The example below demonstrates the lowering processs of a MobileNet V2 model from torchvision for a Ethos-U55 target. Since the model is a floating point model, first quantize it using the `EthosUQuantizer`. Then, pass an instance of the `EthosUPartitioner` to `to_edge_transform_and_lower`. Both the quantizer and the partitioner need a compilation specification created using `ArmCompileSpecBuilder`.
2522

docs/source/tutorial-arm-ethos-u.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -244,28 +244,9 @@ python3 -m examples.arm.aot_arm_compiler --model_name="add" --delegate
244244
```
245245

246246
### Delegated Quantized Workflow
247-
Before generating the `.pte` file for delegated quantized networks like MobileNetV2, you need to build the `quantized_ops_aot_lib`
248-
249-
You can just run the `backends/arm/scripts/build_quantized_ops_aot_lib.sh` script to build this for you or build it yourself like this.
250-
251-
```bash
252-
253-
cd <executorch_root_dir>
254-
mkdir -p cmake-out-aot-lib
255-
cmake -DCMAKE_BUILD_TYPE=Release \
256-
-DEXECUTORCH_BUILD_XNNPACK=OFF \
257-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
258-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
259-
-DPYTHON_EXECUTABLE=python3 \
260-
-Bcmake-out-aot-lib \
261-
"${et_root_dir}"
262-
263-
cmake --build cmake-out-aot-lib --parallel -- quantized_ops_aot_lib
264-
```
265-
266-
After the `quantized_ops_aot_lib` build, you can run the following script to generate the `.pte` file
247+
Generating the `.pte` file can be done using the aot_arm_compiler:
267248
```bash
268-
python3 -m examples.arm.aot_arm_compiler --model_name="mv2" --delegate --quantize --so_library="$(find cmake-out-aot-lib -name libquantized_ops_aot_lib.so)"
249+
python3 -m examples.arm.aot_arm_compiler --model_name="mv2" --delegate --quantize"
269250
# should produce ./mv2_arm_delegate_ethos-u55-128.pte
270251
```
271252
@@ -315,7 +296,7 @@ To run a `.pte` file with the Arm backend delegate call instructions, you will n
315296
316297
- `libexecutorch_delegate_ethos_u.a`
317298
318-
These libraries are generated by the `backends/arm/scripts/build_executorch.sh`, `backends/arm/scripts/build_portable_kernels.sh` and `backends/arm/scripts/build_quantized_ops_aot_lib.sh` scripts called from the `run.sh` script.
299+
These libraries are generated by the `backends/arm/scripts/build_executorch.sh` and `backends/arm/scripts/build_portable_kernels.sh` scripts called from the `run.sh` script.
319300
320301
The `--portable_kernels` flag can be used to set the build flag `EXECUTORCH_SELECT_OPS_LIST` when running `backends/arm/scripts/build_portable_kernels.sh` that will decide the number of portable operators included in the build and are available at runtime. It must match with `.pte` file's requirements, otherwise you will get `Missing Operator` error at runtime.
321302

examples/arm/aot_arm_compiler.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def get_args():
466466
"--so_library",
467467
required=False,
468468
default=None,
469-
help="Provide path to so library. E.g., cmake-out/examples/portable/custom_ops/libcustom_ops_aot_lib.so",
469+
help="Provide path to custom .so library.",
470470
)
471471
parser.add_argument(
472472
"--debug", action="store_true", help="Set the logging level to debug."
@@ -509,12 +509,6 @@ def get_args():
509509
if args.debug:
510510
logging.basicConfig(level=logging.DEBUG, format=FORMAT, force=True)
511511

512-
if args.quantize and not args.so_library:
513-
logging.warning(
514-
"Quantization enabled without supplying path to libcustom_ops_aot_lib using -s flag."
515-
+ "This is required for running quantized models with unquantized input."
516-
)
517-
518512
# if we have custom ops, register them before processing the model
519513
if args.so_library is not None:
520514
logging.info(f"Loading custom ops from {args.so_library}")

examples/arm/ethos_u_minimal_example.ipynb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,32 +115,6 @@
115115
"quantized_exported_program = torch.export.export_for_training(quantized_graph_module, example_inputs)"
116116
]
117117
},
118-
{
119-
"cell_type": "markdown",
120-
"metadata": {},
121-
"source": [
122-
"The quantization nodes created in the previous cell are not built by default with ExecuTorch but must be included in the .pte-file, and so they need to be built separately. `backends/arm/scripts/build_quantized_ops_aot_lib.sh` is a utility script which does this. "
123-
]
124-
},
125-
{
126-
"cell_type": "code",
127-
"execution_count": null,
128-
"metadata": {},
129-
"outputs": [],
130-
"source": [
131-
"import subprocess\n",
132-
"import os\n",
133-
"\n",
134-
"# Setup paths\n",
135-
"cwd_dir = os.getcwd()\n",
136-
"et_dir = os.path.join(cwd_dir, \"..\", \"..\")\n",
137-
"et_dir = os.path.abspath(et_dir)\n",
138-
"script_dir = os.path.join(et_dir, \"backends\", \"arm\", \"scripts\")\n",
139-
"\n",
140-
"# Run build_quantized_ops_aot_lib.sh\n",
141-
"subprocess.run(os.path.join(script_dir, \"build_quantized_ops_aot_lib.sh\"), shell=True, cwd=et_dir)"
142-
]
143-
},
144118
{
145119
"cell_type": "markdown",
146120
"metadata": {},

0 commit comments

Comments
 (0)