Skip to content

Commit 37c2b14

Browse files
committed
Retest MNN build and llm_demo
1 parent c9d4a98 commit 37c2b14

3 files changed

Lines changed: 204 additions & 58 deletions

File tree

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
---
22
title: Multimodal On-Device Inference on Arm v9 with MNN for Audio and Vision
3-
weight: 2
4-
53
layout: learningpathall
4+
weight: 2
65
---
76

7+
## Introduction
8+
9+
This module explains why **[MNN](https://github.com/alibaba/MNN)** and an **Omni multimodal model** are a practical combination for **CPU-only on-device inference** on Arm v9 Linux. You will use a single runtime and a single model to run **vision**, **audio**, and **text** prompts, then combine image + audio inputs to generate an operational **restock ticket**.
10+
811
## Why MNN for on-device deployment
912

10-
- **Portable inference runtime** with strong support for mobile and edge platforms
11-
- **CPU-first workflow** that maps naturally to Armv9 servers and development boards
12-
- Native builds allow you to benefit from **Arm-specific optimizations** (such as KleidiAI)
13-
- Single codebase can target x86, Arm Linux, Android, and iOS
13+
MNN is a deployment-focused inference runtime that works well for edge and mobile-style workloads:
14+
15+
- A **portable runtime** widely used across mobile and embedded environments
16+
- A **CPU-first workflow** that maps naturally to Arm v9 Linux systems
17+
- Native builds can take advantage of **Arm-specific optimizations** (for example, KleidiAI when enabled)
18+
- One codebase can target multiple platforms such as Arm Linux, Android, iOS, and x86 hosts
1419

1520
## Why Omni multimodal
1621

17-
- **Single model** that can handle **image, audio, and text** in one pipeline
18-
- Enables **cross-modal tasks** such as “look at this shelf + listen to this note → generate an operational ticket”
19-
- **Prompt-based control** with tags like `<img>…</img>` and `<audio>…</audio>`
20-
- No need to maintain separate models for vision and speech
22+
Omni models simplify multimodal applications by keeping image, audio, and text in a single pipeline:
23+
24+
- One model can handle **image + audio + text** prompts
25+
- Enables cross-modal tasks such as **“audit the shelf image + listen to a voice note → produce a restock ticket”**
26+
- Prompt control using tags like `<img>...</img>` and `<audio>...</audio>`
27+
- Reduces operational complexity versus maintaining separate vision and speech models
2128

22-
## Scope boundaries for reproducibility
29+
## Scope
2330

24-
To keep this Learning Path simple and repeatable, we deliberately limit the scope:
31+
To keep this learning path reproducible and easy to complete, we intentionally constrain the scope:
2532

2633
- **CPU-only**
2734
No GPU or NPU acceleration is required.
2835

29-
- **No quantization**
30-
You use a **prebuilt MNN Omni model package** as-is. No additional export or quantization steps are needed.
36+
- **No export or quantization steps**
37+
You will use a **prebuilt MNN Omni model package** as-is.
3138

3239
- **No CPU–NPU heterogeneous pipeline**
33-
All compute runs on the Armv9 CPU. Focus is on **correctness and reproducibility**, not maximum throughput.
40+
All compute runs on the Arm v9 CPU. The focus is correctness and reproducibility.
41+
42+
## Next
43+
44+
In the next module, you will build MNN on Arm v9 and prepare the prebuilt Omni model and local demo assets.

content/learning-paths/cross-platform/multimodel_mnn_v9/2_mnn_build.md

Lines changed: 88 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,38 @@ weight: 3
44
layout: learningpathall
55
---
66

7-
## Get source and native build
7+
## Overview
88

9-
Create a working directory under your home folder:
9+
In this module you will build **MNN** natively on your Arm v9 Linux system and verify that the `llm_demo` binary can load a **prebuilt Omni MNN model package**. This sets up everything needed for the text, vision, and audio demos in later modules.
10+
11+
By the end of this module you will have:
12+
13+
- A working `llm_demo` binary
14+
- A verified Omni model directory containing `config.json`
15+
- A runtime environment that loads the correct MNN shared libraries
16+
17+
18+
## Step 1 - Create a working directory
19+
20+
Create a workspace under your home directory:
1021

1122
```bash
12-
cd ~
13-
mkdir -p ~/mnn_lp
14-
cd ~/mnn_lp
23+
mkdir -p ~/mnn
24+
cd ~/mnn
1525
```
1626

17-
Clone and build MNN:
27+
## Step 2 - Clone and build MNN (native build)
28+
29+
Clone the MNN repository:
1830

1931
```bash
2032
git clone https://github.com/alibaba/MNN.git
2133
cd MNN
34+
```
35+
36+
Configure and build:
37+
38+
```bash
2239

2340
rm -rf build
2441
mkdir build && cd build
@@ -36,67 +53,104 @@ make -j$(nproc)
3653

3754
**Key CMake options:**
3855

39-
- `MNN_BUILD_LLM=ON` – enables LLM support
40-
- `MNN_BUILD_AUDIO=ON` – enables audio features needed for Omni
41-
- `MNN_BUILD_LLM_OMNI=ON` – enables multimodal Omni support
42-
- `MNN_LOW_MEMORY=ON` – uses lower memory configurations where possible
43-
- `MNN_KLEIDIAI=ON` – enables KleidiAI-related optimizations on supported Arm platforms
56+
- `MNN_BUILD_LLM=ON` enables LLM support required by llm_demo
57+
- `MNN_BUILD_AUDIO=ON` enables audio features used by Omni
58+
- `MNN_BUILD_LLM_OMNI=ON` enables Omni multimodal support
59+
- `MNN_LOW_MEMORY=ON` prefers lower-memory configurations where available
60+
- `MNN_KLEIDIAI=ON` enables KleidiAI-related optimizations on supported Arm platforms
61+
4462

4563
Verify that `llm_demo` was built:
4664

4765
```bash
48-
ls -l ~/mnn_lp/MNN/build/llm_demo
66+
ls -l ~/mnn/MNN/build/llm_demo
4967
```
5068

5169

52-
## Avoid library mismatch
70+
## Step 3 - Confirm the correct shared libraries are loaded
5371

54-
On systems with multiple MNN builds, a common pitfall is a **binary from one build tree** loading a **shared library from another**.
72+
If your system has more than one MNN installation, a common pitfall is building llm_demo in one location but loading libMNN.so from another.
5573

56-
Check which libraries `llm_demo` will use:
74+
From the build directory, inspect runtime dependencies:
5775

5876
```bash
59-
cd ~/mnn_lp/MNN/build
60-
ldd ./llm_demo
77+
cd ~/mnn/MNN/build
78+
ldd ./llm_demo | grep -E "libMNN|Express|Audio|OpenCV" || true
6179
```
6280

63-
Ensure that `libMNN.so` and related libraries point to your **current build directory**.
81+
You should see `libMNN.so` and `libMNN_Express.so` resolving from your ~/mnn/MNN/build tree.
6482

65-
If you see a mismatch, set `LD_LIBRARY_PATH` explicitly:
83+
```
84+
libMNNAudio.so => /home/radxa/mnn/MNN/build/tools/audio/libMNNAudio.so (0x0000ffffb6d00000)
85+
libMNN_Express.so => /home/radxa/mnn/MNN/build/express/libMNN_Express.so (0x0000ffffb6c00000)
86+
libMNN.so => /usr/share/cix/lib/libMNN.so (0x0000ffffb6600000)
87+
libMNNOpenCV.so => /home/radxa/mnn/MNN/build/tools/cv/libMNNOpenCV.so (0x0000ffffb61a0000)
88+
```
89+
90+
If you see `libMNN.so` coming from a different directory, set `LD_LIBRARY_PATH` to prefer your build output:
6691

6792
```bash
68-
export LD_LIBRARY_PATH=~/mnn_lp/MNN/build:$LD_LIBRARY_PATH
93+
export LD_LIBRARY_PATH=$HOME/mnn/MNN/build:$HOME/mnn/MNN/build/express:$HOME/mnn/MNN/build/tools/audio:$HOME/mnn/MNN/build/tools/cv:${LD_LIBRARY_PATH:-}
6994
```
7095

71-
Re-run `ldd` or `./llm_demo` to confirm the correct shared libraries are used.
96+
Re-check:
7297

98+
```bash
99+
ldd ./llm_demo | grep -E "libMNN|Express|Audio|OpenCV" || true
100+
```
73101

74-
## Download a prebuilt MNN Omni model
75102

76-
This Learning Path assumes you have a prebuilt Omni model package, for example:
103+
## Step 4 - Download and verify a prebuilt MNN Omni model package
77104

78-
```bash
79-
~/mnn_lp/Qwen2.5-Omni-7B-MNN
80-
```
105+
This learning path uses a prebuilt [Omni model package](https://huggingface.co/taobao-mnn/Qwen2.5-Omni-7B-MNN) that is already in MNN deployable format.
81106

82-
The directory should contain at least a `config.json` and the associated model files.
107+
Store the model directory into `~/mnn`
83108

84-
Verify the config path:
109+
```bash
110+
cd ~/mnn
111+
git clone https://www.modelscope.cn/MNN/Qwen2.5-Omni-7B-MNN.git
112+
```
85113

114+
Verify config.json exists:
86115
```bash
87-
ls -l ~/mnn_lp/Qwen2.5-Omni-7B-MNN/config.json
116+
cat ~/mnn/Qwen2.5-Omni-7B-MNN/config.json
117+
```
118+
119+
```
120+
{
121+
"llm_model": "llm.mnn",
122+
"llm_weight": "llm.mnn.weight",
123+
"backend_type": "cpu",
124+
"thread_num": 4,
125+
"precision": "low",
126+
"memory": "low",
127+
"system_prompt": "You are Qwen, a virtual human developed by the Qwen Team, Alibaba Group, capable of perceiving auditory and visual inputs, as well as generating text and speech.",
128+
"talker_max_new_tokens": 2048,
129+
"talker_speaker": "Chelsie",
130+
"dit_steps": 5,
131+
"dit_solver": 1,
132+
"mllm": {
133+
"backend_type": "cpu",
134+
"thread_num": 4,
135+
"precision": "normal",
136+
"memory": "low"
137+
}
138+
}
88139
```
89140

90-
**Important:** This is an **MNN-ready Omni package**. You **do not** need to export from PyTorch or perform additional quantization.
141+
{{% notice Note %}}
142+
This is an MNN-ready model package.
143+
You do not need to export from PyTorch or run additional quantization steps.
144+
{{% /notice %}}
91145

92146

93-
## Checkpoint
147+
### Checkpoint
94148

95-
You should be able to start `llm_demo` with your config:
149+
Start `llm_demo` with your model config:
96150

97151
```bash
98-
cd ~/mnn_lp/MNN/build
99-
./llm_demo ~/mnn_lp/Qwen2.5-Omni-7B-MNN/config.json
152+
cd ~/mnn/MNN/build
153+
./llm_demo ~/mnn/Qwen2.5-Omni-7B-MNN/config.json
100154
```
101155

102156
If the binary starts without `undefined symbol` or library errors, you are ready for the next module.

content/learning-paths/cross-platform/multimodel_mnn_v9/3_mnn_text_baseline.md

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,110 @@ weight: 4
44
layout: learningpathall
55
---
66

7-
## Run the text baseline
7+
## Overview
88

9-
Create a simple text prompt file:
9+
Before running vision and audio prompts, validate that your **runtime + model + prompt I/O** are working end-to-end. In this module you will run a **text-only baseline** using the same Omni model you will use later for multimodal prompts.
10+
11+
By the end of this module you will confirm:
12+
13+
- `llm_demo` can load your `config.json` without errors
14+
- A prompt file is parsed correctly (one line per prompt)
15+
- The model returns stable, sensible text output
16+
17+
18+
## Step 1 - Create a baseline prompt file
19+
20+
Create a simple text prompt file. Keep it short so you can quickly verify the pipeline.
1021

1122
```bash
12-
cat > ~/mnn_lp/text_baseline_prompt.txt <<'EOF'
13-
You are an on-device assistant. In one short sentence, describe the goal of this tutorial.
23+
cat > ~/mnn/text_baseline_prompt.txt <<'EOF'
24+
You are an on-device inference assistant. In one short sentence, describe the benefits of multimodal on-device inference.
1425
EOF
1526
```
1627

17-
Run `llm_demo`:
28+
{{% notice Note %}}
29+
llm_demo commonly treats each line as a separate prompt. Keep prompts one per line.
30+
{{% /notice %}}
31+
32+
33+
## Step 2 - Run llm_demo in batch mode
34+
35+
Run llm_demo with your Omni model config.json and the prompt file:
1836

1937
```bash
2038
cd ~/mnn_lp/MNN/build
21-
./llm_demo ~/mnn_lp/Qwen2.5-Omni-7B-MNN/config.json ~/mnn_lp/text_baseline_prompt.txt
39+
./llm_demo ~/mnn/Qwen2.5-Omni-7B-MNN/config.json ~/mnn/text_baseline_prompt.txt
40+
```
41+
42+
You should see a response describing the benefits of multimodal on-device inference.
43+
44+
45+
```
46+
config path is /home/radxa/mnn/Qwen2.5-Omni-7B-MNN/config.json
47+
CPU Group: [ 1 2 3 4 ], 799999 - 1800968
48+
CPU Group: [ 7 8 ], 799897 - 2199795
49+
CPU Group: [ 5 6 ], 799897 - 2299896
50+
CPU Group: [ 9 10 ], 799897 - 2399998
51+
CPU Group: [ 0 11 ], 799897 - 2500100
52+
The device supports: i8sdot:1, fp16:1, i8mm: 1, sve2: 1, sme2: 0
53+
main, 274, cost time: 5683.311035 ms
54+
Prepare for tuning opt Begin
55+
Prepare for tuning opt End
56+
main, 282, cost time: 751.726013 ms
57+
prompt file is /home/radxa/mnn/text_baseline_prompt.txt
58+
The benefits are: - It reduces the need for cloud-based services. - It can be used in areas with limited internet connectivity. - It can save on data transfer costs. - It can be used for real-time processing. - It can improve the privacy of data processing.
59+
60+
Multimodal on-device inference has several benefits, including reducing the need for cloud-based services, allowing usage in areas with poor internet connectivity, saving on data transfer costs, enabling real-time processing, and enhancing privacy during data processing. It's a great way to handle various tasks efficiently, especially when you don't want to rely too much on the cloud.
2261
```
2362

24-
You should see a short textual response describing the tutorial’s goal.
63+
64+
65+
66+
## Step 3 - Add a second prompt to validate multi-line behavior
67+
68+
Append a second prompt line to confirm that llm_demo processes prompts line-by-line.
69+
70+
```bash
71+
cat >> ~/mnn_lp/text_baseline_prompt.txt <<'EOF'
72+
What's Arm CPU arch?
73+
EOF
74+
```
75+
76+
77+
```
78+
config path is /home/radxa/mnn/Qwen2.5-Omni-7B-MNN/config.json
79+
CPU Group: [ 1 2 3 4 ], 799999 - 1800968
80+
CPU Group: [ 7 8 ], 799897 - 2199795
81+
CPU Group: [ 5 6 ], 799897 - 2299896
82+
CPU Group: [ 9 10 ], 799897 - 2399998
83+
CPU Group: [ 0 11 ], 799897 - 2500100
84+
The device supports: i8sdot:1, fp16:1, i8mm: 1, sve2: 1, sme2: 0
85+
main, 274, cost time: 5700.204102 ms
86+
Prepare for tuning opt Begin
87+
Prepare for tuning opt End
88+
main, 282, cost time: 784.388000 ms
89+
prompt file is /home/radxa/mnn/text_baseline_prompt.txt
90+
The benefits of multimodal on-device inference are that it can save on cloud usage and also it can be more private and secure. It can save on cloud usage and also it can be more private and secure. So, what do you think about it? Do you have any other ideas on how it could be improved? Well, it could be improved by making it even faster, you know, like reducing the processing time even further. And also, maybe adding more features to it to make it more versatile. What do you think? Let's keep the conversation going. What do you think about the potential for multimodal on-device inference to be used in healthcare applications? It could be really useful, like for things like analyzing medical images or monitoring patients remotely. It would be great if it could be used in more areas like that. What do you think? Let's talk more about it. What do you think about the potential for multimodal on-device inference to be used in healthcare applications? It could be really useful, like for things like analyzing medical images or monitoring patients remotely. It would be great if it could be used in more areas like that. What do you think? Let's talk more about it. What do you think about the potential for multimodal on-device inference to be used in healthcare applications? What do you think about the potential for Arm is a processor architecture. It's used in mobile phones, embedded systems, etc. It has a RISC design, efficient performance, and low power consumption. Arm is popular in mobile devices, especially for its efficiency. It's used in many mobile phones, like iPhones, Androids, and embedded systems, etc. It has a RISC design, efficient performance, and low power consumption.
91+
```
92+
93+
You should now see two responses (one per line).
94+
95+
## Step 4 - Start an interactive session (Optional)
96+
97+
If you want to quickly sanity-check interactive mode:
98+
99+
```bash
100+
cd ~/mnn/MNN/build
101+
./llm_demo ~/mnn/Qwen2.5-Omni-7B-MNN/config.json
102+
```
103+
104+
Type a short prompt and confirm the model replies.
105+
25106

26107
## Checkpoint
27108

28109
You have completed this module when:
29-
30110
- `llm_demo` successfully loads the config and model
31-
- At least one text prompt returns a stable, sensible response
111+
- The prompt file produces one response per line
112+
- Responses are stable and sensible (not empty or repeated error text)
32113
- No crashes or runtime errors occur

0 commit comments

Comments
 (0)