[分享] 用腾讯开源的混元翻译模型 1.8B 给翻译插件当本地 API

5 月 26 日
 zsxzy

最近在找本地离线翻译大模型,测试了腾讯开源的 **混元翻译模型 1.8B **。

我用了几篇不同的技术文章进行深度对比,它的翻译质量明显高于 Google 翻译和微软翻译,术语和语序都更符合中文习惯,1.8B 的体量能有这个效果让人非常惊喜。

这里分享一下我的部署和启动参数优化经验。


1. 模型下载

建议下载 GGUF 格式,方便用 llama.cpp / llama-server 直接跑:


2. 启动与优化指令

如果你使用的是 RTX 3060 6GB 显卡,可以使用我优化后的 llama-server 启动命令。

这里开启了 --flash-attn 以及 KV 缓存量化(q8_0),基本可以把模型完全塞进显存,速度飞快:

llama-server -hf tencent/Hy-MT2-1.8B-GGUF:Q8_0 \
  -c 8192 \
  --port 8080 \
  -ngl 99 \
  --flash-attn on \
  -t 6 \
  --cache-type-k q8_0 \
  --cache-type-v q8_0 \
  --parallel 1 \
  --jinja \
  --n-predict -1 \
  --verbosity 1

3. PowerShell 测试指令

服务启动后,兼容 OpenAI 的 API 格式。在 Windows 下可以用以下 PowerShell 命令直接测试:

Invoke-RestMethod -Method Post -Uri "[http://127.0.0.1:8080/v1/chat/completions]( http://127.0.0.1:8080/v1/chat/completions)" `
  -ContentType "application/json" `
  -Body (@{
    model = "gpt-3.5-turbo"
    messages = @(
        @{role = "user"; content = "Translate to Chinese: Comparing Rust and C++ performance is a topic that all software developers should consider. In this guide, they are compared in terms of memory safety, concurrency models, and compilation performance. You will understand why C++ provides the best performance, and Rust does not compromise on safety as a trade-off. Simple differentiation and real-life examples will help you be prepared to make the correct choice of the right tool 。"}
    )
    stream = $false
  } | ConvertTo-Json)


4. 运行结果与性能 (RTX 3060 6GB)

在我的 3060 上,生成的 Token 速度非常理想,完全能喂饱翻译插件的并发需求:

choices            : {@{finish_reason=stop; index=0; message=}}
created            : 1779531650
model              : tencent/Hy-MT2-1.8B-GGUF:Q8_0
system_fingerprint : b9294-0f3cb3fc8
object             : chat.completion
usage              : @{completion_tokens=68; prompt_tokens=88; total_tokens=156; prompt_tokens_details=}
id                 : chatcmpl-5XADKRfaVh7iZ1Iva7bt1P1oRJkQBr5Q

# 性能耗时指标:
timings            : @{
    cache_n=0; 
    prompt_n=88; 
    prompt_ms=312.969; 
    prompt_per_token_ms=3.556; 
    prompt_per_second=281.178; 
    predicted_n=68; 
    predicted_ms=555.212; 
    predicted_per_token_ms=8.164; 
    predicted_per_second=122.475
}

总结: predicted_per_second 达到了 122 tokens/s

3384 次点击
所在节点    分享发现
13 条回复
minimaluminium
5 月 26 日
可以试试 tencent/Hy-MT2-1.8B-GGUF
jackOff
5 月 26 日
windows 已经自己开放了一个本地翻译模型接口,纯 cpu 也可以流畅使用
Aprdec
5 月 26 日
@jackOff 请问怎么搜索相关资料
jackOff
5 月 26 日
@Aprdec https://github.com/SakiRinn/LiveCaptions-Translator 这个项目就是直接调用这玩意来做浏览器翻译插件的
jackOff
5 月 26 日
@Aprdec https://github.com/AnYi-0/Translator 搞错了,应该是这玩意,基于 Chrome 版本:138+
sonaxyjh
5 月 26 日
这两天热榜上的不是 MT2 1.8B 吗
Sezxy
5 月 26 日
@jackOff #5 好像翻译效果一般般,技术名词都直接翻译
zsxzy
5 月 26 日
@minimaluminium 下载地址写错了,用的是版本 2 😂
Hansah
5 月 26 日
MT1 1.8B 有 1.25bit 的量化版(需要自己编译 llama ),机器性能好的话可以上 MT2 1.8 ,
skyemin
5 月 26 日
晚上回家试试
iorilu
5 月 27 日
@jackOff 没看明白, 这不是基于 chrome 的吗

你说的 windows 开发本地翻译模型接口, 是指那个
jackOff
5 月 27 日
@iorilu 那我记岔了
Gkont
5 月 28 日
目前在用 Hy-MT2-7B-Q8.感觉还行.碾压谷歌机翻是没问题的.就是逊色于 deepl

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1215441

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX