Skip to content

Commit 93c91b6

Browse files
authored
Merge branch 'main' into arm-backend-llm-export
2 parents 2947953 + ccaf17e commit 93c91b6

400 files changed

Lines changed: 24092 additions & 5310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/scripts/test_cortex_m_e2e.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# Copyright 2026 Arm Limited and/or its affiliates.
34
# All rights reserved.
45
#
56
# This source code is licensed under the BSD-style license found in the
@@ -18,7 +19,7 @@ mkdir -p "./cortex_m_e2e/${MODEL}"
1819
WORK_DIR=$(realpath "./cortex_m_e2e/${MODEL}")
1920

2021
echo "=== Exporting ${MODEL} with cortex-m55+int8 ==="
21-
python -m examples.arm.aot_arm_compiler \
22+
python -m backends.arm.scripts.aot_arm_compiler \
2223
-m "${MODEL}" \
2324
--target=cortex-m55+int8 \
2425
--quantize \

.ci/scripts/test_qnn_static_llm.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ if [[ "${TASK_NAME}" == "stories_110m" ]]; then
4747
$PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
4848

4949
# Compile only as weight sharing is not applicable on x86.
50-
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --model SM8650 --build_folder build-android/ --executorch_root . --artifact_dir ./stories_110m_pte_size --llama_artifacts . --compile_only
50+
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --soc_model SM8650 --build_folder build-android/ --executorch_root . --artifact_dir ./stories_110m_pte_size --llama_artifacts . --compile_only
5151
exit_code1=$?
5252

5353
# Checks accuracy with weight sharing disabled since x86 does not support weight sharing.
54-
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir ./stories_110m_accuracy --llama_artifacts . --enable_x86_64
54+
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --soc_model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir ./stories_110m_accuracy --llama_artifacts . --enable_x86_64
5555
exit_code2=$?
5656

5757
# Check the exit codes and print messages
@@ -84,7 +84,7 @@ elif [[ "${TASK_NAME}" == "smollm2_135m" ]]; then
8484
if [ -n "$2" ]; then
8585
EXTRA_FLAGS="$EXTRA_FLAGS --static_llm_eval_method $2"
8686
fi
87-
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_static_llm_model --model_name smollm2_135m --model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir ./static_smollm2 --enable_x86_64 $EXTRA_FLAGS
87+
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_static_llm_model --model_name smollm2_135m --soc_model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir ./static_smollm2 --enable_x86_64 $EXTRA_FLAGS
8888
exit_code1=$?
8989
if [ $exit_code1 -ne 0 ]; then
9090
exit 1
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# LICENSE file in the root directory of this source tree.
77

88
set -ex
9+
910
# shellcheck source=/dev/null
1011
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1112

@@ -50,21 +51,21 @@ PT2E_QUANTIZE="${PT2E_QUANTIZE:-}"
5051
# Default CMake Build Type to release mode
5152
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release}
5253

53-
if [[ $# -lt 5 ]]; then # Assuming 4 mandatory args
54-
echo "Expecting atleast 5 positional arguments"
55-
echo "Usage: [...]"
56-
fi
5754
if [[ -z "${MODEL_NAME:-}" ]]; then
5855
echo "Missing model name, exiting..."
5956
exit 1
6057
fi
6158

62-
6359
if [[ -z "${MODE:-}" ]]; then
6460
echo "Missing mode, choose openvino or xnnpack, exiting..."
6561
exit 1
6662
fi
6763

64+
if [[ -z "${VIDEO_PATH:-}" ]]; then
65+
echo "Missing video path, exiting..."
66+
exit 1
67+
fi
68+
6869
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
6970
PYTHON_EXECUTABLE=python3
7071
fi
@@ -75,21 +76,13 @@ if [[ "${MODE}" =~ .*openvino.* ]]; then
7576
OPENVINO=ON
7677
TARGET_LIBS="$TARGET_LIBS openvino_backend "
7778

78-
git clone https://github.com/openvinotoolkit/openvino.git
79-
cd openvino && git b16b776ac119dafda51f69a80f1e6b7376d02c3b
80-
git submodule update --init --recursive
81-
sudo ./install_build_dependencies.sh
82-
mkdir build && cd build
83-
cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON
84-
make -j$(nproc)
85-
86-
cd ..
87-
cmake --install build --prefix dist
88-
89-
source dist/setupvars.sh
90-
cd ../backends/openvino
91-
pip install -r requirements.txt
92-
cd ../../
79+
# Install specific OpenVINO runtime from pip.
80+
$PYTHON_EXECUTABLE -m pip install --pre openvino==2026.1.0.dev20260131 --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly
81+
$PYTHON_EXECUTABLE -m pip install -r backends/openvino/requirements.txt
82+
83+
# Set OPENVINO_LIB_PATH so the C++ demo runner can also find libopenvino_c.so.
84+
OPENVINO_LIB_PATH=$($PYTHON_EXECUTABLE -c "import openvino, os, glob; print(sorted(glob.glob(os.path.join(os.path.dirname(openvino.__file__), 'libs', 'libopenvino_c.so*')))[-1])")
85+
export OPENVINO_LIB_PATH
9386
else
9487
OPENVINO=OFF
9588
fi
@@ -103,9 +96,10 @@ fi
10396

10497
which "${PYTHON_EXECUTABLE}"
10598

99+
TORCH_URL=https://download.pytorch.org/whl/cpu
106100

107-
DIR="examples/models/yolo12"
108-
$PYTHON_EXECUTABLE -m pip install -r ${DIR}/requirements.txt
101+
DIR="examples/models/yolo26"
102+
$PYTHON_EXECUTABLE -m pip install --upgrade-strategy only-if-needed --extra-index-url "$TORCH_URL" -r ${DIR}/requirements.txt
109103

110104
cmake_install_executorch_libraries() {
111105
rm -rf cmake-out
@@ -142,11 +136,11 @@ cmake_install_executorch_libraries() {
142136

143137
echo $TARGET_LIBS
144138
export CMAKE_BUILD_ARGS="--target $TARGET_LIBS"
145-
pip install . --no-build-isolation
139+
$PYTHON_EXECUTABLE -m pip install . --no-build-isolation
146140
}
147141

148142
cmake_build_demo() {
149-
echo "Building yolo12 runner"
143+
echo "Building yolo26 runner"
150144
retry cmake \
151145
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
152146
-DUSE_OPENVINO_BACKEND="$OPENVINO" \
@@ -174,24 +168,29 @@ prepare_artifacts_upload() {
174168

175169

176170
# Export model.
177-
EXPORTED_MODEL_NAME="${MODEL_NAME}_fp32_${MODE}.pte"
178-
echo "Exporting ${EXPORTED_MODEL_NAME}"
179171
EXPORT_ARGS="--model_name=${MODEL_NAME} --backend=${MODE}"
172+
if [[ -n "${PT2E_QUANTIZE}" ]]; then
173+
EXPORTED_MODEL_NAME="${MODEL_NAME}_int8_${MODE}.pte"
174+
EXPORT_ARGS="${EXPORT_ARGS} --quantize --video_path=${VIDEO_PATH}"
175+
else
176+
EXPORTED_MODEL_NAME="${MODEL_NAME}_fp32_${MODE}.pte"
177+
fi
178+
echo "Exporting ${EXPORTED_MODEL_NAME}"
180179

181180
# Add dynamically linked library location
182181
cmake_install_executorch_libraries
183182

184-
$PYTHON_EXECUTABLE -m examples.models.yolo12.export_and_validate ${EXPORT_ARGS}
183+
$PYTHON_EXECUTABLE -m examples.models.yolo26.export_and_validate ${EXPORT_ARGS}
185184

186185

187186
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --input_path=${VIDEO_PATH}"
188187
# Check build tool.
189188
cmake_build_demo
190-
# Run yolo12 runner
189+
# Run yolo26 runner
191190
NOW=$(date +"%H:%M:%S")
192-
echo "Starting to run yolo12 runner at ${NOW}"
191+
echo "Starting to run yolo26 runner at ${NOW}"
193192
# shellcheck source=/dev/null
194-
cmake-out/examples/models/yolo12/Yolo12DetectionDemo ${RUNTIME_ARGS} > result.txt
193+
cmake-out/examples/models/yolo26/Yolo26DetectionDemo ${RUNTIME_ARGS} > result.txt
195194
NOW=$(date +"%H:%M:%S")
196195
echo "Finished at ${NOW}"
197196

.claude/skills/qualcomm/SKILL.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
name: qualcomm
3+
description: Build, test, or develop the QNN (Qualcomm AI Engine Direct) backend. Use when working on backends/qualcomm/, building QNN (use backends/qualcomm/scripts/build.sh), adding new ops or passes, running QNN delegate
4+
tests, or exporting models for Qualcomm HTP/GPU targets.
5+
---
6+
7+
# QNN (Qualcomm AI Engine Direct) Backend
8+
9+
## Advanced Topics
10+
11+
When the user's request falls into one of these areas, read the corresponding file before proceeding:
12+
13+
| Topic | File | When to read |
14+
|---|---|---|
15+
| Export / lowering / quantization options / pass pipelines | `lowering_export.md` | User asks about exporting, lowering, quantization config, QuantDtype, QuantRecipe, pass pipelines |
16+
| New op development | `new_op_development.md` | User asks to add/implement a new op or op builder |
17+
| Model enablement | `model_enablement.md` | User asks to enable a new model end-to-end |
18+
| Profiling & debugging | `profiling.md` | User asks about profiling, optrace, QHAS, QAIRT Visualizer *(file TBD)* |
19+
20+
## Building
21+
22+
Use `backends/qualcomm/scripts/build.sh`. Linux only (macOS not supported).
23+
24+
**Environment variables:**
25+
- `QNN_SDK_ROOT` — path to QNN SDK (auto-downloaded if not set)
26+
- `ANDROID_NDK_ROOT` — path to Android NDK (auto-downloaded if not set)
27+
28+
**Build targets:**
29+
30+
| Target | Default | Build dir |
31+
|---|---|---|
32+
| x86_64 (Python interface + host tools) | enabled | `build-x86/` |
33+
| Android arm64-v8a (device runner) | enabled | `build-android/` |
34+
| Hexagon DSP (direct mode) | disabled | `build-hexagon/` |
35+
| OE Linux embedded | disabled | `build-oe-linux/` |
36+
37+
**Common build commands:**
38+
39+
```bash
40+
# Full build (x86_64 + Android)
41+
./backends/qualcomm/scripts/build.sh
42+
43+
# x86_64 only (faster, for Python interface development)
44+
./backends/qualcomm/scripts/build.sh --skip_linux_android
45+
46+
# Android only (skip x86_64)
47+
./backends/qualcomm/scripts/build.sh --skip_x86_64
48+
49+
# Incremental build (skip clean)
50+
./backends/qualcomm/scripts/build.sh --no_clean
51+
52+
# Enable Hexagon DSP direct mode (requires HEXAGON_SDK_ROOT, HEXAGON_TOOLS_ROOT, DSP_VERSION)
53+
./backends/qualcomm/scripts/build.sh --enable_hexagon
54+
55+
# OE Linux embedded target (requires TOOLCHAIN_ROOT_HOST, TOOLCHAIN_ROOT_TARGET)
56+
./backends/qualcomm/scripts/build.sh --enable_linux_embedded
57+
58+
# Release build
59+
./backends/qualcomm/scripts/build.sh --release
60+
61+
# Control parallelism
62+
./backends/qualcomm/scripts/build.sh --job_number 8
63+
```
64+
65+
**After x86_64 build**, the Python interface `.so` files are copied to `backends/qualcomm/python/` automatically.
66+
67+
## Testing
68+
69+
```bash
70+
QNN_SDK_ROOT=/path/to/qnn_sdk \
71+
ANDROID_NDK_ROOT=/path/to/android_ndk \
72+
LD_LIBRARY_PATH=/path/to/executorch/build-x86/lib:/path/to/qnn_sdk/lib/x86_64-linux-clang \
73+
PYTHONPATH=$(dirname $EXECUTORCH_ROOT) \
74+
python backends/qualcomm/tests/test_qnn_delegate.py \
75+
TestQNNFloatingPointOperator.test_qnn_backend_abs \
76+
-H $HOST -s $DEVICE_SERIAL -m SM8850 -b build-android -a /path/to/artifacts
77+
```
78+
79+
> **Note (build from source):** Set `PYTHONPATH` to the parent directory of the executorch repo root. Required because `executorch.examples.qualcomm` lives in the source tree and is not installed into site-packages.
80+
81+
Required flags: `-m` (SoC model), `-b` (Android build dir). Optional: `-s` (device serial), `-H` (host), `-a` (artifact dir), `-c` (compile only), `-x` (run on x86_64).
82+
83+
**Test classes:**
84+
85+
| Class | Description |
86+
|---|---|
87+
| `TestQNNFloatingPointOperator` | FP16 operator tests |
88+
| `TestQNNQuantizedOperator` | Quantized operator tests |
89+
| `TestQNNFloatingPointModel` | FP16 model-level tests |
90+
| `TestQNNQuantizedModel` | Quantized model-level tests |
91+
| `TestQNNFloatingPointUtils` | FP16 utility tests |
92+
| `TestQNNQuantizedUtils` | Quantized utility tests |
93+
| `TestExampleLLMScript` | LLM script tests |
94+
| `TestExampleMultimodalityScript` | Multimodality script tests |
95+
| `TestExampleOssScript` | OSS model script tests |
96+
| `TestExampleQaihubScript` | QAI Hub script tests |
97+
| `TestExampleScript` | General example script tests |
98+
| `TestUtilsScript` | Utility script tests |

0 commit comments

Comments
 (0)