# Marian-ONNX
## Instructions
1. Make sure you have the python dependencies installed.
```sh
python3 -m pip install -r requirements.txt
```
2. Download a Marian model from huggingface hub (you may need to install `git-lfs`)
```sh
git lfs clone https://huggingface.co/Helsinki-NLP/opus-mt-fr-en ./models/fr-en
```
3. Convert the Marian model to ONNX.
```sh
python3 convert.py ./models/fr-en
```
## Usage
```py
from transformers import MarianTokenizer
from core.marian import MarianOnnx
DEVICE = 'cpu'
SENTENCES = ["Bonjour", "Je m'appelle Bob"]
MODEL_PATH = "./outs/fr-en"
tokenizer = MarianTokenizer.from_pretrained(MODEL_PATH)
input_ids = tokenizer(SENTENCES, return_tensors='pt', padding=True).to(DEVICE)
model = MarianOnnx(MODEL_PATH, device=DEVICE)
tokens = model.generate(**input_ids)
print(tokenizer.batch_decode(tokens, skip_special_tokens=True))
# ['Hello.', 'My name is Bob.']
```
## Benchmark
```sh
# Benchmark for the opus-mt-fr-en model on a NVIDIA GeForce RTX 2070
$> python3 -m core.benchmark
CPU Benchmark:
Warming up ORT...
ORT CPU: 48 ms / sentence
PyTorch CPU: 152 ms / sentence
-----
GPU Benchmark:
Warming up ORT...
ORT GPU: 31 ms / sentence
PyTorch GPU: 66 ms / sentence
```
没有合适的资源?快使用搜索试试~ 我知道了~
Marian-onnx-converter, MarianMTModel转换为onnx
共43个文件
py:7个
pyc:6个
xml:6个
需积分: 16 3 下载量 53 浏览量
2022-10-26
23:15:33
上传
评论
收藏 335.84MB ZIP 举报
温馨提示
Marian-onnx-converter, MarianMTModel转换为onnx
资源推荐
资源详情
资源评论
收起资源包目录
Marian-ONNX-Converter.zip (43个子文件)
Marian-ONNX-Converter
models
.gitkeep 0B
core
utils.py 4KB
__pycache__
quantize.cpython-39.pyc 1KB
__init__.cpython-39.pyc 149B
utils.cpython-39.pyc 3KB
benchmark.cpython-39.pyc 3KB
layers.cpython-39.pyc 1KB
marian.cpython-39.pyc 5KB
benchmark.py 2KB
__init__.py 0B
layers.py 1KB
quantize.py 988B
marian.py 7KB
outs
source.spm 786KB
tokenizer_config.json 44B
vocab.json 1.54MB
decoder.onnx 88.8MB
lm_weight.bin 126.96MB
encoder.onnx 50.33MB
target.spm 788KB
opus-mt-zh-en
source.spm 786KB
tokenizer_config.json 44B
vocab.json 1.54MB
lm_weight.bin 126.96MB
target.spm 788KB
lm_bias.bin 255KB
config.json 1KB
lm_bias.bin 255KB
.gitkeep 0B
config.json 1KB
.idea
Marian-ONNX-Converter.iml 493B
misc.xml 194B
deployment.xml 627B
modules.xml 301B
workspace.xml 6KB
.gitignore 184B
inspectionProfiles
Project_Default.xml 1KB
profiles_settings.xml 174B
setup.cfg 617B
convert.py 1KB
requirements.txt 111B
.gitignore 2KB
README.md 1KB
共 43 条
- 1
资源评论
goodfate_and_fortune
- 粉丝: 5
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Tableau实训一-教育网站指标评估
- 基于Python爬虫+词云图+情感分析对某东上完美日记的用户评论分析(数据集+代码).rar
- 古诗105-听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴听琴
- 一个普通的SpringCloud样例
- PSE-PCN考试题库该题库答案为真实选项,另外选项为额外插入,非原题选项
- 数据挖掘实战-基于KMeans算法对超市客户进行聚类分群(数据集+代码).rar
- css网页设计.pdf
- 数据分析案例-顾客购物数据可视化分析(数据集+代码).rar
- 19613fc3f7378acf2787f12bbf7a34a1.JPG
- mmexport1718846385059.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功