跳到主要内容

Neardi LLM/VLM Demos

Contents​

  1. LLM
  2. VLM

1. LLM​

1.1 Overview​

大语言模型(LLM)是一种强大的AI系统,你可以把它想象成一个学习了海量文本(书籍、文章、网页等)的“超级大脑”。它基于一种叫Transformer的神经网络架构,核心能力是理解语言并生成语言。而Qwen3-1.7B就是其中一个具体、轻量化的实例。

1.2 Prepare​

确保Host主机里有rk182x算力卡, 如下:

环境安装okay后, 可以使用如下命令查看:

neardi@RK3576:~$ sudo rknn-smi info
+------------------------+---------------+---------------+----------------------+
| rknn-smi Version: 1.3.0 |
+========================+===============+===============+======================+
| Device Status | Health | Power(mW) | Npu(%) |
| Chip Name | Bus-Id | Temp(C) | Memory-Usage(MB) |
+========================+===============+===============+======================+
| 0 Online | OK | NA | 0 |
| 0 RK1820 | 0000:06:00.0 | 43 | 1376 / 2560 |
+========================+===============+===============+======================+

1.3 Deploy and run Qwen3-1.7B​

从这里下载转换后的Qwen3-1.7B, 拷贝到与rk182x相关的设备, 如下:

neardi@RK3576:~/Qwen$ tree
.
├── Qwen3-1.7B.embed.bin
├── Qwen3-1.7B.rknn
├── Qwen3-1.7B.tokenizer.gguf
└── Qwen3-1.7B.weight

使用如下命令运行Qwen模型, 如下:

neardi@RK3576:~/Qwen$ rkllm3-server -m Qwen3-1.7B.rknn --weight Qwen3-1.7B.weight \
--vocab Qwen3-1.7B.tokenizer.gguf \
--embed Qwen3-1.7B.embed.bin \
--host 0.0.0.0 --port 8080 --repeat-penalty 1.2 --presence-penalty 0.0 \
--frequency-penalty 0.0 --top-k 1 --top-p 0.9 --temp 1.0 -c 0

运行成功后, 有如下log:

neardi@RK3576:~/Qwen$ rkllm3-server -m Qwen3-1.7B.rknn --weight Qwen3-1.7B.weight \
--vocab Qwen3-1.7B.tokenizer.gguf \
--embed Qwen3-1.7B.embed.bin \
--host 0.0.0.0 --port 8080 --repeat-penalty 1.2 --presence-penalty 0.0 \
--frequency-penalty 0.0 --top-k 1 --top-p 0.9 --temp 1.0 -c 0
version: 1.0.4 (04c8fbc@2026-05-13T15:14:35)

main: loading model
srv load_model: loading model 'Qwen3-1.7B.rknn'
====> rknn3_find_devices
device[0]: type=PCIE, serial_id=0000:06:00.0
the device-id is not specified, use "0000:06:00.0" as default!
====> rknn3_init
====> rknn3_load_model_from_path
rknn3_load_model_from_path success!
====> rknn3_query RKNN3_QUERY_CORE_NUMBER
====> rknn3_model_init
rknn3_model_init success!
====> rknn3_query RKNN3_QUERY_LLM_CONFIG
llm_model_type =
rope_cache_host_storage = 0
====> rknn3_query RKNN3_QUERY_CORE_MEM_SIZE
====> rknn3_create_mem
Created user internal memory for core 0: size=8942592, virt_addr=0x7fb0797000
====> rknn3_create_mem
Created user internal memory for core 1: size=6646784, virt_addr=0x7fb0140000
====> rknn3_create_mem
Created user internal memory for core 2: size=6646784, virt_addr=0x7fafae9000
====> rknn3_create_mem
Created user internal memory for core 3: size=6646784, virt_addr=0x7faf492000
====> rknn3_create_mem
Created user internal memory for core 4: size=6646784, virt_addr=0x7faee3b000
====> rknn3_create_mem
Created user internal memory for core 5: size=6646784, virt_addr=0x7fae7e4000
====> rknn3_create_mem
Created user internal memory for core 6: size=6646784, virt_addr=0x7fae18d000
====> rknn3_create_mem
Created user internal memory for core 7: size=6646784, virt_addr=0x7fadb36000
====> rknn3_set_internal_mem
rknn3_set_internal_mem success, set 8 internal memories
load: control-looking token: 128247 '</s>' was not control-type; this is probably a bug in the model. its type will be overridden
load: printing all EOG tokens:
load: - 128247 ('</s>')
load: - 151643 ('<|endoftext|>')
load: - 151645 ('<|im_end|>')
load: - 151662 ('<|fim_pad|>')
load: - 151663 ('<|repo_name|>')
load: - 151664 ('<|file_sep|>')
load: special tokens cache size = 27
load: token to piece cache size = 0.9311 MB
srv init: initializing slots, n_slots = 1
slot init: id 0 | task -1 | new slot n_ctx_slot = 2048
Enable thinking? 1
main: model loaded

接下来可以使用如下命令行进行测试:

neardi@RK3576:~$ curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"messages": [
{"role": "user", "content": "解析一下AI是什么?"}
],
"n_keep": 0,
"cache_prompt": false,
"id_slot": 0,
"n_predict": 512,
"stream": true
}'

模型有如下回复:

neardi@RK3576:~$ curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"messages": [
{"role": "user", "content": "解析一下AI是什么?"}
],
"n_keep": 0,
"cache_prompt": false,
"id_slot": 0,
"n_predict": 512,
"stream": true
}'
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"role":"assistant","content":null}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"<think>"}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"\n"}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"嗯"}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":","}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"用户"}}],"created":1782971670,"id":"chatcmpl-2K5xjPOEpBVObEeb1ke2qcBTRzRlIlZG","id_slot":0,"model":"Qwen3-1.7B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}
...

可以看出, 模型回复的是token的形式。 也可以编写一个HTML页面进行访问, 如下:

HTML代码, 可以从这里download.

2. VLM​

2.1 Overview​

FastVLM 是苹果公司(Apple) 在 2025 年提出并开源的一系列视觉语言模型(Vision Language Model, VLM),相关论文已被 CVPR 2025 接收。它最核心的标签就是 “快”,专为在 iPhone、iPad 和 Mac 等个人设备上高效运行而设计. 这里, 我们把它部署到rk182x设备上面。

2.2 deploy FastVLM(1.6B)​

首先从Rockchip官方下载转换后的FastVLM模型, 并且拷贝到与rk182x相关的设备上面。 如下:

neardi@RK3576:~/FastVLM$ tree
.
├── FastVLM_1.6B.embed.bin
├── FastVLM_1.6B.tokenizer.gguf
├── llm_FastVLM_1.6B.rknn
├── llm_FastVLM_1.6B.weight
├── vision_FastVLM_1.6B.rknn
└── vision_FastVLM_1.6B.weight

接下来运行模型, 使用如下命令:

neardi@RK3576:~/FastVLM$ rkllm3-server -m llm_FastVLM_1.6B.rknn --model2 vision_FastVLM_1.6B.rknn --vocab FastVLM_1.6B.tokenizer.gguf --embed FastVLM_1.6B.embed.bin --host 0.0.0.0 --port 8080 --n_predict 512 --repeat-penalty 1.1 --presence-penalty 1.0 --frequency-penalty 1.0 --top-k 1 --top-p 0.8 --temp 0.8 --img-start "<|im_start|>" --img-end "<|im_end|>" --img-content "<|image_pad|>"

运行成功后, 有如下log:

neardi@RK3576:~/FastVLM$ rkllm3-server -m llm_FastVLM_1.6B.rknn --model2 vision_FastVLM_1.6B.rknn --vocab FastVLM_1.6B.tokenizer.gguf --embed FastVLM_1.6B.embed.bin --host 0.0.0.0 --port 8080 --n_predict 512 --repeat-penalty 1.1 --presence-penalty 1.0 --frequency-penalty 1.0 --top-k 1 --top-p 0.8 --temp 0.8 --img-start "<|im_start|>" --img-end "<|im_end|>" --img-content "<|image_pad|>"
version: 1.0.4 (04c8fbc@2026-05-13T15:14:35)

img_start: <|im_start|>
img_end: <|im_end|>
img_content: <|image_pad|>
main: loading model
srv load_model: loading model 'llm_FastVLM_1.6B.rknn'
====> rknn3_find_devices
device[0]: type=PCIE, serial_id=0000:06:00.0
the device-id is not specified, use "0000:06:00.0" as default!
====> rknn3_init
====> rknn3_load_model_from_path
rknn3_load_model_from_path success!
====> rknn3_query RKNN3_QUERY_CORE_NUMBER
====> rknn3_model_init
rknn3_model_init success!
====> rknn3_query RKNN3_QUERY_LLM_CONFIG
The value of '--ctx-size'(4096) is greater than the model's max_context_len(1024), so '--ctx-size' is limited to 1024.
llm_model_type =
rope_cache_host_storage = 0
====> rknn3_query RKNN3_QUERY_CORE_MEM_SIZE
====> rknn3_init 2
====> rknn3_load_model_from_path 2
rknn3_load_model_from_path 2 success!
====> rknn3_query 2 RKNN3_QUERY_CORE_NUMBER
====> rknn3_model_init 2
rknn3_model_init 2 success!
====> rknn3_query 2 RKNN3_QUERY_CORE_MEM_SIZE
====> rknn3_create_mem
Created user internal memory for core 0: size=39849984, virt_addr=0x7f8977e000
====> rknn3_create_mem
Created user internal memory for core 1: size=27267072, virt_addr=0x7f825ff000
====> rknn3_create_mem
Created user internal memory for core 2: size=27267072, virt_addr=0x7f80bfe000
====> rknn3_create_mem
Created user internal memory for core 3: size=7341056, virt_addr=0x7f8907d000
====> rknn3_create_mem
Created user internal memory for core 4: size=13107200, virt_addr=0x7f883fd000
====> rknn3_create_mem
Created user internal memory for core 5: size=6820864, virt_addr=0x7f8057c000
====> rknn3_create_mem
Created user internal memory for core 6: size=8389632, virt_addr=0x7f7b7ff000
====> rknn3_create_mem
Created user internal memory for core 7: size=5745664, virt_addr=0x7f80001000
====> rknn3_set_internal_mem
rknn3_set_internal_mem success, set 8 internal memories
load: control-looking token: 128247 '</s>' was not control-type; this is probably a bug in the model. its type will be overridden
load: printing all EOG tokens:
load: - 128247 ('</s>')
load: - 151643 ('<|endoftext|>')
load: - 151645 ('<|im_end|>')
load: special tokens cache size = 5
load: token to piece cache size = 0.9308 MB
model input num: 1, output num: 1
input tensors:
Tensor: name=pixel, n_dims=4, shape=[1, 512, 512, 3], stride=[786432, 1536, 3, 1], aligned_size=786432, layout=NHWC, dtype=UINT8, core_id=0, qnt_type=NONE
output tensors:
Tensor: name=1982, n_dims=3, shape=[1, 64, 1536], stride=[98304, 1536, 1], aligned_size=196608, layout=UNDEFINED, dtype=FP16, core_id=0, qnt_type=NONE
model is NHWC input layout
input image height=512, input image width=512, input image channel=3
model is UNDEFINED output layout
output img embeds dim0=1, img embeds dim1=64
====> rknn3_create_mem input 0
====> rknn3_create_mem output 0
srv init: initializing slots, n_slots = 1
slot init: id 0 | task -1 | new slot n_ctx_slot = 1024
Enable thinking? 0
main: model loaded

最后, 我们来测试一下FastVLM模型, 打开一个terminal终端, 使用如下命令:

neardi@RK3576:~$ curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"messages": [
{"role": "user", "content": "解析一下AI是什么?"}
],
"n_keep": 0,
"cache_prompt": false,
"id_slot": 0,
"n_predict": 512,
"stream": true
}'

模型回答的log如下:

neardi@RK3576:~$ curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"messages": [
{"role": "user", "content": "解析一下AI是什么?"}
],
"n_keep": 0,
"cache_prompt": false,
"id_slot": 0,
"n_predict": 512,
"stream": true
}'
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"role":"assistant","content":null}}],"created":1782959150,"id":"chatcmpl-XcAL2PVlYckXPWwUhIuO3IbFSLElnSUM","id_slot":0,"model":"llm_FastVLM_1.6B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"AI"}}],"created":1782959150,"id":"chatcmpl-XcAL2PVlYckXPWwUhIuO3IbFSLElnSUM","id_slot":0,"model":"llm_FastVLM_1.6B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":","}}],"created":1782959150,"id":"chatcmpl-XcAL2PVlYckXPWwUhIuO3IbFSLElnSUM","id_slot":0,"model":"llm_FastVLM_1.6B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}

data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"全"}}],"created":1782959150,"id":"chatcmpl-XcAL2PVlYckXPWwUhIuO3IbFSLElnSUM","id_slot":0,"model":"llm_FastVLM_1.6B.rknn","system_fingerprint":"b5166-24345353","object":"chat.completion.chunk"}
...

2.3 HTML client​

上面的测试是基于命令行, 查看模型的回答很不友好, 看见的是一个一个词元(token)。 这里创建一个HTML页面来和模型对话, 如下:

HTML代码, 可以从这里download.

3. Gemma-e4b​

3.1 Overview​

Gemma E4B 是 Google 专为在手机、算力卡这类边缘设备上,实现高效、低功耗运行而设计的“有效参数”多模态模型。 这里我们把Gemma-e4b部署到rk182x上面。

deploy Gemma-e4b​

首先把gemma-e4b模型转换成RKNN, 或者从这里下载gemma. 如下:

.
├── gemma4-e4b.embed.bin
├── gemma4-e4b_per_layer_inputs.embed.bin
├── gemma4-e4b.tokenizer.gguf
├── llm_gemma4-e4b.rknn
├── llm_gemma4-e4b.safetensors
├── llm_gemma4-e4b.weight
├── vision_gemma4-e4b.rknn
└── vision_gemma4-e4b.weight

其次, 下载rknn3-model-zoo, 在rk182x的SDK环境编译, 如下:

linx@ubuntu2204-docker:~/neardi_rk182x/rknn/rknn3-model-zoo$ export GCC_COMPILER=/mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu
linx@ubuntu2204-docker:~/neardi_rk182x/rknn/rknn3-model-zoo$ ./build-linux.sh -t rk3576 -a aarch64 -d gemma4 ./build-linux.sh -t rk3576 -a aarch64 -d gemma4
/mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu
find: ‘tested_models’: No such file or directory
===================================
BUILD_DEMO_NAME=gemma4
BUILD_DEMO_PATH=examples/gemma4/cpp
TARGET_SOC=rk3576
TARGET_ARCH=aarch64
BUILD_TYPE=Release
ENABLE_ASAN=OFF
DISABLE_RGA=OFF
DISABLE_LIBJPEG=OFF
INSTALL_DIR=/mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/install/rk3576_linux_aarch64/rknn_gemma4_demo
BUILD_DIR=/mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/build/build_rknn_gemma4_demo_rk3576_linux_aarch64_Release
CC=/mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
CXX=/mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++
===================================
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mnt/data/linx/rk3576_linux6.1_next/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- LIBRKNNAPI = /mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/3rdparty/rknpu3/Linux/aarch64/librknn3_api.so
-- LIBRKNNAPI_INCLUDES = /mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/3rdparty/rknpu3/include
-- TARGET_LIB_ARCH =
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/build/build_rknn_gemma4_demo_rk3576_linux_aarch64_Release
[ 5%] Building C object utils.out/CMakeFiles/timeutils.dir/time_utils.c.o
[ 11%] Building CXX object utils.out/CMakeFiles/cnpy.dir/cnpy.cpp.o
[ 16%] Building CXX object utils.out/CMakeFiles/audioutils.dir/audio_utils.cc.o
[ 22%] Building C object utils.out/CMakeFiles/fileutils.dir/file_utils.c.o
[ 27%] Linking C static library libtimeutils.a
[ 33%] Linking C static library libfileutils.a
[ 33%] Built target fileutils
[ 33%] Built target timeutils
[ 38%] Building C object utils.out/CMakeFiles/imagedrawing.dir/image_drawing.c.o
[ 44%] Building C object utils.out/CMakeFiles/imageutils.dir/image_utils.c.o
/mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/utils/image_utils.c: In function ‘write_image’:
/mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/utils/image_utils.c:291:35: warning: passing argument 1 of ‘get_image_size’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
291 | int size = get_image_size(img);
| ^~~
In file included from /mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/utils/image_utils.c:20:
/mnt/data/linx/neardi_rk182x/rknn/rknn3-model-zoo/utils/image_utils.h:67:36: note: expected ‘image_buffer_t *’ but argument is of type ‘const image_buffer_t *’
67 | int get_image_size(image_buffer_t* image);
| ~~~~~~~~~~~~~~~~^~~~~
[ 50%] Linking CXX static library libcnpy.a
[ 50%] Built target cnpy
[ 55%] Linking C static library libimagedrawing.a
[ 55%] Built target imagedrawing
[ 61%] Linking C static library libimageutils.a
[ 61%] Built target imageutils
[ 66%] Linking CXX static library libaudioutils.a
[ 66%] Built target audioutils
[ 72%] Building CXX object CMakeFiles/rknn_gemma4_demo.dir/rknn_gemma4.cc.o
[ 77%] Building CXX object CMakeFiles/rknn_gemma4_demo.dir/vision/rknn_gemma4_vision.cc.o
[ 83%] Building CXX object CMakeFiles/rknn_gemma4_demo.dir/main.cc.o
[ 88%] Building CXX object CMakeFiles/rknn_gemma4_demo.dir/llm/rknn_gemma4_llm.cc.o
[ 94%] Building CXX object CMakeFiles/rknn_gemma4_demo.dir/audio/rknn_gemma4_audio.cc.o
[100%] Linking CXX executable rknn_gemma4_demo
[100%] Built target rknn_gemma4_demo

编译成功有如下文件:

linx@ubuntu2204-docker:~/neardi_rk182x/rknn/rknn3-model-zoo/install/rk3576_linux_aarch64/rknn_gemma4_demo$ tree
.
├── lib
│   ├── librga.so
│   ├── librknn3_api_rkcp.so
│   └── librknn3_api.so
└── rknn_gemma4_demo

最后, 把下载的gemma模型及demo app都拷贝到带rk182x的设备端, 如下:

neardi@LB3576:~/gemma$ tree
.
├── gemma4-e4b.embed.bin
├── gemma4-e4b_per_layer_inputs.embed.bin
├── gemma4-e4b.tokenizer.gguf
├── llm_gemma4-e4b.rknn
├── llm_gemma4-e4b.safetensors
├── llm_gemma4-e4b.weight
├── vision_gemma4-e4b.rknn
└── vision_gemma4-e4b.weight
neardi@LB3576:~/rk182x/rknn_gemma4_demo$ tree
.
├── bell.jpg
├── bus.jpg
├── lib
│   ├── librga.so
│   ├── librknn3_api_rkcp.so
│   └── librknn3_api.so
├── person.jpg
└── rknn_gemma4_demo

3.2 Test Gemma-e4b 多模态模型​

3.2.1 测试Gemma LLM​

如下方式启动Gemma LLM

rkllm3-server -m llm_gemma4-e4b.rknn \
--model2 vision_gemma4-e4b.rknn \
--vocab gemma4-e4b.tokenizer.gguf \
--embed gemma4-e4b.embed.bin \
--embed-ple gemma4-e4b_per_layer_inputs.embed.bin \
--rope-tensor llm_gemma4-e4b.safetensors \
--host 0.0.0.0 \
--port 8080 -c 0 \
--repeat-penalty 1.0 \
--presence-penalty 0 \
--frequency-penalty 0 \
--top-k 1 --top-p 0.8 --temp 0.8 \
--img-start "<image>" --img-end "</image>" \
--img-content "<unk>"

测试使用HTML页面即可, 如下:

3.2.1 测试Gemma Vision​

这里使用rknn3_gemma_zoo里的demo app来测试Gemma Vision模型, 把这张图片送给模型进行识别

如下:

neardi@LB3576:~/rk182x/rknn_gemma4_demo$ ./rknn_gemma4_demo  \
/home/neardi/gemma/llm_gemma4-e4b.rknn \
/home/neardi/gemma/llm_gemma4-e4b.weight \
0xff \
/home/neardi/gemma/gemma4-e4b.tokenizer.gguf \
/home/neardi/gemma/gemma4-e4b.embed.bin \
16384 \
4096 \
/home/neardi/gemma/gemma4-e4b_per_layer_inputs.embed.bin \
/home/neardi/gemma/llm_gemma4-e4b.safetensors \
"" \
"" \
0 \
/home/neardi/gemma/vision_gemma4-e4b.rknn \
/home/neardi/gemma/vision_gemma4-e4b.weight \
0xff \
"" \
bus.jpg "<image>请描述图片"
llama_model_loader: loaded meta data with 32 key-value pairs and 0 tensors from /home/neardi/gemma/gemma4-e4b.tokenizer.gguf (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv 0: general.architecture str = gemma4
llama_model_loader: - kv 1: general.type str = model
llama_model_loader: - kv 2: general.name str = Gemma 4 E4B It
llama_model_loader: - kv 3: general.license str = apache-2.0
llama_model_loader: - kv 4: general.license.link str = https://ai.google.dev/gemma/docs/gemm...
llama_model_loader: - kv 5: general.tags arr[str,1] = ["any-to-any"]
llama_model_loader: - kv 6: gemma4.context_length u32 = 131072
llama_model_loader: - kv 7: gemma4.embedding_length u32 = 2560
llama_model_loader: - kv 8: gemma4.block_count u32 = 42
llama_model_loader: - kv 9: gemma4.feed_forward_length u32 = 10240
llama_model_loader: - kv 10: gemma4.attention.head_count u32 = 8
llama_model_loader: - kv 11: gemma4.attention.layer_norm_rms_epsilon f32 = 0.000001
llama_model_loader: - kv 12: gemma4.attention.key_length u32 = 256
llama_model_loader: - kv 13: gemma4.attention.value_length u32 = 256
llama_model_loader: - kv 14: general.file_type u32 = 1
llama_model_loader: - kv 15: gemma4.rope.freq_base f32 = 1000000.000000
llama_model_loader: - kv 16: gemma4.attention.sliding_window u32 = 512
llama_model_loader: - kv 17: gemma4.attention.head_count_kv u32 = 2
llama_model_loader: - kv 18: general.quantization_version u32 = 2
llama_model_loader: - kv 19: tokenizer.ggml.model str = gemma4
llama_model_loader: - kv 20: tokenizer.ggml.tokens arr[str,262144] = ["<pad>", "<eos>", "<bos>", "<unk>", ...
llama_model_loader: - kv 21: tokenizer.ggml.scores arr[f32,262144] = [-1000.000000, -1000.000000, -1000.00...
llama_model_loader: - kv 22: tokenizer.ggml.token_type arr[i32,262144] = [3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, ...
llama_model_loader: - kv 23: tokenizer.ggml.merges arr[str,514906] = ["\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n", ...
llama_model_loader: - kv 24: tokenizer.ggml.bos_token_id u32 = 2
llama_model_loader: - kv 25: tokenizer.ggml.eos_token_id u32 = 1
llama_model_loader: - kv 26: tokenizer.ggml.unknown_token_id u32 = 3
llama_model_loader: - kv 27: tokenizer.ggml.padding_token_id u32 = 0
llama_model_loader: - kv 28: tokenizer.ggml.mask_token_id u32 = 4
llama_model_loader: - kv 29: tokenizer.chat_template str = {%- macro format_parameters(propertie...
llama_model_loader: - kv 30: tokenizer.ggml.add_space_prefix bool = false
llama_model_loader: - kv 31: tokenizer.ggml.add_bos_token bool = true
init_tokenizer: initializing tokenizer for type 2
load: 0 unused tokens
load: control token: 258884 '<|video|>' is not marked as EOG
load: control token: 255999 '<|image>' is not marked as EOG
load: control token: 258882 '<image|>' is not marked as EOG
load: control token: 258883 '<audio|>' is not marked as EOG
load: control token: 98 '<|think|>' is not marked as EOG
load: control token: 105 '<|turn>' is not marked as EOG
load: control token: 258880 '<|image|>' is not marked as EOG
load: control token: 2 '<bos>' is not marked as EOG
load: control-looking token: 212 '</s>' was not control-type; this is probably a bug in the model. its type will be overridden
load: control token: 0 '<pad>' is not marked as EOG
load: control-looking token: 50 '<|tool_response>' was not control-type; this is probably a bug in the model. its type will be overridden
load: control token: 46 '<|tool>' is not marked as EOG
load: control token: 47 '<tool|>' is not marked as EOG
load: control token: 256000 '<|audio>' is not marked as EOG
load: control token: 3 '<unk>' is not marked as EOG
load: control token: 258881 '<|audio|>' is not marked as EOG
load: control token: 4 '<mask>' is not marked as EOG
load: printing all EOG tokens:
load: - 1 ('<eos>')
load: - 50 ('<|tool_response>')
load: - 106 ('<turn|>')
load: - 212 ('</s>')
load: special_eog_ids contains '<|tool_response>', removing '</s>' token from EOG list
load: special tokens cache size = 24
load: token to piece cache size = 1.9445 MB
print_info: vocab type = BPE
print_info: n_vocab = 262144
print_info: n_merges = 514906
print_info: BOS token = 2 '<bos>'
print_info: EOS token = 1 '<eos>'
print_info: UNK token = 3 '<unk>'
print_info: PAD token = 0 '<pad>'
print_info: MASK token = 4 '<mask>'
print_info: LF token = 107 '
'
print_info: EOG token = 1 '<eos>'
print_info: EOG token = 50 '<|tool_response>'
print_info: EOG token = 106 '<turn|>'
print_info: max token length = 93
GetVocabInfo: special_eos_id[1] = 1
GetVocabInfo: special_eog_id[2] = 50
GetVocabInfo: special_eog_id[3] = 106
vocab_info: vocab_size=262144, special_bos_id=[2], special_eos_id=[1, 50, 106]
--> init gemma4 vision model
model input num: 1, output num: 1
input tensors:
Tensor: name=pixel, n_dims=4, shape=[1, 384, 384, 3], stride=[442368, 1152, 3, 1], aligned_size=442368, layout=NHWC, dtype=UINT8, core_id=0, qnt_type=NONE
output tensors:
Tensor: name=last_hidden_state, n_dims=2, shape=[64, 2560], stride=[2560, 1], aligned_size=327680, layout=UNDEFINED, dtype=FP16, core_id=0, qnt_type=NONE
model is NHWC input layout
input image height=384, input image width=384, input image channel=3
model is UNDEFINED output layout
--> init gemma4 llm model
device id: 0000:04:00.0, type: PCIE
--> reading image file: bus.jpg
Loaded rope_cos_cache_0 dtype=1 shape=[1,16,1,16384,16]
Loaded rope_sin_cache_0 dtype=1 shape=[1,16,1,16384,16]
Loaded rope_cos_cache_1 dtype=1 shape=[1,32,1,16384,16]
Loaded rope_sin_cache_1 dtype=1 shape=[1,32,1,16384,16]

=============================================================
Max Context Length : 16384
Max Position Embeddings : 16384
Model Type : gemma4
Task Type : RKNN3_LLM_TASK_GENERATE
Max New Tokens : 4096
=============================================================

--> inference gemma4 model
convert image use cpu
finish
image n_image_tokens: 64
--> inference gemma4 llm model
This is a photograph of a **city bus** parked on a street, with a backdrop of **European-style buildings**.

Here is a detailed description:

**The Bus:**
* The most prominent feature is a **large, modern city bus**.
* It is predominantly **dark blue** with white and light blue accents.
* The side of the bus features prominent branding, including the word "**e2e**" and text that appears to relate to environmental or low-emission transport (partially visible text includes "low emission").
* The bus has large windows and appears to be a public transit vehicle.

**The People:**
* There are **three men** visible near the bus, suggesting they might be waiting, working, or interacting near the vehicle.
* **Man 1 (Left):** Wearing a light-colored (possibly beige or light gray) jacket and dark pants, he is standing near the front of the bus, looking toward the center.
* **Man 2 (Center):** Wearing a dark blue or black jacket and dark pants, he is standing near the middle of the bus, looking toward the left.
* **Man 3 (Right):** Wearing a dark jacket and dark pants, he is visible on the far right side of the frame, near the rear of the bus.

**The Setting/Background:**
* The bus is situated on a **paved street or square**.
* The background consists of **historic or traditional European-style architecture**. The buildings are multi-story, featuring stone or stucco facades, and some have visible window frames and balconies.
* There is **greenery** visible, including trees and bushes, suggesting an urban or town setting.
* The lighting suggests it is **daytime** with bright sunlight.

**Overall Impression:**
The image captures a slice of urban life, focusing on modern public transportation set against a backdrop of older, European-inspired city architecture.
-----------------------------------------------------------------------------------------
Stage | Total Time (ms) | Tokens | Time per Token (ms) | Tokens per Second
-----------------------------------------------------------------------------------------
Prefill | 173.87 | 78 | 2.23 | 448.61
Generate | 8624.90 | 415 | 20.78 | 48.12
-----------------------------------------------------------------------------------------
Vision latency = 71.91 ms, FPS = 13.91
neardi@LB3576:~/rk182x/rknn_gemma4_demo$

可以看出gemma vision已经对图片有识别并输出结果。