They finally fixed this stupid bug...
Browse files
README.md
CHANGED
@@ -5,10 +5,6 @@ tags:
|
|
5 |
- rknn
|
6 |
- rkllm
|
7 |
---
|
8 |
-
注意: 由于疑似RKLLM那边的问题, 目前此模型的推理输出结果不正常 (https://github.com/airockchip/rknn-llm/issues/101), 未来修复后这个repo会更新.
|
9 |
-
|
10 |
-
NOTE: Due to suspected issues in RKLLM(https://github.com/airockchip/rknn-llm/issues/101) , the model cannot be used normally for inference at the moment. Once fixed, this repo will be updated.
|
11 |
-
|
12 |
# MiniCPM-V-2_6-rkllm
|
13 |
|
14 |
## (English README see below)
|
@@ -22,7 +18,7 @@ NOTE: Due to suspected issues in RKLLM(https://github.com/airockchip/rknn-llm/is
|
|
22 |
|
23 |
1. 克隆或者下载此仓库到本地. 模型较大, 请确保有足够的磁盘空间.
|
24 |
|
25 |
-
2. 开发板的RKNPU2内核驱动版本必须>=0.9.6才能运行这么大的模型.
|
26 |
使用root权限运行以下命令检查驱动版本:
|
27 |
```bash
|
28 |
> cat /sys/kernel/debug/rknpu/version
|
@@ -40,10 +36,60 @@ pip install numpy<2 opencv-python
|
|
40 |
4. 运行
|
41 |
|
42 |
```bash
|
43 |
-
python
|
44 |
```
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
## 模型转换
|
49 |
|
@@ -68,15 +114,19 @@ python run_rknn.py
|
|
68 |
|
69 |
## 已知问题
|
70 |
|
71 |
-
-
|
72 |
-
-
|
|
|
|
|
|
|
|
|
73 |
- 视觉编码器转换ONNX的代码取自 https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6 , 感谢Sophgo提供的代码. 但是这个转换方法似乎将原模型中的自适应图像分块算法删除了, 可能会导致精度下降.
|
74 |
|
75 |
## 参考
|
76 |
|
77 |
-
[sophgo/LLM-TPU models/MiniCPM-V-2_6](https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6)
|
78 |
-
[openbmb/MiniCPM-V-2_6](https://huggingface.co/openbmb/MiniCPM-V-2_6)
|
79 |
-
[Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B)
|
80 |
|
81 |
|
82 |
## English README
|
@@ -90,7 +140,7 @@ Run the Powerful MiniCPM-V-2.6 Visual Language Model on RK3588!
|
|
90 |
|
91 |
1. Clone or download this repository locally. The model is large, so make sure you have enough disk space.
|
92 |
|
93 |
-
2. The RKNPU2 kernel driver version on the development board must be >=0.9.6 to run such a large model.
|
94 |
Use the following command with root privileges to check the driver version:
|
95 |
```bash
|
96 |
> cat /sys/kernel/debug/rknpu/version
|
@@ -108,10 +158,60 @@ You also need to manually install rknn-toolkit2-lite2.
|
|
108 |
4. Run
|
109 |
|
110 |
```bash
|
111 |
-
python
|
112 |
```
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
## Model Conversion
|
117 |
|
@@ -136,12 +236,16 @@ You can modify the content in `run_rknn.py` to test different inputs.
|
|
136 |
|
137 |
## Known Issues
|
138 |
|
139 |
-
- Due to a suspected issue in RKLLM, this model currently cannot perform inference normally
|
140 |
-
- Due to an issue in RKLLM, the visual encoder and LLM cannot be loaded simultaneously at present. The visual encoder must be unloaded first, then the LLM reloaded. If multiple inferences are required, the unloading and loading operations must be repeated, which is very slow
|
|
|
|
|
|
|
|
|
141 |
- The code for converting the visual encoder to ONNX is taken from https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6, thanks to Sophgo for providing the code. However, this conversion method seems to have removed the adaptive image partitioning algorithm from the original model, which may lead to a decrease in accuracy.
|
142 |
|
143 |
## References
|
144 |
|
145 |
-
[sophgo/LLM-TPU models/MiniCPM-V-2_6](https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6)
|
146 |
-
[openbmb/MiniCPM-V-2_6](https://huggingface.co/openbmb/MiniCPM-V-2_6)
|
147 |
-
[Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B)
|
|
|
5 |
- rknn
|
6 |
- rkllm
|
7 |
---
|
|
|
|
|
|
|
|
|
8 |
# MiniCPM-V-2_6-rkllm
|
9 |
|
10 |
## (English README see below)
|
|
|
18 |
|
19 |
1. 克隆或者下载此仓库到本地. 模型较大, 请确保有足够的磁盘空间.
|
20 |
|
21 |
+
2. 开发板的RKNPU2内核驱动版本必须>=0.9.6才能运行这么大的模型.
|
22 |
使用root权限运行以下命令检查驱动版本:
|
23 |
```bash
|
24 |
> cat /sys/kernel/debug/rknpu/version
|
|
|
36 |
4. 运行
|
37 |
|
38 |
```bash
|
39 |
+
python multiprocess_inference.py
|
40 |
```
|
41 |
|
42 |
+
test.jpg:
|
43 |
+

|
44 |
+
|
45 |
+
>```
|
46 |
+
>Start loading language model (size: 7810.02 MB)
|
47 |
+
>
|
48 |
+
>I rkllm: rkllm-runtime version: 1.1.2, rknpu driver version: 0.9.8, platform: RK3588
|
49 |
+
>
|
50 |
+
>W rknn-toolkit-lite2 version: 2.2.0
|
51 |
+
>Start loading vision encoder model (size: 942.29 MB)
|
52 |
+
>Vision encoder loaded in 10.22 seconds
|
53 |
+
>I RKNN: [02:28:20.939] RKNN Runtime Information, librknnrt version: 2.1.0 (967d001cc8@2024-08-07T19:28:19)
|
54 |
+
>I RKNN: [02:28:20.939] RKNN Driver Information, version: 0.9.8
|
55 |
+
>I RKNN: [02:28:20.940] RKNN Model Information, version: 6, toolkit version: 2.2.0(compiler version: 2.2.0 (c195366594@2024-09-14T12:24:14)), target: RKNPU v2, target platform: rk3588, framework name: ONNX, framework layout: NCHW, model inference type: dynamic_shape
|
56 |
+
>W RKNN: [02:28:20.940] RKNN Model version: 2.2.0 not match with rknn runtime version: 2.1.0
|
57 |
+
>Received ready signal: vision_ready
|
58 |
+
>Language model loaded in 29.21 seconds
|
59 |
+
>Received ready signal: llm_ready
|
60 |
+
>All models loaded, starting interactive mode...
|
61 |
+
>
|
62 |
+
>Enter your input (3 empty lines to start inference, Ctrl+C to exit, for example:
|
63 |
+
>详细描述一下{{./test.jpg}}这张图片
|
64 |
+
>What is the weather in {{./test.jpg}}?
|
65 |
+
>How many people are in {{./test.jpg}}?
|
66 |
+
>):
|
67 |
+
>
|
68 |
+
>以猫猫的身份描述一下{{test.jpg}}吧喵~
|
69 |
+
>
|
70 |
+
>
|
71 |
+
>
|
72 |
+
>Start vision inference...
|
73 |
+
>
|
74 |
+
>Vision encoder inference time: 4.92 seconds
|
75 |
+
>
|
76 |
+
>Time to first token: 1.95 seconds
|
77 |
+
>
|
78 |
+
>哇哦!这只像人一样的猫咪似乎正自信地走在街道上,手拿一把蓝白相间的伞。它穿着一件漂亮的外套和裤子,还有一双时尚的鞋子呢!
|
79 |
+
>
|
80 |
+
>周围的环境也很热闹啊~路上停满了各种各样的汽车、卡车和公交车,还有红绿灯在指挥交通。猫猫身边还有一个栏杆,上面挂着几面旗帜,看起来好有趣。
|
81 |
+
>
|
82 |
+
>天空一片蔚蓝,阳光明媚,猫猫似乎正在享受这美好的一天!喵呜~
|
83 |
+
>
|
84 |
+
>(finished)
|
85 |
+
>
|
86 |
+
>--------------------------------------------------------------------------------------
|
87 |
+
> Stage Total Time (ms) Tokens Time per Token (ms) Tokens per Second
|
88 |
+
>--------------------------------------------------------------------------------------
|
89 |
+
> Prefill 1761.10 94 18.74 53.38
|
90 |
+
> Generate 25757.53 104 248.72 4.02
|
91 |
+
>--------------------------------------------------------------------------------------
|
92 |
+
>```
|
93 |
|
94 |
## 模型转换
|
95 |
|
|
|
114 |
|
115 |
## 已知问题
|
116 |
|
117 |
+
- ~~由于疑似RKLLM中存在的问题, 目前此模型无法正常推理.~~ (已修复)
|
118 |
+
- ~~由于RKLLM中存在的问题, 目前视觉编码器和LLM无法同时被加载, 必须先卸载掉视觉编码器, 再重新加载LLM. 如果要推理多次, 必须重复执行卸载和加载操作, 速度非常慢.~~ (已修复)
|
119 |
+
- 由于疑似RKLLM中存在的问题, 如果视觉编码器和LLM加载进同一个Python进程, 会导致LLM推理时报错段错误. 可以使用多进程来解决. 参考`multiprocess_inference.py`.
|
120 |
+
- 由于RKLLM的多模态输入的限制, 在整个对话中只能加载一张图片. 可以通过Embedding输入的方式来解决, 但我没有实现.
|
121 |
+
- 没有实现多轮对话.
|
122 |
+
- RKLLM的w8a8量化貌似存在不小的精度损失.
|
123 |
- 视觉编码器转换ONNX的代码取自 https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6 , 感谢Sophgo提供的代码. 但是这个转换方法似乎将原模型中的自适应图像分块算法删除了, 可能会导致精度下降.
|
124 |
|
125 |
## 参考
|
126 |
|
127 |
+
- [sophgo/LLM-TPU models/MiniCPM-V-2_6](https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6)
|
128 |
+
- [openbmb/MiniCPM-V-2_6](https://huggingface.co/openbmb/MiniCPM-V-2_6)
|
129 |
+
- [Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B)
|
130 |
|
131 |
|
132 |
## English README
|
|
|
140 |
|
141 |
1. Clone or download this repository locally. The model is large, so make sure you have enough disk space.
|
142 |
|
143 |
+
2. The RKNPU2 kernel driver version on the development board must be >=0.9.6 to run such a large model.
|
144 |
Use the following command with root privileges to check the driver version:
|
145 |
```bash
|
146 |
> cat /sys/kernel/debug/rknpu/version
|
|
|
158 |
4. Run
|
159 |
|
160 |
```bash
|
161 |
+
python multiprocess_inference.py
|
162 |
```
|
163 |
|
164 |
+
test.jpg:
|
165 |
+

|
166 |
+
|
167 |
+
>```
|
168 |
+
>Start loading language model (size: 7810.02 MB)
|
169 |
+
>
|
170 |
+
>I rkllm: rkllm-runtime version: 1.1.2, rknpu driver version: 0.9.8, platform: RK3588
|
171 |
+
>
|
172 |
+
>W rknn-toolkit-lite2 version: 2.2.0
|
173 |
+
>Start loading vision encoder model (size: 942.29 MB)
|
174 |
+
>Vision encoder loaded in 10.22 seconds
|
175 |
+
>I RKNN: [02:28:20.939] RKNN Runtime Information, librknnrt version: 2.1.0 (967d001cc8@2024-08-07T19:28:19)
|
176 |
+
>I RKNN: [02:28:20.939] RKNN Driver Information, version: 0.9.8
|
177 |
+
>I RKNN: [02:28:20.940] RKNN Model Information, version: 6, toolkit version: 2.2.0(compiler version: 2.2.0 (c195366594@2024-09-14T12:24:14)), target: RKNPU v2, target platform: rk3588, framework name: ONNX, framework layout: NCHW, model inference type: dynamic_shape
|
178 |
+
>W RKNN: [02:28:20.940] RKNN Model version: 2.2.0 not match with rknn runtime version: 2.1.0
|
179 |
+
>Received ready signal: vision_ready
|
180 |
+
>Language model loaded in 29.21 seconds
|
181 |
+
>Received ready signal: llm_ready
|
182 |
+
>All models loaded, starting interactive mode...
|
183 |
+
>
|
184 |
+
>Enter your input (3 empty lines to start inference, Ctrl+C to exit, for example:
|
185 |
+
>详细描述一下{{./test.jpg}}这张图片
|
186 |
+
>What is the weather in {{./test.jpg}}?
|
187 |
+
>How many people are in {{./test.jpg}}?
|
188 |
+
>):
|
189 |
+
>
|
190 |
+
>Describe the image: {{test.jpg}} in every detail.
|
191 |
+
>
|
192 |
+
>
|
193 |
+
>
|
194 |
+
>Start vision inference...
|
195 |
+
>
|
196 |
+
>Vision encoder inference time: 4.80 seconds
|
197 |
+
>
|
198 |
+
>In this urban street scene, an older individual is seen crossing at a pedestrian crosswalk with an umbrella held aloft against what appears to be bright sunlight. The person's attire suggests preparedness for varying weather conditions - they're dressed casually yet practically, wearing trousers and sneakers paired with a jacket that can offer some protection from sun or light rain.
|
199 |
+
>
|
200 |
+
>The vehicles on the road hint at a typical busy day in this locale; there are various models visible including what looks like an SUV. The presence of multiple lanes suggests traffic is managed for different types of vehicular movement - possibly separate lines for cars and larger trucks, ensuring safety for all commuters.
|
201 |
+
>
|
202 |
+
>In contrast to the hustle and bustle on the road, trees line one side of the street, providing a touch of nature amidst urban development. Their green foliage might offer shade during hotter times of the day or act as windbreakers in windy conditions.
|
203 |
+
>
|
204 |
+
>Traffic signs are visible above, which likely provide essential directions for both drivers and pedestrians alike, contributing to organized movement within this bustling environment. The presence of these elements collectively paints a picture of an orderly city where nature coexists with human-made structures, while people navigate their way through daily life amidst the backdrop of urban infrastructure.
|
205 |
+
>
|
206 |
+
>(finished)
|
207 |
+
>
|
208 |
+
>--------------------------------------------------------------------------------------
|
209 |
+
> Stage Total Time (ms) Tokens Time per Token (ms) Tokens per Second
|
210 |
+
>--------------------------------------------------------------------------------------
|
211 |
+
> Prefill 1712.87 94 18.22 54.88
|
212 |
+
> Generate 60417.39 243 249.58 4.01
|
213 |
+
>--------------------------------------------------------------------------------------
|
214 |
+
>```
|
215 |
|
216 |
## Model Conversion
|
217 |
|
|
|
236 |
|
237 |
## Known Issues
|
238 |
|
239 |
+
- ~~Due to a suspected issue in RKLLM, this model currently cannot perform inference normally.~~ (Fixed)
|
240 |
+
- ~~Due to an issue in RKLLM, the visual encoder and LLM cannot be loaded simultaneously at present. The visual encoder must be unloaded first, then the LLM reloaded. If multiple inferences are required, the unloading and loading operations must be repeated, which is very slow.~~ (Fixed)
|
241 |
+
- Due to a suspected issue in RKLLM, if the visual encoder and LLM are loaded into the same Python process, the LLM inference will segmentation fault. You can use multiprocessing to solve this problem. See `multiprocess_inference.py`.
|
242 |
+
- Due to the limitation of RKLLM's multimodal input, only one image can be loaded in the entire conversation. This can be solved by using embedding input, but I haven't implemented it yet.
|
243 |
+
- I don't implement multi-turn chat.
|
244 |
+
- There is a significant precision loss in RKLLM's w8a8 quantization.
|
245 |
- The code for converting the visual encoder to ONNX is taken from https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6, thanks to Sophgo for providing the code. However, this conversion method seems to have removed the adaptive image partitioning algorithm from the original model, which may lead to a decrease in accuracy.
|
246 |
|
247 |
## References
|
248 |
|
249 |
+
- [sophgo/LLM-TPU models/MiniCPM-V-2_6](https://github.com/sophgo/LLM-TPU/tree/main/models/MiniCPM-V-2_6)
|
250 |
+
- [openbmb/MiniCPM-V-2_6](https://huggingface.co/openbmb/MiniCPM-V-2_6)
|
251 |
+
- [Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B)
|