-
Notifications
You must be signed in to change notification settings - Fork 742
Add Run Android LlamaDemo with QNN backend #16011
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
base: main
Are you sure you want to change the base?
Changes from all commits
29f233a
2c39ea1
5ba7196
c67fca4
975c371
3731048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -288,6 +288,138 @@ After the above command, pre-processed inputs and outputs are put in `$EXECUTORC | |||||||||||||||||||||||||||||||||||||||||
| The command-line arguments are written in [utils.py](https://github.com/pytorch/executorch/blob/main/examples/qualcomm/utils.py#L139). | ||||||||||||||||||||||||||||||||||||||||||
| The model, inputs, and output location are passed to `qnn_executorch_runner` by `--model_path`, `--input_list_path`, and `--output_folder_path`. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ### Run [Android LlamaDemo](https://github.com/meta-pytorch/executorch-examples/tree/main/llm/android/LlamaDemo) with QNN backend | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| `$DEMO_APP` refers to the root of the executorch android demo, i.e., the directory containing `build.gradle.kts`. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 1***: Rebuild ExecuTorch AAR | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| # Build the AAR | ||||||||||||||||||||||||||||||||||||||||||
| cd $EXECUTORCH_ROOT | ||||||||||||||||||||||||||||||||||||||||||
| export BUILD_AAR_DIR=$EXECUTORCH_ROOT/aar-out | ||||||||||||||||||||||||||||||||||||||||||
| ./scripts/build_android_library.sh | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 2***: Copy AAR to Android Project | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| cp $EXECUTORCH_ROOT/aar-out/executorch.aar \ | ||||||||||||||||||||||||||||||||||||||||||
| $DEMO_APP/app/libs/executorch.aar | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 3***: Build Android APK | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| cd $DEMO_APP | ||||||||||||||||||||||||||||||||||||||||||
| ./gradlew clean assembleDebug -PuseLocalAar=true | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 4***: Install on Device | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| adb install -r app/build/outputs/apk/debug/app-debug.apk | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 5***: Push model | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| adb shell mkdir -p /data/local/tmp/llama | ||||||||||||||||||||||||||||||||||||||||||
| adb push model.pte /data/local/tmp/llama | ||||||||||||||||||||||||||||||||||||||||||
| adb push tokenizer.bin /data/local/tmp/llama | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+328
to
+329
|
||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 6***: Run the Llama Demo | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| - Open the App on Android | ||||||||||||||||||||||||||||||||||||||||||
| - Select `QUALCOMM` backend | ||||||||||||||||||||||||||||||||||||||||||
| - Select `model.pte` Model | ||||||||||||||||||||||||||||||||||||||||||
| - Select `tokenizer.bin` Tokenizer | ||||||||||||||||||||||||||||||||||||||||||
| - Select Model Type | ||||||||||||||||||||||||||||||||||||||||||
| - Click LOAD MODEL | ||||||||||||||||||||||||||||||||||||||||||
| - It should show `Successfully loaded model.` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| #### Verification Steps | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 1***. Verify AAR Contains Your Changes | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| # Check for debug strings in the AAR | ||||||||||||||||||||||||||||||||||||||||||
| unzip -p $DEMO_APP/app/libs/executorch.aar jni/arm64-v8a/libexecutorch.so | \ | ||||||||||||||||||||||||||||||||||||||||||
| strings | grep "QNN" # Replace "QNN" with your actual debug string if needed | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| If found, your changes are in the AAR. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ***Step 2***. Verify APK Contains Correct Libraries | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||||||
| # Check QNN library version in APK | ||||||||||||||||||||||||||||||||||||||||||
| cd $DEMO_APP | ||||||||||||||||||||||||||||||||||||||||||
| unzip -l app/build/outputs/apk/debug/app-debug.apk | grep "libQnnHtp.so" | ||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Expected size for QNN 2.37.0: ~2,465,440 bytes | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| Expected size for QNN 2.37.0: ~2,465,440 bytes | |
| Expected size for QNN 2.37.0: ~2.4–2.5 MB (2,400,000–2,500,000 bytes) |
luffy-yu marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The note appears after the 'Before' label but should appear before showing any code examples. Moving it above line 395 would make the documentation flow more clearly and prevent confusion about which versions to use.
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The note about version numbers being examples appears after mentioning 'version X' and 'version Y' in the previous text but before showing the actual version numbers. This note would be more effective if placed immediately after the code examples (after line 403) where the specific versions are shown, or reference should be made to it in the text above where X and Y are mentioned.
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numbered list item '1.' is followed by a note and code examples, but there's no item '2.' at the same indentation level until line 405. The note and code examples should be indented or formatted as sub-items of item 1 to maintain proper list structure.
| > **Note:** The version numbers below (`2.33.0` and `2.37.0`) are examples only. Please check for the latest compatible QNN runtime version or match your QNN SDK version to avoid API mismatches. | |
| **Before**: | |
| ```kotlin | |
| implementation("com.qualcomm.qti:qnn-runtime:2.33.0") | |
| ``` | |
| **After**: | |
| ```kotlin | |
| implementation("com.qualcomm.qti:qnn-runtime:2.37.0") | |
| ``` | |
| > **Note:** The version numbers below (`2.33.0` and `2.37.0`) are examples only. Please check for the latest compatible QNN runtime version or match your QNN SDK version to avoid API mismatches. | |
| **Before**: | |
| ```kotlin | |
| implementation("com.qualcomm.qti:qnn-runtime:2.33.0") | |
| ``` | |
| **After**: | |
| ```kotlin | |
| implementation("com.qualcomm.qti:qnn-runtime:2.37.0") | |
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external link points to 'meta-pytorch/executorch-examples' but the PR is in the 'pytorch/executorch' repository. Verify this is the correct repository reference for the LlamaDemo, as it may confuse users if the link is incorrect or if the demo has moved.