Skip to content

Commit 1a04d1f

Browse files
committed
Arm backend: Remove build_quantized_ops_aot_lib.sh
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]> Change-Id: Ia3cf9eabb4e293ef96a9cc3441c4233241873684
1 parent a4be2e4 commit 1a04d1f

File tree

10 files changed

+25
-161
lines changed

10 files changed

+25
-161
lines changed

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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import logging
77
import os
8-
import platform
98
import random
109
import shutil
1110
import subprocess
@@ -174,30 +173,31 @@ def get_option(option: str) -> Any | None:
174173
return None
175174

176175

177-
def _load_libquantized_ops_aot_lib():
176+
def _load_lib(lib_name_pattern: str, build_folder: str):
178177
"""
179-
Find and load the libquantized_ops_aot_lib shared library.
178+
Find and load a library by name in build_folder.
180179
"""
181-
so_ext = {
182-
"Darwin": "dylib",
183-
"Linux": "so",
184-
"Windows": "dll",
185-
}.get(platform.system(), None)
186-
187180
find_lib_cmd = [
188181
"find",
189-
"cmake-out-aot-lib",
182+
build_folder,
190183
"-name",
191-
f"libquantized_ops_aot_lib.{so_ext}",
184+
f"{lib_name_pattern}",
192185
]
193-
194186
res = subprocess.run(find_lib_cmd, capture_output=True)
195187
if res.returncode == 0:
196-
library_path = res.stdout.decode().strip()
188+
library_paths = res.stdout.decode().strip().split("\n")
197189
import torch
198190

199-
torch.ops.load_library(library_path)
191+
torch.ops.load_library(library_paths[0])
200192
else:
201193
raise RuntimeError(
202-
f"Did not find libquantized_ops_aot_lib.{so_ext} in cmake-out-aot-lib. Did you build it?"
194+
f"Did not find any library matching {lib_name_pattern} in {build_folder}. Have you installed executorch properly?"
203195
)
196+
197+
198+
def _load_libquantized_ops_aot_lib(executorch_install_dir: str = "pip-out"):
199+
"""
200+
Find and load the libquantized_ops_aot_lib shared library.
201+
"""
202+
_load_lib("_portable_lib.cpython-310*", executorch_install_dir)
203+
_load_lib("libquantized_ops_aot_lib.*", executorch_install_dir)

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
get_symmetric_quantization_config,
3030
TOSAQuantizer,
3131
)
32+
from executorch.backends.arm.test.conftest import _load_libquantized_ops_aot_lib
3233
from executorch.backends.arm.tosa_partitioner import TOSAPartitioner
3334
from executorch.backends.arm.tosa_specification import TosaSpecification
3435

@@ -466,7 +467,7 @@ def get_args():
466467
"--so_library",
467468
required=False,
468469
default=None,
469-
help="Provide path to so library. E.g., cmake-out/examples/portable/custom_ops/libcustom_ops_aot_lib.so",
470+
help="Provide path to custom .so library.",
470471
)
471472
parser.add_argument(
472473
"--debug", action="store_true", help="Set the logging level to debug."
@@ -509,11 +510,10 @@ def get_args():
509510
if args.debug:
510511
logging.basicConfig(level=logging.DEBUG, format=FORMAT, force=True)
511512

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-
)
513+
# Load quantized ops library.
514+
if args.quantize:
515+
logging.info("Loading lib_quantized_custom_op_lib")
516+
_load_libquantized_ops_aot_lib(executorch_install_dir="pip-out")
517517

518518
# if we have custom ops, register them before processing the model
519519
if args.so_library is not None:

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": {},

examples/arm/run.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,6 @@ fi
146146
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag
147147
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels
148148

149-
# Build a lib quantized_ops_aot_lib
150-
backends/arm/scripts/build_quantized_ops_aot_lib.sh --et_build_root="${et_build_root}" --build_type=$build_type
151-
152-
SO_EXT=$(python3 -c 'import platform; print({"Darwin": "dylib", "Linux": "so", "Windows": "dll"}.get(platform.system(), None))')
153-
# We are using the aot_lib from build_quantization_aot_lib below
154-
SO_LIB=$(find "${et_build_root}/cmake-out-aot-lib" -name libquantized_ops_aot_lib.${SO_EXT})
155-
156-
157149
if [[ -z "$model_name" ]]; then
158150
# the test models run, and whether to delegate
159151
test_model=( "softmax" "add" "add3" "mv2" )
@@ -205,7 +197,7 @@ for i in "${!test_model[@]}"; do
205197
model_compiler_flags="${model_compiler_flags} --model_input=${model_input}"
206198
fi
207199

208-
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --so_library=$SO_LIB --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag"
200+
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag"
209201
echo "CALL ${ARM_AOT_CMD}" >&2
210202
${ARM_AOT_CMD} 1>&2
211203

0 commit comments

Comments
 (0)