Skip to content

Commit c8424b0

Browse files
Guang Yangguangy10
authored andcommitted
Add the example non-genai qnn model to ci and benchinfra
1 parent 2b3c01c commit c8424b0

File tree

4 files changed

+125
-13
lines changed

4 files changed

+125
-13
lines changed

.ci/scripts/build-qnn-sdk.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,43 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
set -ex
8+
set -eux
99

1010
build_qnn_backend() {
1111
echo "Start building qnn backend."
1212
export ANDROID_NDK_ROOT=/opt/ndk
1313
export QNN_SDK_ROOT=/tmp/qnn/2.23.0.240531
14-
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
14+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
1515

1616
bash backends/qualcomm/scripts/build.sh --skip_aarch64 --job_number 2 --release
1717
}
1818

19+
set_up_aot() {
20+
cd $EXECUTORCH_ROOT
21+
if [ ! -d "cmake-out" ]; then
22+
mkdir cmake-out
23+
fi
24+
pushd cmake-out
25+
cmake .. \
26+
-DCMAKE_INSTALL_PREFIX=$PWD \
27+
-DEXECUTORCH_BUILD_QNN=ON \
28+
-DQNN_SDK_ROOT=${QNN_SDK_ROOT} \
29+
-DEXECUTORCH_BUILD_SDK=ON \
30+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
31+
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
32+
-DPYTHON_EXECUTABLE=python3 \
33+
-DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=OFF
34+
cmake --build $PWD --target "PyQnnManagerAdaptor" "PyQnnWrapperAdaptor" -j$(nproc)
35+
# install Python APIs to correct import path
36+
# The filename might vary depending on your Python and host version.
37+
cp -f backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
38+
cp -f backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
39+
popd
40+
41+
# Workaround for fbs files in exir/_serialize
42+
cp schema/program.fbs exir/_serialize/program.fbs
43+
cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs
44+
}
45+
1946
build_qnn_backend
47+
set_up_aot

.ci/scripts/test.sh

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,25 @@ if [[ -z "${BACKEND:-}" ]]; then
2828
exit 1
2929
fi
3030

31+
UPLOAD_DIR=${4:-}
32+
33+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
34+
PYTHON_EXECUTABLE=python3
35+
fi
3136
which "${PYTHON_EXECUTABLE}"
37+
3238
# Just set this variable here, it's cheap even if we use buck2
3339
CMAKE_OUTPUT_DIR=cmake-out
40+
EXPORTED_MODEL=${MODEL_NAME}
41+
42+
prepare_artifacts_upload() {
43+
if [ -n "$UPLOAD_DIR" ]; then
44+
echo "Preparing for uploading generated artifacs"
45+
zip -j model.zip "${EXPORTED_MODEL}.pte"
46+
mkdir -p "${UPLOAD_DIR}"
47+
mv model.zip "${UPLOAD_DIR}"
48+
fi
49+
}
3450

3551
build_cmake_executor_runner() {
3652
echo "Building executor_runner"
@@ -95,8 +111,8 @@ build_cmake_xnn_executor_runner() {
95111
}
96112

97113
test_model_with_xnnpack() {
98-
WITH_QUANTIZATION=$1
99-
WITH_DELEGATION=$2
114+
WITH_QUANTIZATION=${1:true}
115+
WITH_DELEGATION=${2:true}
100116

101117
# Quantization-only
102118
if [[ ${WITH_QUANTIZATION} == true ]] && [[ ${WITH_DELEGATION} == false ]]; then
@@ -114,6 +130,7 @@ test_model_with_xnnpack() {
114130
fi
115131

116132
OUTPUT_MODEL_PATH="${MODEL_NAME}_xnnpack_${SUFFIX}.pte"
133+
EXPORTED_MODEL=${OUTPUT_MODEL_PATH}
117134

118135
# Run test model
119136
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
@@ -129,9 +146,36 @@ test_model_with_xnnpack() {
129146
fi
130147
}
131148

149+
test_model_with_qnn() {
150+
source "$(dirname "${BASH_SOURCE[0]}")/build-qnn-sdk.sh"
151+
echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
152+
echo "QNN_SDK_ROOT: $QNN_SDK_ROOT"
153+
echo "EXECUTORCH_ROOT: $EXECUTORCH_ROOT"
154+
155+
export LD_LIBRARY_PATH=$QNN_SDK_ROOT/lib/x86_64-linux-clang/
156+
export PYTHONPATH=$EXECUTORCH_ROOT/..
157+
158+
if [[ "${MODEL_NAME}" == "dl3" ]]; then
159+
"${PYTHON_EXECUTABLE}" -m examples.qualcomm.scripts.deeplab_v3 -b ${CMAKE_OUTPUT_DIR} -m SM8550 --compile_only --download
160+
EXPORTED_MODEL=./deeplab_v3/dlv3_qnn
161+
fi
162+
}
163+
132164
if [[ "${BACKEND}" == "portable" ]]; then
133165
echo "Testing ${MODEL_NAME} with portable kernels..."
134166
test_model
167+
elif [[ "${BACKEND}" == "qnn" ]]; then
168+
echo "Testing ${MODEL_NAME} with qnn..."
169+
test_model_with_qnn
170+
if [[ $? -eq 0 ]]; then
171+
prepare_artifacts_upload
172+
fi
173+
elif [[ "${BACKEND}" == "xnnpack" ]]; then
174+
echo "Testing ${MODEL_NAME} with xnnpack..."
175+
test_model_with_xnnpack
176+
if [[ $? -eq 0 ]]; then
177+
prepare_artifacts_upload
178+
fi
135179
else
136180
set +e
137181
if [[ "${BACKEND}" == *"quantization"* ]]; then
@@ -153,5 +197,7 @@ else
153197
if [[ -n "${Q_ERROR:-}" ]] || [[ -n "${D_ERROR:-}" ]] || [[ -n "${Q_D_ERROR:-}" ]]; then
154198
echo "Portable q8 ${Q_ERROR:-ok}," "Delegation fp32 ${D_ERROR:-ok}," "Delegation q8 ${Q_D_ERROR:-ok}"
155199
exit 1
200+
else
201+
prepare_artifacts_upload
156202
fi
157203
fi

.github/workflows/android-perf.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,39 @@ jobs:
135135
fail-fast: false
136136
with:
137137
runner: linux.2xlarge
138-
docker-image: executorch-ubuntu-22.04-clang12
138+
docker-image: executorch-ubuntu-22.04-clang12-android
139139
submodules: 'true'
140140
timeout: 60
141141
upload-artifact: android-models
142142
script: |
143143
# The generic Linux job chooses to use base env, not the one setup by the image
144+
echo "::group::Setting up dev environment"
144145
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
145146
conda activate "${CONDA_ENV}"
146-
147+
if [[ ${{ matrix.delegate }} == "qnn" ]]; then
148+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
149+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
150+
fi
147151
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
148-
echo "Exporting model: ${{ matrix.model }}"
149-
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded/${{ matrix.model }}_${{ matrix.delegate }}
152+
ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded/${{ matrix.model }}_${{ matrix.delegate }}
153+
echo "::endgroup::"
150154
151-
# TODO(T197546696): Note that the following scripts/steps only work for llama. It's expected to fail for other models+delegates.
152-
# Install requirements for export_llama
153-
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
154-
# Test llama2
155-
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh "${{ matrix.model }}.pt" "cmake" "fp32" "xnnpack+custom+qe" "${ARTIFACTS_DIR_NAME}"\
155+
echo "::group::Exporting ${{ matrix.delegate }} model: ${{ matrix.model }}"
156+
BUILD_MODE="cmake"
157+
DTYPE="fp32"
158+
159+
if [[ ${{ matrix.model }} == "llama*" ]]; then
160+
# Install requirements for export_llama
161+
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
162+
# Test llama2
163+
if [[ ${{ matrix.delegate }} == "xnnpack" ]]; then
164+
DELEGATE_CONFIG="xnnpack+custom+qe"
165+
fi
166+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh "${{ matrix.model }}.pt" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
167+
else
168+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${{ matrix.model }}" "${BUILD_MODE}" "${{ matrix.delegate }}" "${ARTIFACTS_DIR_NAME}"
169+
fi
170+
echo "::endgroup::"
156171
157172
# Upload models to S3. The artifacts are needed not only by the device farm but also TorchChat
158173
upload-models:

.github/workflows/trunk.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,26 @@ jobs:
270270
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/models/llama2/install_requirements.sh
271271
# Test llama2
272272
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
273+
274+
test-qnn-model:
275+
name: test-qnn-model
276+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
277+
strategy:
278+
matrix:
279+
dtype: [fp32]
280+
model: [dl3]
281+
fail-fast: false
282+
with:
283+
runner: linux.2xlarge
284+
docker-image: executorch-ubuntu-22.04-clang12-android
285+
submodules: 'true'
286+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
287+
timeout: 900
288+
script: |
289+
# The generic Linux job chooses to use base env, not the one setup by the image
290+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
291+
conda activate "${CONDA_ENV}"
292+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh cmake
293+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
294+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
295+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh ${{ matrix.model }} "cmake" "qnn"

0 commit comments

Comments
 (0)