Skip to content

Commit 10d0292

Browse files
committed
Update on "[Executorch] Add quantized kv cache to oss ci"
Fixes to make sure quantized kv cache works in oss Differential Revision: [D66269487](https://our.internmc.facebook.com/intern/diff/D66269487/) [ghstack-poisoned]
2 parents 982bc6a + 0f817ad commit 10d0292

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ build_qnn_backend() {
1212
echo "Start building qnn backend."
1313
export ANDROID_NDK_ROOT=/opt/ndk
1414
export QNN_SDK_ROOT=/tmp/qnn/2.25.0.240728
15-
export EXECUTORCH_SRC_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
16-
export EXECUTORCH_INSTALL_ROOT="$(python -c 'import executorch; print(executorch.__path__[0])')"
17-
if [ "$EXECUTORCH_INSTALL_ROOT" == "" ]; then
18-
echo "Failed to find where executorch package is installed."
19-
echo "import executorch failed"
20-
exit -1
21-
fi
15+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
2216

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

2620
set_up_aot() {
27-
cd $EXECUTORCH_SRC_ROOT
21+
cd $EXECUTORCH_ROOT
2822
if [ ! -d "cmake-out" ]; then
2923
mkdir cmake-out
3024
fi
@@ -42,8 +36,8 @@ set_up_aot() {
4236
cmake --build $PWD --target "PyQnnManagerAdaptor" "PyQnnWrapperAdaptor" -j$(nproc)
4337
# install Python APIs to correct import path
4438
# The filename might vary depending on your Python and host version.
45-
cp -f backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_INSTALL_ROOT/backends/qualcomm/python
46-
cp -f backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_INSTALL_ROOT/backends/qualcomm/python
39+
cp -f backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
40+
cp -f backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
4741
popd
4842

4943
# Workaround for fbs files in exir/_serialize

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ if [[ "${MODE}" =~ .*qnn.* ]]; then
113113
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
114114
export QNN_SDK_ROOT=/tmp/qnn/2.25.0.240728
115115
export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang"
116+
export PYTHONPATH=".."
116117
cp schema/program.fbs exir/_serialize/program.fbs
117118
cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs
118119
cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python

.ci/scripts/test_model.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ test_model_with_qnn() {
152152
source "$(dirname "${BASH_SOURCE[0]}")/build-qnn-sdk.sh"
153153
echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
154154
echo "QNN_SDK_ROOT: $QNN_SDK_ROOT"
155+
echo "EXECUTORCH_ROOT: $EXECUTORCH_ROOT"
155156

156157
export LD_LIBRARY_PATH=$QNN_SDK_ROOT/lib/x86_64-linux-clang/
158+
export PYTHONPATH=$EXECUTORCH_ROOT/..
157159

158160
if [[ "${MODEL_NAME}" == "dl3" ]]; then
159161
EXPORT_SCRIPT=deeplab_v3

examples/models/llama/source_transformation/quantized_kv_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import torch.nn as nn
1212
from executorch.examples.models.llama.llama_transformer import KVCache
1313

14+
# This is needed to ensure that custom ops are registered
15+
from executorch.extension.pybindings import portable_lib # noqa # usort: skip
1416
from executorch.extension.llm.custom_ops import custom_ops # noqa: F401
1517
from torch.ao.quantization.fx._decomposed import quantized_decomposed_lib # noqa: F401
1618

@@ -23,7 +25,10 @@
2325

2426
import executorch
2527

26-
executorch_package_path = executorch.__path__[0]
28+
# Ideally package is installed in only one location but usage of
29+
# PYATHONPATH can result in multiple locations.
30+
# ATM this is mainly used in CI for qnn runner. Will need to revisit this
31+
executorch_package_path = executorch.__path__[-1]
2732
libs = list(
2833
glob.glob(
2934
f"{executorch_package_path}/**/libquantized_ops_aot_lib.*", recursive=True

extension/llm/custom_ops/custom_ops.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626

2727
import executorch
2828

29-
executorch_package_path = executorch.__path__[0]
29+
# Ideally package is installed in only one location but usage of
30+
# PYATHONPATH can result in multiple locations.
31+
# ATM this is mainly used in CI for qnn runner. Will need to revisit this
32+
executorch_package_path = executorch.__path__[-1]
3033
logging.info(f"Looking for libcustom_ops_aot_lib.so in {executorch_package_path }")
3134
libs = list(
3235
glob.glob(

0 commit comments

Comments
 (0)