Skip to content

Add stories ci for qnn #4662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
61c57ca
update qnn sdk
cccclai Aug 11, 2024
488e98b
add try 3
cccclai Aug 11, 2024
b16a17b
more fix to sdk download
cccclai Aug 11, 2024
0e4cd80
fix the qnn sdk path
cccclai Aug 12, 2024
b25acc8
fix qnn sdk path
cccclai Aug 12, 2024
0cd8823
fix qnn sdk path
cccclai Aug 12, 2024
34fce2a
fix qnn sdk path
cccclai Aug 12, 2024
ebaf390
fix qnn path
cccclai Aug 12, 2024
f912c76
fix next
cccclai Aug 12, 2024
03919c8
fix qnn path
cccclai Aug 12, 2024
00024a9
fix conda run
cccclai Aug 12, 2024
12902f8
set env
cccclai Aug 12, 2024
6565dbd
install
cccclai Aug 12, 2024
16992fa
fix build script
cccclai Aug 12, 2024
8b2aa83
fix build
cccclai Aug 12, 2024
7f56881
skip aarch64
cccclai Aug 12, 2024
ccae714
change job number
cccclai Aug 12, 2024
4a76821
change job numbers
cccclai Aug 12, 2024
5f8975c
change job numbers
cccclai Aug 12, 2024
822df7b
fix qnn build
cccclai Aug 12, 2024
61e2b1d
add export file
cccclai Aug 12, 2024
14e5aa8
fix python import
cccclai Aug 12, 2024
35101b7
copy .fbs file
cccclai Aug 12, 2024
6d6ad5e
fix unbound var
cccclai Aug 12, 2024
f7755c9
fix unbound var
cccclai Aug 12, 2024
2270a79
copy .so
cccclai Aug 12, 2024
e451533
fix copy so
cccclai Aug 12, 2024
0def468
debug partitioner import
cccclai Aug 12, 2024
89b29a1
fix python path
cccclai Aug 12, 2024
207f76c
recover the rest of the tests
cccclai Aug 12, 2024
d93f52c
fix other tests
cccclai Aug 12, 2024
757c62e
move to trunk
cccclai Aug 12, 2024
be000bd
move to trunk
cccclai Aug 12, 2024
fa09ace
use qnn docker
cccclai Aug 12, 2024
5a9fe4d
fix docker
cccclai Aug 12, 2024
67062b0
fix mac llama
cccclai Aug 13, 2024
6da04ae
fix mac llama
cccclai Aug 13, 2024
5174d8f
update qnn build output place
cccclai Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .ci/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ case "${IMAGE_NAME}" in
ARM_SDK=yes
CLANG_VERSION=12
;;
executorch-ubuntu-22.04-qnn-sdk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding qnn sdk by extending the executorch-ubuntu-22.04-clang12-android image below? QNN backend would require ndk and cross-compilation, making it a good fit to the android image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not android, it's x86

QNN_SDK=yes
CLANG_VERSION=12
;;
executorch-ubuntu-22.04-clang12-android)
LINTRUNNER=""
CLANG_VERSION=12
Expand All @@ -59,6 +63,9 @@ cp ../../requirements-lintrunner.txt ./
# with a new image hash when the content here is updated
cp -r ../../examples/arm/ ./arm

# Copy qnn setup script from root to here
cp -r ../../backends/qualcomm/ ./qualcomm

docker build \
--no-cache \
--progress=plain \
Expand All @@ -72,6 +79,7 @@ docker build \
--build-arg "LINTRUNNER=${LINTRUNNER:-}" \
--build-arg "BUILD_DOCS=${BUILD_DOCS}" \
--build-arg "ARM_SDK=${ARM_SDK:-}" \
--build-arg "QNN_SDK=${QNN_SDK:-}" \
--build-arg "ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-}" \
-f "${OS}"/Dockerfile \
"$@" \
Expand Down
5 changes: 5 additions & 0 deletions .ci/docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@ COPY --chown=ci-user:ci-user ./arm /opt/arm
# Set up ARM SDK if needed
RUN if [ -n "${ARM_SDK}" ]; then git config --global user.email "ossci@example.com"; git config --global user.name "OSS CI"; bash /opt/arm/setup.sh --i-agree-to-the-contained-eula /opt/arm-sdk; chown -R ci-user:ci-user /opt/arm-sdk; fi

ARG QNN_SDK
COPY --chown=ci-user:ci-user ./qualcomm /opt/qualcomm
# Set up QNN SDK if needed
RUN if [ -n "${QNN_SDK}" ]; then git config --global user.email "ossci@example.com"; git config --global user.name "OSS CI"; fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARG QNN_SDK
COPY --chown=ci-user:ci-user ./scripts/setup-qnn-deps.sh setup-qnn-deps.sh
# Set up QNN SDK if needed
RUN if [ -n "${QNN_SDK}" ]; then ./setup-qnn-deps.sh; fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARG QNN_SDK
COPY --chown=ci-user:ci-user ./scripts/setup-qnn-deps.sh setup-qnn-deps.sh
RUN mkdir /opt/qualcomm; chown ci-user:ci-user /opt/qualcomm
RUN if [ -n "${QNN_SDK}" ]; then ./setup-qnn-deps.sh; fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARG QNN_SDK
COPY --chown=ci-user:ci-user ./scripts/setup-qnn-deps.sh setup-qnn-deps.sh
RUN if [ -n "${QNN_SDK}" ]; then mkdir /opt/qualcomm; chown ci-user:ci-user /opt/qualcomm; ./setup-qnn-deps.sh; fi

USER ci-user
CMD ["bash"]
19 changes: 19 additions & 0 deletions .ci/scripts/build-qnn-sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -ex

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

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

build_qnn_backend
29 changes: 29 additions & 0 deletions .ci/scripts/setup-qnn-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -ex

install_qnn() {
echo "Start installing qnn."
QNN_INSTALLATION_DIR=/tmp/qnn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe /opt instead of /tmp ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah will address it in next diff

mkdir -p "${QNN_INSTALLATION_DIR}"

curl -Lo /tmp/v2.23.0.24.06.24.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.23.0.24.06.24.zip"
echo "Finishing downloading qnn sdk."
unzip -qo /tmp/v2.23.0.24.06.24.zip -d /tmp
echo "Finishing unzip qnn sdk."


# Print the content for manual verification
ls -lah "/tmp/qairt"
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."

ls -lah "${QNN_INSTALLATION_DIR}"
}

install_qnn
24 changes: 24 additions & 0 deletions .ci/scripts/test_llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ fi

echo "COREML option ${COREML}"

if [[ "${MODE}" =~ .*qnn.* ]]; then
QNN=ON
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
export QNN_SDK_ROOT=/tmp/qnn/2.23.0.240531
export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang"
export PYTHONPATH=".."
cp schema/program.fbs exir/_serialize/program.fbs
cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs
cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python
cp -f build-x86/backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python

else
QNN=OFF
QNN_SDK_ROOT=""
fi

echo "QNN option ${QNN}"
echo "QNN_SDK_ROOT: ${QNN_SDK_ROOT}"

if [[ -z "${BUCK:-}" ]]; then
BUCK=buck2
fi
Expand All @@ -96,6 +115,8 @@ cmake_install_executorch_libraries() {
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
-DEXECUTORCH_BUILD_MPS="$MPS" \
-DEXECUTORCH_BUILD_COREML="$COREML" \
-DEXECUTORCH_BUILD_QNN="$QNN" \
-DQNN_SDK_ROOT="$QNN_SDK_ROOT" \
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-Bcmake-out .
cmake --build cmake-out -j9 --target install --config Debug
Expand Down Expand Up @@ -176,6 +197,9 @@ fi
if [[ "${COREML}" == "ON" ]]; then
EXPORT_ARGS="${EXPORT_ARGS} -kv -v --coreml --disable_dynamic_shape"
fi
if [[ "${QNN}" == "ON" ]]; then
EXPORT_ARGS="${EXPORT_ARGS} -kv -v --qnn --disable_dynamic_shape"
fi
# Add dynamically linked library location
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama ${EXPORT_ARGS}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- docker-image-name: executorch-ubuntu-22.04-clang12
- docker-image-name: executorch-ubuntu-22.04-linter
- docker-image-name: executorch-ubuntu-22.04-arm-sdk
- docker-image-name: executorch-ubuntu-22.04-qnn-sdk
- docker-image-name: executorch-ubuntu-22.04-clang12-android
env:
DOCKER_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/executorch/${{ matrix.docker-image-name }}
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,38 @@ jobs:
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/models/llama2/install_requirements.sh
# Test llama2
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"


test-llama-runner-qnn-linux:
name: test-llama-runner-qnn-linux
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
strategy:
matrix:
dtype: [fp32]
build-tool: [cmake]
mode: [qnn]
fail-fast: false
with:
runner: linux.2xlarge
docker-image: executorch-ubuntu-22.04-qnn-sdk
submodules: 'true'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
timeout: 900
script: |
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"

DTYPE=${{ matrix.dtype }}
BUILD_TOOL=${{ matrix.build-tool }}
MODE=${{ matrix.mode }}

PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh

# Setup executorch
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
# Install requirements for export_llama
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
# Test llama2
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
2 changes: 1 addition & 1 deletion backends/qualcomm/aot/python/PyQnnWrapperAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PyQnnOpWrapper {
break;
default:
QNN_EXECUTORCH_LOG_ERROR(
"%s has invalid data type: %d", name, data_type);
"%s has invalid data type: %d", name.c_str(), data_type);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions backends/qualcomm/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ usage() {
[ "$1" = -h ] && usage

BUILD_X86_64="true"
CMAKE_X86_64="cmake-out"
CMAKE_X86_64="build-x86"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chiwwang I rename it to the similar name as before, because the ci job will clean up cmake-out for every run. We can make build.sh takes configurable name as next step and change the default name to cmake-out and cmake-out-android

BUILD_AARCH64="true"
CMAKE_AARCH64="cmake-out-android"
CMAKE_AARCH64="build-android"
CLEAN="true"
BUILD_TYPE="Debug"
BUILD_JOB_NUMBER="16"
Expand Down
Loading