Skip to content

Commit bffccd1

Browse files
tom-armzingo
andauthored
Arm backend: Remove quantize library loading from Silero VAD example (#24681)
* Ensure it's loaded using executorch.kernels.quantized * Remove use of environment variable * Don't build library in OOTB tests Change-Id: Id35e4197f047b25185339e529d8e4a8f70dc8180 cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Tom Allsop <tom.allsop@arm.com> Co-authored-by: Zingo Andersen <zingo.andersen@arm.com>
1 parent 0fde0dd commit bffccd1

2 files changed

Lines changed: 1 addition & 97 deletions

File tree

‎backends/arm/test/test_arm_ootb.sh‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,11 @@ run_silero_vad_e2e_ethos_u() {
388388
local build_dir="${work_root}/silero_vad_app"
389389
local fvp_out_dir="${work_root}/fvp"
390390
local et_build_dir="${et_root_dir}/cmake-out-arm"
391-
local quantized_aot_build_dir="${work_root}/quantized_ops_aot"
392-
local python_package_dir="${work_root}/python_package"
393391
local pte_path="${export_dir}/silero_vad_ethos_u.pte"
394392
local expected_path="${export_dir}/expected_probs.bin"
395393
local fvp_log_path="${fvp_out_dir}/fvp.log"
396394
local validation_threshold="0.55"
397395
local toolchain_file="${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake"
398-
local export_pythonpath="${et_root_dir}/third-party/ao:${python_package_dir}:${PYTHONPATH:-}"
399396
local codegen_pythonpath="${et_root_dir}:${PYTHONPATH:-}"
400397
local platform_cmake_args=()
401398
if [[ "$(uname -s)" == "Darwin" ]]; then
@@ -414,39 +411,6 @@ run_silero_vad_e2e_ethos_u() {
414411
cmake --preset arm-baremetal -B "${et_build_dir}"
415412
cmake --build "${et_build_dir}" --target install -j"$n_proc"
416413

417-
echo "${FUNCNAME}: Building host quantized AOT library"
418-
local python_executable
419-
python_executable="$(python3 -c 'import sys; print(sys.executable)')"
420-
cmake \
421-
-S "${et_root_dir}" \
422-
-B "${quantized_aot_build_dir}" \
423-
-DCMAKE_BUILD_TYPE=Release \
424-
-DEXECUTORCH_BUILD_CPUINFO=OFF \
425-
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
426-
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=OFF \
427-
-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=OFF \
428-
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=OFF \
429-
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=OFF \
430-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
431-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
432-
-DEXECUTORCH_BUILD_PTHREADPOOL=OFF \
433-
-DEXECUTORCH_BUILD_XNNPACK=OFF \
434-
-DPYTHON_EXECUTABLE="${python_executable}"
435-
cmake --build "${quantized_aot_build_dir}" --target quantized_ops_aot_lib -j"$n_proc"
436-
437-
local quantized_ops_library
438-
quantized_ops_library="$(
439-
find "${quantized_aot_build_dir}/kernels/quantized" \
440-
-name 'libquantized_ops_aot_lib.*' \
441-
-type f \
442-
-print \
443-
-quit
444-
)"
445-
[[ -n "${quantized_ops_library}" ]] || {
446-
echo "${FUNCNAME}: Missing quantized AOT library under ${quantized_aot_build_dir}"
447-
return 1
448-
}
449-
450414
if [[ ! -f "${jit_path}" || "$(git -C "${model_dir}" rev-parse HEAD 2>/dev/null)" != "${model_revision}" ]]; then
451415
echo "${FUNCNAME}: Cloning Silero VAD repository"
452416
rm -rf "${model_dir}"
@@ -470,18 +434,8 @@ run_silero_vad_e2e_ethos_u() {
470434
--duration-seconds 2.5 \
471435
--output "${validation_audio_path}"
472436

473-
echo "${FUNCNAME}: Preparing ExecuTorch Python package"
474-
rm -rf "${python_package_dir}"
475-
(
476-
cd "${et_root_dir}"
477-
EXECUTORCH_BUILD_PYBIND=OFF python3 setup.py build_py \
478-
--build-lib="${python_package_dir}"
479-
)
480-
481437
echo "${FUNCNAME}: Exporting quantized Silero VAD PTE"
482-
env EXECUTORCH_QUANTIZED_OPS_AOT_LIBRARY="${quantized_ops_library}" \
483-
PYTHONPATH="${export_pythonpath}" \
484-
python3 "${example_dir}/model_export/export_silero_vad_ethos_u.py" \
438+
python3 "${example_dir}/model_export/export_silero_vad_ethos_u.py" \
485439
--jit-model "${jit_path}" \
486440
--calibration-audio "${calibration_audio_path}" \
487441
--validation-audio "${validation_audio_path}" \

‎examples/arm/silero_vad_example_ethos_u/model_export/export_silero_vad_ethos_u.py‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# LICENSE file in the root directory of this source tree.
55

66
import argparse
7-
import importlib
87
import math
98
import os
109
import struct
@@ -39,7 +38,6 @@
3938
ExecutorchBackendConfig,
4039
to_edge_transform_and_lower,
4140
)
42-
from executorch.exir.dialects._ops import ops as exir_ops # noqa: E402
4341
from executorch.exir.passes.init_mutable_pass import ( # noqa: E402
4442
InitializedMutableBufferPass,
4543
)
@@ -272,53 +270,6 @@ def write_float32_file(path: str, values: torch.Tensor) -> None:
272270
output_file.write(struct.pack(f"<{len(data)}f", *data))
273271

274272

275-
def ensure_quantized_out_variants() -> None:
276-
try:
277-
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default.to_out_variant()
278-
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default.to_out_variant()
279-
return
280-
except RuntimeError:
281-
pass
282-
283-
configured_library = os.environ.get("EXECUTORCH_QUANTIZED_OPS_AOT_LIBRARY")
284-
if configured_library:
285-
library_path = Path(configured_library).expanduser().resolve()
286-
if not library_path.is_file():
287-
raise FileNotFoundError(f"Quantized ops library not found: {library_path}")
288-
torch.ops.load_library(str(library_path))
289-
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default.to_out_variant()
290-
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default.to_out_variant()
291-
return
292-
293-
try:
294-
import executorch.extension.pybindings.portable_lib # noqa: F401
295-
except ImportError:
296-
pass
297-
298-
candidate_roots = [REPO_ROOT]
299-
executorch_pkg = importlib.import_module("executorch")
300-
for package_path in getattr(executorch_pkg, "__path__", []):
301-
resolved_package_path = Path(package_path).resolve()
302-
if resolved_package_path.parent.name == "src":
303-
candidate_roots.append(resolved_package_path.parent.parent)
304-
305-
suffixes = (".so", ".dylib", ".dll")
306-
for root in dict.fromkeys(candidate_roots):
307-
quantized_dir = root / "kernels" / "quantized"
308-
for suffix in suffixes:
309-
candidate = quantized_dir / f"libquantized_ops_aot_lib{suffix}"
310-
if candidate.exists():
311-
torch.ops.load_library(str(candidate))
312-
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default.to_out_variant()
313-
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default.to_out_variant()
314-
return
315-
316-
raise RuntimeError(
317-
"Could not load quantized q/dq out variants. Build or install the "
318-
"quantized AOT op library before exporting this example."
319-
)
320-
321-
322273
def quantize_model(
323274
model: torch.nn.Module,
324275
quantizer: EthosUQuantizer,
@@ -444,7 +395,6 @@ def parse_args() -> argparse.Namespace:
444395
_check_ir_validity=False,
445396
),
446397
)
447-
ensure_quantized_out_variants()
448398
executorch_program = edge_program.to_executorch(
449399
config=ExecutorchBackendConfig(
450400
extract_delegate_segments=False,

0 commit comments

Comments
 (0)