Skip to content

Commit 2fb946f

Browse files
committed
MNN Tech review
1 parent 89c61ba commit 2fb946f

5 files changed

Lines changed: 59 additions & 95 deletions

File tree

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

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ layout: learningpathall
66

77
## Introduction
88

9-
In this section, you will build **MNN** natively on your Armv9 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 sections.
9+
In this section, you will build **MNN** natively on your Armv9 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 sections.
1010

11-
This section uses a native **CPU-only** MNN build on Armv9. That is a deliberate design choice, not a fallback. The goal is to show how a compact, reproducible, deployment-friendly software stack can run directly on an Armv9 CPU without depending on a discrete GPU or separate accelerator.
11+
This section uses a native CPU-only MNN build on Armv9. That is a deliberate design choice, not a fallback. The goal is to show how a compact, reproducible, deployment-friendly software stack can run directly on an Armv9 CPU without depending on a discrete GPU or separate accelerator.
1212

13-
At the end of this module, you will have:
13+
At the end of this section, you will have:
1414

1515
- a working `llm_demo` binary
1616
- a validated model directory that includes `config.json`
@@ -26,13 +26,13 @@ mkdir -p ~/mnn
2626
cd ~/mnn
2727
```
2828

29-
## Why build natively on Armv9 first
29+
## Why build natively on Armv9
3030

31-
This Learning Path uses a native build on the target Armv9 system before introducing any cross-compilation workflow. Building directly on the target helps reduce environment drift, makes library and toolchain issues easier to diagnose, and lets you validate the runtime in the same environment where you will execute the model.
31+
Building, running inference, and deploying all happen directly on the Armv9 device. There is no cross-compilation involved. This keeps the toolchain simple, eliminates environment drift between build and target, and means any library or configuration issue you encounter is the same one you would hit in production.
3232

33-
A native-first approach also makes it easier to confirm that the final binary, shared libraries, and model assets work together correctly on the Armv9 platform. For a reproducible Learning Path, this is usually the fastest way to get to a working baseline before optimizing or automating the workflow further.
33+
Building on the target also makes it straightforward to confirm that the binary, shared libraries, and model assets all resolve correctly in the same environment where you will run the model.
3434

35-
## Build MNN natively on Armv9
35+
## Build MNN
3636

3737
Clone the MNN repository:
3838

@@ -41,12 +41,20 @@ git clone https://github.com/alibaba/MNN.git
4141
cd MNN
4242
```
4343

44+
Install the required build dependencies:
45+
46+
```bash
47+
sudo apt update
48+
sudo apt install -y build-essential gcc g++ cmake
49+
```
50+
4451
Configure and build MNN with LLM, audio, and Omni support enabled:
4552

4653
```bash
47-
rm -rf build
4854
mkdir build && cd build
55+
```
4956

57+
```bash
5058
cmake .. \
5159
-DCMAKE_BUILD_TYPE=Release \
5260
-DMNN_BUILD_SHARED=ON \
@@ -85,7 +93,6 @@ If your system already has another MNN installation, `llm_demo` can load a diffe
8593
From the build directory, inspect the runtime dependencies:
8694

8795
```bash
88-
cd ~/mnn/MNN/build
8996
ldd ./llm_demo | grep -E "libMNN|Express|Audio|OpenCV" || true
9097
```
9198

@@ -128,7 +135,7 @@ ldd ./llm_demo | grep -E "libMNN|Express|Audio|OpenCV" || true
128135

129136
## Download the prebuilt Omni model package
130137

131-
This Learning Path uses a prebuilt [Omni model package](https://huggingface.co/taobao-mnn/Qwen2.5-Omni-7B-MNN) that is already prepared for MNN deployment.
138+
This Learning Path uses a prebuilt [Omni model package](https://www.modelscope.cn/MNN/Qwen2.5-Omni-7B-MNN) that is already prepared for MNN deployment. The full package is approximately 15 GB, so ensure you have sufficient disk space and a stable internet connection before cloning.
132139

133140
Clone the model repository into your workspace:
134141

@@ -138,64 +145,31 @@ git clone https://www.modelscope.cn/MNN/Qwen2.5-Omni-7B-MNN.git
138145
cd ~/mnn/Qwen2.5-Omni-7B-MNN
139146
```
140147

141-
## Verify that the required model files are present
142-
143-
Check that the repository contains the expected configuration and model files:
144-
145-
```bash
146-
ls -lh ~/mnn/Qwen2.5-Omni-7B-MNN
147-
```
148-
149-
Verify that `config.json` exists:
150-
151-
```bash
152-
cat ~/mnn/Qwen2.5-Omni-7B-MNN/config.json
153-
```
154-
155-
The presence of `config.json` alone does not guarantee that the full model weights are available locally. Confirm that the main model files are present:
148+
## Download the model weights
156149

157-
- `llm.mnn`
158-
- `llm.mnn.weight`
150+
After cloning, install Git LFS and pull the large model files:
159151

160152
```bash
161-
ls -lh ~/mnn/Qwen2.5-Omni-7B-MNN/llm.mnn ~/mnn/Qwen2.5-Omni-7B-MNN/llm.mnn.weight
162-
```
163-
164-
If both files exist and show non-trivial file sizes, the model package is ready for inference.
165-
166-
## If the model weights are missing
167-
168-
Some environments fetch the large model files automatically when you clone the repository, while others do not. If `llm.mnn` or `llm.mnn.weight` is missing, install **Git LFS** and pull the large files explicitly.
169-
170-
Install Git LFS:
171-
172-
```bash
173-
sudo apt-get update
174153
sudo apt-get install -y git-lfs
175154
git lfs install
176-
```
177-
178-
Then download the large model files:
179-
180-
```bash
181155
cd ~/mnn/Qwen2.5-Omni-7B-MNN
182156
git lfs pull
183157
```
184158

185159
{{% notice Note %}}
186-
Downloading the full model weights can take a while depending on your network connection and available bandwidth.
160+
The full model weights are approximately 15 GB. Downloading can take a while depending on your network connection.
187161
{{% /notice %}}
188162

189-
After `git lfs pull`, verify the files again:
163+
Verify that the main model files are present and several gigabytes in size:
190164

191165
```bash
192166
ls -lh ~/mnn/Qwen2.5-Omni-7B-MNN/llm.mnn ~/mnn/Qwen2.5-Omni-7B-MNN/llm.mnn.weight
193167
```
194168

195-
{{% notice Note %}}
196-
This package is already prepared for MNN deployment.
169+
If either file is only a few hundred bytes, the LFS download did not complete. Run `git lfs pull` again to resume it.
197170

198-
You do not need to export the model from PyTorch or run additional quantization steps before using it in this Learning Path.
171+
{{% notice Note %}}
172+
This package is already prepared for MNN deployment. You do not need to export the model from PyTorch or run additional quantization steps before using it in this Learning Path.
199173
{{% /notice %}}
200174

201175
## Check your setup

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ Prepare for tuning opt Begin
9797
Prepare for tuning opt End
9898
main, 282, cost time: 784.388000 ms
9999
prompt file is /home/radxa/mnn/text_baseline_prompt.txt
100-
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.
100+
The benefits of multimodal on-device inference are that it can save on cloud usage and also it can be more private and secure.
101+
[...]
102+
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.
101103
```
102104

103105
{{% notice Note %}}
@@ -111,7 +113,7 @@ cd ~/mnn/MNN/build
111113
./llm_demo ~/mnn/Qwen2.5-Omni-7B-MNN/config.json
112114
```
113115

114-
Enter a short prompt and confirm that the model returns a reply. Type `exit` or press Ctrl+C to quit.
116+
Enter a short prompt and confirm that the model returns a reply. Press Ctrl+C to quit.
115117

116118
## Check your results
117119

content/learning-paths/cross-platform/multimodel_mnn_v9/4_mnn_vision.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ You should see output similar to:
4040
JPEG image data, JFIF standard 1.02, resolution (DPI), density 72x72, segment length 16, Exif Standard: [TIFF image data, little-endian, direntries=12, description= , manufacturer=SONY, model=DSC-W50, orientation=upper-left, xresolution=203, yresolution=211, resolutionunit=2, software=Adobe Photoshop CS Macintosh, datetime=2007:04:10 17:45:47], progressive, precision 8, 2816x2112, components 3
4141
```
4242

43-
This confirms that the image asset is ready for the vision prompt.
43+
The key detail is that the output starts with `JPEG image data`, confirming the file is a valid JPEG. The remaining EXIF metadata can be ignored.
4444

4545
![Pet food aisle shelf with multiple levels stocked with pet food products, used as the vision prompt input for the shelf audit#center](pet_food_aisle.jpg "Pet food aisle shelf used for the vision audit prompt")
4646

@@ -67,6 +67,10 @@ EOF
6767

6868
Run `llm_demo` with the model `config.json` file and the vision prompt:
6969

70+
{{% notice Note %}}
71+
Vision inference takes longer than text-only inference because the model encodes the image into tokens before generation begins. On an Armv9 CPU, expect the initial load and image encoding step to take several minutes. The terminal will appear idle during this time — this is expected.
72+
{{% /notice %}}
73+
7074
```bash
7175
cd ~/mnn/MNN/build
7276
./llm_demo ~/mnn/Qwen2.5-Omni-7B-MNN/config.json ~/mnn/prompt_picture_coverage.txt

content/learning-paths/cross-platform/multimodel_mnn_v9/5_mnn_vision_audio.md

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,28 @@ layout: learningpathall
66

77
## Introduction
88

9-
In this module, you use an audio prompt and an MNN Omni model to convert a spoken restock note into a structured one-line ticket on an Armv9 system.
9+
In this section, you use an audio prompt and an MNN Omni model to convert a spoken restock note into a structured one-line ticket on an Armv9 system.
1010

1111
This mirrors a simple retail workflow. A store associate records a short voice note during a shelf walk, and the system converts it into a task that can be reviewed by staff or passed to another tool.
1212

13-
To keep the output predictable, this module uses a single-line format with semicolon-separated fields. This also helps when terminal output does not preserve line breaks consistently.
13+
To keep the output predictable, this section uses a single-line format with semicolon-separated fields. This also helps when terminal output does not preserve line breaks consistently.
1414

1515
## Prepare the audio asset
1616

1717
To simplify the demonstration and improve clarity for this learning path, directly download the prepared audio file:
1818

1919
```bash
20-
mkdir ~/mnn/assets
21-
wget wget https://github.com/odincodeshen/multimodel_mnn_armv9/raw/main/assets/restock_note.wav -P ~/mnn/assets
20+
mkdir -p ~/mnn/assets
21+
wget https://github.com/odincodeshen/multimodel_mnn_armv9/raw/main/assets/restock_note.wav -P ~/mnn/assets
2222
```
2323

24-
This audio `restock_note.wav` contains brief spoken instructions describing restocking tasks, such as:
24+
The audio file contains a spoken restocking instruction. The content is similar to:
2525

26-
- please restock the bottom-left large pet food bags, add ten bags
27-
- also restock the middle-left canned pet food, add twenty-four cans
28-
- finish before 3 PM today
29-
- if something is out of stock, use a similar substitute
30-
31-
The model’s goal is to extract structured operational information from this audio, specifically:
32-
33-
- items
34-
- quantities
35-
- shelf zones
36-
- deadline
37-
- substitution policy
26+
```text
27+
This is the pet food aisle, left shelf. Please restock the bottom left large pet food bags, add 10 bags. Also restock the middle left canned food, add 24 cans. Finish before 3 PM today. If something is out of stock, use a similar substitute.
28+
```
3829

39-
The objective isnt comprehensive speech analytics but efficiently converting spoken instructions into a compact operational ticket.
30+
From this spoken note, the model extracts item names, quantities, shelf zones, a deadline, and a substitution policy. The goal isn't comprehensive speech analytics — it's converting a short spoken instruction into a compact operational ticket.
4031

4132
## Verify the audio format
4233

@@ -48,23 +39,17 @@ file ~/mnn/assets/restock_note.wav
4839

4940
You should see output indicating that the file is a RIFF/WAV audio file.
5041

51-
If you'd like to record the audio by yourself as MP3 format, please convert it to a speech-friendly WAV format:
42+
If you have your own MP3 recording, convert it to a speech-friendly WAV format:
5243

5344
```bash
5445
ffmpeg -y -i input.mp3 -ac 1 -ar 16000 -c:a pcm_s16le ~/mnn/assets/restock_note.wav
5546
```
5647

5748
This creates a mono, 16 kHz, 16-bit PCM WAV file, which is a practical format for speech input.
5849

59-
The spoken content can be similar to:
60-
61-
```text
62-
This is the pet food aisle, left shelf. Please restock the bottom left large pet food bags, add 10 bags. Also restock the middle left canned food, add 24 cans. Finish before 3 PM today. If something is out of stock, use a similar substitute.
63-
```
64-
6550
In store inspection scenarios, unreliable connectivity, or environments where teams prefer not to upload audio in real time, local speech understanding on Armv9 has clear deployment value.
6651

67-
In this module, the audio input is not just an audio prompt. It acts as on-device spoken task capture for store operations, turning a short spoken restocking note into structured operational input.
52+
In this section, the audio input is not just an audio prompt. It acts as on-device spoken task capture for store operations, turning a short spoken restocking note into structured operational input.
6853

6954
## Create the audio prompt
7055

@@ -77,13 +62,11 @@ Create a prompt file that attaches the WAV file and asks the model to return a s
7762
Create the prompt file:
7863

7964
```bash
80-
cat > ~/mnn/prompt_audio_ticket.txt <<'EOF'
81-
<audio>/home/radxa/mnn/assets/restock_note.wav</audio> You are a retail store replenishment assistant. Convert the spoken note into a restocking ticket. Output EXACTLY ONE line using bullet-style segments separated by semicolons: Restock ticket; - Location: pet food aisle left shelf; - Task 1: <generic item> | qty <number or NOT_SURE> | zone <top|middle|bottom>-<left|center|right or NOT_SURE>; - Task 2: <generic item> | qty <number or NOT_SURE> | zone <top|middle|bottom>-<left|center|right or NOT_SURE>; - Deadline: <time or NOT_SURE>; - Substitution: <use similar substitute|no substitute|NOT_SURE>; - Notes: <short note>; - Confidence: <high|medium|low>. Rules: do not invent quantities if not in audio.
65+
cat > ~/mnn/prompt_audio_ticket.txt <<EOF
66+
<audio>$HOME/mnn/assets/restock_note.wav</audio> You are a retail store replenishment assistant. Convert the spoken note into a restocking ticket. Output EXACTLY ONE line using bullet-style segments separated by semicolons: Restock ticket; - Location: pet food aisle left shelf; - Task 1: <generic item> | qty <number or NOT_SURE> | zone <top|middle|bottom>-<left|center|right or NOT_SURE>; - Task 2: <generic item> | qty <number or NOT_SURE> | zone <top|middle|bottom>-<left|center|right or NOT_SURE>; - Deadline: <time or NOT_SURE>; - Substitution: <use similar substitute|no substitute|NOT_SURE>; - Notes: <short note>; - Confidence: <high|medium|low>. Rules: do not invent quantities if not in audio.
8267
EOF
8368
```
8469

85-
If your username or home directory is different, replace `/home/radxa` with the correct local path.
86-
8770
This prompt asks the model to:
8871

8972
- use generic item names instead of brands
@@ -125,7 +108,7 @@ Restock ticket;
125108
126109
```
127110
The exact wording can vary. What matters is that the response stays close to the requested structure and reflects the spoken content rather than invented details.
128-
![image2 Prompt Audio Ticket](prompt_audio_ticket.gif)
111+
![Animated terminal output showing llm_demo processing an audio prompt and returning a structured restock ticket on Armv9#center](prompt_audio_ticket.gif "llm_demo audio prompt output on Armv9")
129112

130113
## Verify the result
131114

0 commit comments

Comments
 (0)