|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Qualcomm Innovation Center, Inc. |
| 3 | +# All rights reserved |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +set -euxo pipefail |
| 9 | + |
| 10 | +source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" |
| 11 | + |
| 12 | +TASK_NAME=$1 |
| 13 | +if [[ -z "${TASK_NAME:-}" ]]; then |
| 14 | + echo "Missing task name, exiting..." |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | + |
| 19 | +# Download QNN_SDK. If already downloaded, export environment path |
| 20 | +source "$(dirname "${BASH_SOURCE[0]}")/../../backends/qualcomm/scripts/install_qnn_sdk.sh" |
| 21 | +install_qnn |
| 22 | + |
| 23 | +export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" |
| 24 | +export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang" |
| 25 | +export PYTHONPATH=".." |
| 26 | +cp schema/program.fbs exir/_serialize/program.fbs |
| 27 | +cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs |
| 28 | +cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python |
| 29 | +cp -f build-x86/backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python |
| 30 | + |
| 31 | +if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then |
| 32 | + PYTHON_EXECUTABLE=python3 |
| 33 | +fi |
| 34 | + |
| 35 | +which "${PYTHON_EXECUTABLE}" |
| 36 | + |
| 37 | +# Although static llama CI does not require graphviz, it is required by test_qnn_delegate.py |
| 38 | +pip install graphviz |
| 39 | + |
| 40 | +set +e |
| 41 | + |
| 42 | +echo "Executing task: $TASK_NAME" |
| 43 | +if [[ "${TASK_NAME}" == "stories_110m" ]]; then |
| 44 | + # Download stories llama110m artifacts |
| 45 | + download_stories_model_artifacts |
| 46 | + echo "Creating tokenizer.bin" |
| 47 | + $PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin |
| 48 | + |
| 49 | + # 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 |
| 51 | + exit_code1=$? |
| 52 | + |
| 53 | + # 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 |
| 55 | + exit_code2=$? |
| 56 | + |
| 57 | + # Check the exit codes and print messages |
| 58 | + if [ $exit_code1 -ne 0 ]; then |
| 59 | + echo "Static Llama compile only with weight sharing test failed. $exit_code1." |
| 60 | + fi |
| 61 | + |
| 62 | + if [ $exit_code2 -ne 0 ]; then |
| 63 | + echo "Static Llama accuracy test failed. $exit_code2." |
| 64 | + fi |
| 65 | + |
| 66 | + if [ $exit_code1 -ne 0 ] || [ $exit_code2 -ne 0 ]; then |
| 67 | + exit 1 |
| 68 | + else |
| 69 | + exit 0 |
| 70 | + fi |
| 71 | + |
| 72 | +elif [[ "${TASK_NAME}" == "stories_260k_bc" ]]; then |
| 73 | + |
| 74 | + # Check BC |
| 75 | + bash backends/qualcomm/bc/test_qnn_static_llama_bc.sh |
| 76 | + exit_code1=$? |
| 77 | + if [ $exit_code1 -ne 0 ]; then |
| 78 | + exit 1 |
| 79 | + else |
| 80 | + exit 0 |
| 81 | + fi |
| 82 | + |
| 83 | +elif [[ "${TASK_NAME}" == "smollm2_135m" ]]; then |
| 84 | + $PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_static_smollm2 --model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir ./static_smollm2 --enable_x86_64 |
| 85 | + exit_code1=$? |
| 86 | + if [ $exit_code1 -ne 0 ]; then |
| 87 | + exit 1 |
| 88 | + else |
| 89 | + exit 0 |
| 90 | + fi |
| 91 | +else |
| 92 | + echo "Unsupported task: $TASK_NAME" |
| 93 | + exit 1 |
| 94 | +fi |
0 commit comments