Skip to content

Commit a524e0e

Browse files
authored
Merge pull request #1712 from HenryDen/ViT_MNN_submit
Modify Vision LLM inference on Android with KleidiAI and MNN Page
2 parents ed50d31 + 094052d commit a524e0e

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Build the MNN Command-line ViT Demo
2+
title: Benchmark the Vision Transformer performance with KleidiAI
33
weight: 4
44

55
### FIXED, DO NOT MODIFY
@@ -35,12 +35,16 @@ $ git clone https://github.com/alibaba/MNN.git
3535
$ mkdir build_64 && cd build_64
3636
$ ../build_64.sh "-DMNN_LOW_MEMORY=true -DLLM_SUPPORT_VISION=true -DMNN_KLEIDIAI=true -DMNN_CPU_WEIGHT_DEQUANT_GEMM=true -DMNN_BUILD_LLM=true -DMNN_SUPPORT_TRANSFORMER_FUSE=true -DMNN_ARM82=true -DMNN_OPENCL=true -DMNN_USE_LOGCAT=true -DMNN_IMGCODECS=true -DMNN_BUILD_OPENCV=true"
3737
$ adb push *so llm_demo tools/cv/*so /data/local/tmp/
38-
$ adb shell
3938
```
4039

40+
The Build parameter above ```-DMNN_KLEIDIAI ```is to enable the kleidiAI on the MNN, it can be set to false to disable the KleidiAi.
41+
42+
## Test the performance within/without kleidiAi
43+
4144
Here switch to android adb shell environment.
4245

4346
```shell
47+
$ adb shell
4448
$ cd /data/local/tmp/
4549
$ chmod +x llm_demo
4650
$ export LD_LIBRARY_PATH=./
@@ -73,3 +77,10 @@ prefill speed = 135.29 tok/s
7377
##################################
7478
```
7579
80+
Here is my performance comparation within/without kleidiAI
81+
82+
| | KleidiAI OFF | KleidiAi ON |
83+
|----------|----------|----------|
84+
| Vision Process Time | 5.45s | 5.43 s |
85+
| Prefill Speed | 132.35 tok/s | 148.30 tok/s |
86+
| Decode Speed | 21.61 tok/s | 33.26 tok/s |

content/learning-paths/mobile-graphics-and-gaming/Vision-LLM-inference-on-Android-with-KleidiAI-and-MNN/Build_the_MNN_Android_Demo_with_GUI.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Open up a Windows PowerShell or Git Bash and checkout the source tree:
2424
cd C:\Users\$env:USERNAME
2525
git clone https://github.com/HenryDen/MNN.git
2626
cd MNN
27-
git checkout 83b650fc8888d7ccd38dbc68330a87d048b9fe7a
27+
git checkout origin/MNN_commit
2828
```
2929

3030
{{% notice Note %}}
@@ -33,28 +33,15 @@ The app code is currently not merged into the MNN repo. The repo above is a fork
3333

3434
## Build the app using Android Studio
3535

36-
Create a signing.gradle file at android/app with the following template:
37-
```shell
38-
ext{
39-
signingConfigs = [
40-
release: [
41-
storeFile: file('PATH_TO_jks_file'),
42-
storePassword: "****",
43-
keyAlias: "****",
44-
keyPassword: "****"
45-
]
46-
]
47-
}
48-
```
36+
Open Android Studio
4937

50-
If you don't need to compile a release version of the app, you can skip the following step of creating a sign file and write anything in the signing.gradle.
38+
- Navigate to **Open**.
39+
- Browse the folder to the MNN/transformers/llm/engine/android, it will be android icon as picture show,
40+
- Press **OK** to load the android project
41+
- Wait for a while till the Gradle sync finish
5142

52-
- Navigate to **Build -> Generate Signed App Bundle or APK**.
53-
- Select **APK** and click **next**.
54-
- Press **Create new** and fill in the information..
55-
- Fill in the information of the newly generated JKS file in the template above.
43+
![Loading screenshot](open_project.png)
5644

57-
Open the MNN/transformers/llm/engine/android directory with Android Studio and wait for the Gradle project sync to finish.
5845

5946
## Prepare the model
6047
You can download the model from ModelScope : https://www.modelscope.cn/models/qwen/qwen2-vl-2b-instruct
@@ -79,7 +66,7 @@ $ llmexport --path /path/to/mnn-llm/Qwen2-VL-2B-Instruct/ --export mnn --quant_b
7966
- --sym: the quantization parameter, means symmetrical quantization.
8067

8168
## Build and run the app
82-
Before launching the app, you need to push the model into the device manually:
69+
Before launching the app, you need to push the model into the device manually, connect the android device with the host PC with usb, and make sure the USB debugging is enable in the android device:
8370

8471
```shell
8572
$ adb shell mkdir /data/local/tmp/models/
45.9 KB
Loading

0 commit comments

Comments
 (0)