4. RKLLM3 Server#
RKLLM3 Server 是基于RKNPU3实现的LLM HTTP Server,向客户端提供与 OpenAI API 兼容 的对话补全、 词嵌入等接口,支持文本、图片与音频输入、视频输入,并通过Session(Slot)机制实现多用户并发与对话隔离。
RKLLM3 Server以 二进制文件和库的方式 发布,在安装预编译固件时,会自动安装, 参考文档 RK182X快速使用 正常安装固件包后,即可在板卡端使用rkllm3-server命令。
rkllm3-server详细参数和使用请参考网盘文档: 06_RKLLM3_Server_使用指南_V1.2.0.pdf以及 Rockchip_User_Guide_RKNN_RKLLM3_Server_DEMO_CN.pdf。
4.1. 获取测试模型文件#
从网盘下载测试模型文件,或者参考后面模型示例章节自行转换LLM/VLM模型文件。
按下面的目录结构组织模型:
/home/cat/
├── Qwen3-0.6B/
│ ├── Qwen3-0.6B.embed.bin
│ ├── Qwen3-0.6B.rknn
│ ├── Qwen3-0.6B.tokenizer.gguf
│ └── Qwen3-0.6B.weight
└── Qwen3-VL-2B/
├── llm_Qwen3-VL-2B.rknn
├── llm_Qwen3-VL-2B.weight
├── Qwen3-VL-2B.embed.bin
├── Qwen3-VL-2B.tokenizer.gguf
├── vision_Qwen3-VL-2B.rknn
└── vision_Qwen3-VL-2B.weight
将Qwen3-0.6B或者Qwen3-VL-2B目录下的模型文件复制到板端(Host端)用户目录下,通过scp或者adb命令。
4.2. 启动rkllm3-server服务#
rkllm3-server程序的相关参数,请使用命令查看:
cat@lubancat:~$ rkllm3-server -h
ersion: 1.2.0 (e7a9c4f93@2026-10-29T14:47:21)
----- common params -----
-c, --ctx-size N#N#N... size of the prompt context (default: 4096, 0 = loaded from model); use
'#' to separate per-slot values, e.g. 4096#2048#8192
-n, --predict, --n-predict N#N#N...
number of tokens to predict (default: -1, -1 = context size); use '#'
to separate per-slot values, e.g. 512#256#-1
-a, --alias STRING set alias for model name (to be used by REST API)
-m, --model FNAME rknn llm model path. For multi-card cascade, please set the first
stage model name(e.g. model_seg0.rknn). Prefix "dev:" means
device-side filesystem (emmc)
--weight FNAME rknn llm model weight path. For multi-card cascade, set the first
stage weight name(e.g. model_seg0.weight). Prefix "dev:" means
device-side filesystem (emmc)
--stage-count N count of model segmentation, just for multi-card cascade
--bucket-size N bucket size (max tokens per prefill bucket) for multi-card pipeline
--model2 FNAME rknn vision model path. Prefix "dev:" means device-side filesystem
(emmc)
--weight2 FNAME rknn vision model weight path. Prefix "dev:" means device-side
filesystem (emmc)
--model3 FNAME rknn audio model path. Prefix "dev:" means device-side filesystem
(emmc)
--weight3 FNAME rknn audio model weight path. Prefix "dev:" means device-side
filesystem (emmc)
#省略........................................
常用参数 |
说明 |
|---|---|
|
LLM 模型与权重路径;权重可由模型路径自动推导 |
|
tokenizer 与 embedding 文件路径 |
|
上下文长度,默认 4096;0 表示从模型加载 |
|
生成 token 数,默认 -1(等于上下文长度) |
|
LLM 核掩码, |
|
Vision / Audio 模型的核掩码 |
|
Session(Slot)数量,默认 1,最大 16,需考虑设备内存 |
|
监听地址与端口,默认 |
|
多设备时指定设备 ID |
|
读写超时时间(秒),默认 600 |
|
采样参数,默认 0.8 / 1 / 0.9 |
|
日志详细程度,默认 0 |
4.2.1. 命令行启动rkllm3-server#
测试纯文本 LLM(Qwen3-0.6B),在与模型文件相同的工作目录执行:
cd /home/cat/Qwen3-0.6B/
# 板端测试
rkllm3-server \
-m Qwen3-0.6B.rknn \
--weight Qwen3-0.6B.weight \
--vocab Qwen3-0.6B.tokenizer.gguf \
--embed Qwen3-0.6B.embed.bin \
--host 0.0.0.0 \
--port 8080 \
-c 768 \
-n 512 \
--core-mask 0xff \
--repeat-penalty 1.1 \
--presence-penalty 1.0 \
--frequency-penalty 1.0 \
--top-k 1 --top-p 0.8 --temp 0.8
启动成功后终端会显示类似信息:
main: server is listening on http://0.0.0.0:8080 - starting the main loop
bind_server: binding port with default address family
测试VLM模型Qwen3-VL-2B,在与模型文件相同的工作目录执行:
4.2.2. 配置文件启动#
同时加载多个模型时,通过 --params-file 指定 JSON 配置⽂件,然后启动服务。
型配置⽂件⽰例(教程测试是一个模型,可添加多个模型):
1{
2 "host": "127.0.0.1",
3 "port": 8080,
4 "timeout": 30,
5 "models": {
6 "Qwen3-0.6B": {
7 "alias": "Qwen3-0.6B",
8 "model": "Qwen3-0.6B.rknn",
9 "weight": "Qwen3-0.6B.weight",
10 "vocab": "Qwen3-0.6B.tokenizer.gguf",
11 "embed": "Qwen3-0.6B.embed.bin",
12 "ctx-size": 1024,
13 "predict": 512,
14 "temp": 0.8,
15 "top-k": 1,
16 "top-p": 0.8,
17 "repeat-penalty": 1.1,
18 "presence-penalty": 1.0,
19 "frequency-penalty": 1.0,
20 "n-session": 1
21 }
22 }
23}
cd /home/cat/Qwen3-0.6B/
# 板端测试,将前面的配置文件保存为params.json,然后执行如下命令:
rkllm3-server --params-file params.json
# 正常启动后
main: server is listening on http://127.0.0.1:8080 - starting the main loop
bind_server: binding port with default address family
srv update_slots: all slots are idle
4.2.3. 服务常用API端点#
端点 |
方法 |
功能 |
|---|---|---|
|
GET |
健康检查 |
|
POST |
对话补全(流式 / 非流式) |
|
GET |
模型列表 |
|
GET |
嵌入向量 |
|
GET |
获取所有 LoRA 适配器信息 |
|
POST |
设置 LoRA 适配器列表 |
|
POST |
暂停 slot |
4.2.4. 简单测试#
# 另外开启一个终端,测试服务状态输出
cat@lubancat:~$ curl http://localhost:8080/health
{"status":"ok"}
# 查看模型列表
cat@lubancat:~$ curl http://localhost:8080/v1/models
{"object":"list","data":[{"id":"Qwen3-0.6B","object":"model","created":1795056505,"owned_by":"rknn",
"meta":{"vocab_type":2,"n_vocab":151936,"n_ctx_train":-1,"n_embd":1024,"n_params":0,"size":0}}]}
4.3. API 调用对话测试#
4.3.1. curl 请求#
# 测试输出
cat@lubancat:~$ curl --request POST \
--url http://localhost:8080/v1/chat/completions \
--header "Content-Type: application/json" \
--header "Authorization: Bearer no-key" \
--data '{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"n_predict": 128
}'
{"choices":[{"finish_reason":"stop","index":0,"message":{"role":"assistant","content":"<think>\nOkay,
the user just said \"Hello!\" so I need to respond appropriately. Let me check if there's any specific context
or question they might be asking here. Since it's a greeting, maybe they're testing my response style or want
some friendly interaction.\n\nI should acknowledge their message and offer help. Maybe say something like
\"Hi! How can I assist you today?\" That way, the conversation remains open-ended and helpful.
Also, keeping the tone positive is important to maintain good rapport.
\n</think>\n\nHello! How can I assist you today? 😊"}}],"created":1794966628,"model":"Qwen3-0.6B.rknn","
system_fingerprint":"b5166-24345353","object":"chat.completion","usage":{"completion_tokens":115,
"prompt_tokens":42,"total_tokens":157},"id":"chatcmpl-O2FpO7xPEq5NUgp8Wkte8dosikgwsVEV","id_slot":0,
"timings":{"prompt_n":42,"prompt_ms":64.71,"prompt_per_token_ms":1.5407142857142855,
"prompt_per_second":649.0496059341679,"predicted_n":115,"predicted_ms":794.954,
"predicted_per_token_ms":6.973280701754385,"predicted_per_second":143.404524035353}}
4.3.2. Python 客户端#
板端(Host端)安装openai
pip3 install openai
rkllm3-server服务兼容OpenAI PythonSDK, 调用方式与标准OpenAI API一致,添加python脚本文件(以qwen3 纯⽂本对话为例):
import openai
client = openai.OpenAI(
base_url="http://localhost:8080/v1",
api_key="sk-no-key-required",
)
# 这里只有一个模型默认即可
completion = client.chat.completions.create(
model="Qwen3-0.6B",
messages=[{"role": "user", "content": "Hello!"}],
)
print(completion.choices[0].message.content)
流式输出使用 stream=True:
completion = client.chat.completions.create(
model="Qwen3-0.6B",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
extra_body={"n_predict": 128},
)
for chunk in completion:
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="", flush=True)
# 将前面内容复制到创建的python文件:python_openai.py 中,然后测试输出
cat@lubancat:~$ python3 python_openai.py
<think>
Okay, the user just said "Hello!" so I need to respond appropriately.
Let me check if there's any specific context they're looking for.
Since it's a greeting, maybe offer help or ask how I can assist them.
I should keep it friendly and open-ended. Maybe say something like "Hi! How can I assist you today?"
That covers both the greeting and offers support.
</think>
Hello! How can I assist you today? 😊cat@lubancat:~$