Skip to content

Commit da54a2f

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

File tree

4 files changed

+117
-11
lines changed

4 files changed

+117
-11
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +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
3440

41+
prepare_artifacts_upload() {
42+
if [ -n "$UPLOAD_DIR" ]; then
43+
echo "Preparing for uploading generated artifacs"
44+
zip -j model.zip "${EXPORTED_MODEL}"
45+
mkdir -p "${UPLOAD_DIR}"
46+
mv model.zip "${UPLOAD_DIR}"
47+
fi
48+
}
49+
3550
build_cmake_executor_runner() {
3651
echo "Building executor_runner"
3752
(rm -rf ${CMAKE_OUTPUT_DIR} \
@@ -129,9 +144,30 @@ test_model_with_xnnpack() {
129144
fi
130145
}
131146

147+
test_model_with_qnn() {
148+
source "$(dirname "${BASH_SOURCE[0]}")/build-qnn-sdk.sh"
149+
echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
150+
echo "QNN_SDK_ROOT: $QNN_SDK_ROOT"
151+
echo "EXECUTORCH_ROOT: $EXECUTORCH_ROOT"
152+
153+
export LD_LIBRARY_PATH=$QNN_SDK_ROOT/lib/x86_64-linux-clang/
154+
export PYTHONPATH=$EXECUTORCH_ROOT/..
155+
156+
if [[ "${MODEL_NAME}" == "dl3" ]]; then
157+
"${PYTHON_EXECUTABLE}" -m examples.qualcomm.scripts.deeplab_v3 -b ${CMAKE_OUTPUT_DIR} -m SM8550 --compile_only --download
158+
EXPORTED_MODEL=./${CMAKE_OUTPUT_DIR}/deeplab_v3/dlv3_qnn.pte
159+
fi
160+
}
161+
132162
if [[ "${BACKEND}" == "portable" ]]; then
133163
echo "Testing ${MODEL_NAME} with portable kernels..."
134164
test_model
165+
elif [[ "${BACKEND}" == "qnn" ]]; then
166+
echo "Testing ${MODEL_NAME} with qnn..."
167+
test_model_with_qnn
168+
if [[ $? -eq 0 ]]; then
169+
prepare_artifacts_upload
170+
fi
135171
else
136172
set +e
137173
if [[ "${BACKEND}" == *"quantization"* ]]; then
@@ -153,5 +189,7 @@ else
153189
if [[ -n "${Q_ERROR:-}" ]] || [[ -n "${D_ERROR:-}" ]] || [[ -n "${Q_D_ERROR:-}" ]]; then
154190
echo "Portable q8 ${Q_ERROR:-ok}," "Delegation fp32 ${D_ERROR:-ok}," "Delegation q8 ${Q_D_ERROR:-ok}"
155191
exit 1
192+
else
193+
prepare_artifacts_upload
156194
fi
157195
fi

.github/workflows/android-perf.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,41 @@ 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::"
154+
155+
echo "::group::Exporting ${{ matrix.delegate }} model: ${{ matrix.model }}"
156+
BUILD_MODE="cmake"
157+
DTYPE="fp32"
158+
if [[ ${{ matrix.delegate }} == "qnn" ]]; then
159+
DELEGATE_CONFIG="qnn"
160+
elif [[ ${{ matrix.delegate }} == "xnnpack" ]]; then
161+
DELEGATE_CONFIG="xnnpack+custom+qe"
162+
fi
150163
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}"\
164+
if [[ ${{ matrix.model }} == "llama*" ]]; then
165+
# Install requirements for export_llama
166+
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
167+
# Test llama2
168+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh "${{ matrix.model }}.pt" "${BUILD_MODE}" "${DTYPE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
169+
else
170+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${{ matrix.model }}" "${BUILD_MODE}" "${DELEGATE_CONFIG}" "${ARTIFACTS_DIR_NAME}"
171+
fi
172+
echo "::endgroup::"
156173
157174
# Upload models to S3. The artifacts are needed not only by the device farm but also TorchChat
158175
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)