48 lines
2.0 KiB
Markdown
48 lines
2.0 KiB
Markdown
# engnex-r200-translation
|
||
|
||
运行于【昆仑芯 R200】系列算力卡的【翻译】引擎,基于 transformer 架构,支持 NLLB-200、SMaLL-100 等最新流行翻译模型
|
||
|
||
# translation-transformers
|
||
## Quickstart
|
||
```shell
|
||
#构建docker镜像
|
||
docker build . -t klx_r200_translation
|
||
|
||
#运行docker容器
|
||
docker run -it -p 10078:80 -v 你的模型路径:/model:ro --device=/dev/xpu0:/dev/xpu0 --device=/dev/xpuctrl:/dev/xpuctrl -e MODEL_TYPE=opus_mt -e --name klx_r200_translation_test klx_r200_translation
|
||
```
|
||
请提前将模型文件下载某个位置,并替换掉上述docker run命令中的“你的模型路径”
|
||
模型地址,如:https://modelscope.cn/models/moxying/opus-mt-zh-en
|
||
等待模型加载完成,出现以下日志时,代表服务启动成功
|
||
```shell
|
||
INFO: Application startup complete.
|
||
INFO: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
|
||
```
|
||
执行测试程序
|
||
```shell
|
||
python3 test.py
|
||
```
|
||
测试程序执行结果
|
||
```
|
||
Succeed!
|
||
Response: [{'translations': [{'origin_text': '生活就像一块巧克力', 'translated': 'Life is like a piece of chocolate.'}, {'origin_text': '你来自哪里', 'translated': 'Where are you from?'}, {'origin_text': '你吃饭了吗', 'translated': 'Have you eaten yet?'}]}]
|
||
```
|
||
停止docker容器
|
||
```
|
||
docker stop klx_r200_translation_test
|
||
```
|
||
## 模型支持
|
||
在Quickstart中运行容器时,通过环境变量的方式,指定模型的类型,即:
|
||
```
|
||
-e MODEL_TYPE=opus_mt
|
||
```
|
||
目前支持以下几种配置:
|
||
| MODEL_TYPE | 模型名称 |
|
||
| ---------- | --------------------------------------- |
|
||
| nllb200 | facebook/nllb-200-distilled-600M |
|
||
| small100 | aiyueqi/alirezamsh_small100 |
|
||
| mbart | facebook/mbart-large-50-many-to-many-mmt|
|
||
| opus_mt | moxying/opus-mt-zh-en |
|
||
|
||
其中,MODEL_TYPE代表模型类型,必须为以上表格列举之一; 模型文件提前下载到某个路径下,并挂载到容器中的/model目录,需要和MODEL_TYPE对应
|