端侧部署 HY-MT2-1.8B
介绍
Hy-MT2 是一系列专为复杂现实场景设计的“快速思考”多语言翻译模型。该系列包含三种模型尺寸:1.8B、7B 和 30B-A3B (MoE),均支持 33 种语言之间的互译,并能有效遵循多种语言的翻译指令。
针对端侧部署需求,采用 AngelSlim 1.25-bit 极限量化技术后,1.8B 模型的存储需求大幅缩减至仅 440 MB,同时推理速度提升了 1.5 倍。
多维度评估表明,Hy-MT2 在通用领域、真实业务场景、特定领域以及指令遵循等翻译任务中均表现出卓越的性能。在快速思考模式下,其 7B 和 30B-A3B 模型超越了 DeepSeek-V4-Pro 和 Kimi K2.6 等开源模型;而轻量级的 1.8B 模型在整体表现上也超越了微软、豆包等主流商业 API。
本章节将演示如何在边缘设备上完成 HY-MT2-1.8B 部署、加载与翻译流程。提供以下两种方式部署:
- AidGen C++ API
- AidGenSE OpenAI API
在本案例中,大语言模型推理运行在设备端,通过代码调用相关接口接收用户输入并实时返回对话结果。
- 设备:Rhino Pi-X1
- 系统:Ubuntu 22.04
- 模型:HY-MT2-1.8B
支持平台
| 平台 | 运行方式 |
|---|---|
| Rhino Pi-X1 | Ubuntu 22.04, AidLux |
准备工作
Rhino Pi-X1 硬件
Ubuntu 22.04 系统或 AidLux 系统
AidGen 案例部署
步骤一:安装 AidGen SDK
bash
# 安装 AidGen SDK
sudo aid-pkg update
sudo aid-pkg -i aidgen-sdk
sudo aid-pkg -i aidgen-qnn240
sudo aid-pkg -i aidgen-qnn248
# 拷贝测试代码
cd /home/aidlux/aidllm
cp -r /usr/local/share/aidgen/examples/ ./步骤二:下载模型资源
由于 HY-MT2-1.8B 目前位于 Model Farm 专业板块中,需要通过
mms命令获取
bash
# 登录
mms login
# 查找模型
mms list HY
# 下载模型
mms get -m HY-MT2-1.8B -p w4a16 -c qcs8550 -b qnn2.48 -d /home/aidlux/aidllm/
cd /home/aidlux/aidllm/
unzip qnn236_qcs8550_cl4096.zip步骤三:资源文件确认
文件分布如下:
bash
/home/aidlux/aidllm/qnn236_qcs8550_cl4096
├── hy-mt2-1.8b_qnn236_qcs8550_cl4096_3_of_3.serialized.bin.aidem
├── hy-mt2-1.8b_qnn236_qcs8550_cl4096_2_of_3.serialized.bin.aidem
├── hy-mt2-1.8b_qnn236_qcs8550_cl4096_1_of_3.serialized.bin.aidem
├── chat.txt
├── aidgen_config.json
├── prefix-kvcache步骤四:对话模板设置
💡注意
对话模板请参考模型资源包中的chat.txt 文件
根据大模型的模板修改 test_aidgen_t2t.cpp 文件:
cpp
std::string system_prompt =
"<|hy_begin▁of▁sentence|><|hy_User|>Translate the following text into Chinese.\n"
"Only output the translated result without any additional explanation:\n";
auto make_user_turn = [](const std::string& text) -> std::string {
return "<|im_start|>user\n" + text + "<|im_end|>\n" + "<|hy_Assistant|>";
};步骤五:编译运行
bash
cd /home/aidlux/aidllm/examples
# 编译
mkdir build && cd build
cmake .. && make
cp test_t2t ../../qnn236_qcs8550_cl2048
cd /home/aidlux/aidllm/qnn236_qcs8550_cl4096
./test_t2t aidgen_config.json "Success is not final, failure is not fatal: it is the courage to continue that counts. Believe in yourself and all that you are, for greatness lives within your soul."- 模型运行成功后,有如下日志回显
bash
============================================================
Turn 1: Single-turn inference
============================================================
User: Success is not final, failure is not fatal: it is the courage to continue that counts. Believe in yourself and all that you are, for greatness lives within your soul.
Assistant: [API] Generator::run(prompt, callback)
[BOS]成功并非终点,失败也不算彻底:重要的是继续前进的勇气。相信自己以及自己的全部特质,因为伟大存在于你的灵魂之中。<|hy_place▁holder▁no▁2|>[EOS]
--- Turn 1 Performance (Generator::get_profiler) ---
Init Time (us): 1982206
Prompt Token Count: 65
Time-to-First-Token (us): 53478
Prompt TPS (tok/s): 2393.51
Generated Token Count: 27
Generate Time (us): 708170
Generate TPS (tok/s): 38.1264
============================================================AidGenSE 案例部署
步骤一:安装 AidGenSE
bash
sudo aid-pkg update
# 确保 aidgense 是最新版本
sudo aid-pkg remove aidgense
sudo aid-pkg -i aidgense
sudo aid-pkg -i aidgen-sdk
sudo aid-pkg -i aidgen-qnn*步骤二:模型查询 & 获取
bash
# 查看模型
aidllm remote-list api | grep hy
#------------------------可以看到 HY-MT2-1.8B 模型------------------------
hy-mt2-1.8b-qnn2.48-w4a16-qcs8550 LLM 2026-08-13 17:46:43
hy-mt1.5-1.8b-qnn2.36-w4a16-qcs8550 LLM 2026-08-13 17:46:43
...
# 下载 HY-MT2-1.8B
aidllm pull api hy-mt2-1.8b-qnn2.48-w4a16-qcs8550步骤三:启动 HTTP 服务
bash
# 启动对应模型的 openai api 服务
aidllm start api -m hy-mt2-1.8b-qnn2.48-w4a16-qcs8550 --qnn_ver 248
# 查看状态
aidllm status api
# 停止服务: aidllm stop api
# 重启服务: aidllm restart api💡注意
默认端口号是 8888
步骤四:对话测试
使用 Web UI 对话测试
bash
# 安装 UI 前端服务
sudo aidllm install ui
# 启动 UI 服务
aidllm start ui
# 查看 UI 服务状态: aidllm status ui
# 停止 UI 服务: aidllm stop uiUI 服务启动后访问 http://ip:51104
输入如下对话模板即可翻译
plain
Translate the following segment into Chinese, without additional explanation.
Success is not final, failure is not fatal: it is the courage to continue that counts. Believe in yourself and all that you are, for greatness lives within your soul.使用 Python 对话测试
python
import os
import requests
import json
def stream_chat_completion(messages, model="hy-mt2-1.8b-qnn2.48-w4a16-qcs8550"):
url = "http://127.0.0.1:8888/v1/chat/completions"
headers = {
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages,
"stream": True # 打开流式
}
# 发起带 stream=True 的请求
response = requests.post(url, headers=headers, json=payload, stream=True)
response.raise_for_status()
# 逐行读取并解析 SSE 格式
for line in response.iter_lines():
if not line:
continue
# print(line)
line_data = line.decode('utf-8')
# SSE 每一行以 "data: " 前缀开头
if line_data.startswith("data: "):
data = line_data[len("data: "):]
# 结束标志
if data.strip() == "[DONE]":
break
try:
chunk = json.loads(data)
except json.JSONDecodeError:
# 解析出错时打印并跳过
print("无法解析JSON:", data)
continue
# 取出模型输出的 token
content = chunk["choices"][0]["delta"].get("content")
if content:
print(content, end="", flush=True)
if __name__ == "__main__":
# 示例对话
messages = [
{"role": "system", "content": ""},
{"role": "user", "content": "Translate the following segment into Chinese, without additional explanation.\n\nSuccess is not final, failure is not fatal: it is the courage to continue that counts. Believe in yourself and all that you are, for greatness lives within your soul."}
]
print("Assistant:", end=" ")
stream_chat_completion(messages)
print() # 换行