Downloads · 30 days
34
14% of all-time downloads
baby2008/nllb-200-distilled-600M-onnx
nllb-200-distilled-600M-onnx is a translation model from baby2008. Use it when you need text moved from one language to another. The card lists the license as mit.
NLLB-200 (No Language Left Behind) 翻译模型的 ONNX 格式版本,支持 200+ 语言互译。
Downloads · 30 days
34
14% of all-time downloads
All-time downloads
235
Public
Repo size
4.3 GB
Likes
0
Public
Click a slice to open those files.
.onnx4.2 GB · 99%
From the Hugging Face model README
NLLB-200 (No Language Left Behind) 翻译模型的 ONNX 格式版本,支持 200+ 语言互译。
.
├── config.json
├── tokenizer.json
├── special_tokens_map.json
├── generation_config.json
├── quantize_config.json
├── onnx/
│ ├── fp32/ # FP32 原始模型 (1.6 GB)
│ │ ├── encoder.onnx # 编码器 (1.54 GB)
│ │ ├── decoder.onnx # 解码器 (420 KB)
│ │ ├── decoder_with_past.onnx # 带缓存的解码器 (313 KB)
│ │ └── decoder_merged.onnx # 合并版解码器 (915 KB)
│ └── int8/ # INT8 量化模型 (2.5 GB)
│ ├── encoder.onnx # 量化编码器 (397 MB)
│ ├── decoder.onnx # 量化解码器 (697 MB)
│ ├── decoder_with_past.onnx # 量化带缓存解码器 (673 MB)
│ └── decoder_merged.onnx # 量化合并解码器 (698 MB)
| 指标 | FP32 | INT8 | 改进 |
|---|---|---|---|
| 编码器大小 | 1.54 GB | 397 MB | ↓ 74% |
| 内存占用 | 2259 MB | 577 MB | ↓ 74% |
| 推理速度 | 1.0x | 1.3x | ↑ 30% |
| 输出质量 | 基准 | 99.93% | 几乎无损失 |
推荐使用 INT8 量化模型 - 适合:
使用 FP32 原始模型 - 仅当:
pip install onnxruntime transformers numpy
import onnxruntime as ort
from transformers import AutoTokenizer
# 加载分词器
tokenizer = AutoTokenizer.from_pretrained("baby2008/nllb-200-distilled-600M-onnx")
# 加载 ONNX 模型
encoder = ort.InferenceSession(
"baby2008/nllb-200-distilled-600M-onnx/onnx/int8/encoder.onnx",
providers=["CPUExecutionProvider"]
)
decoder = ort.InferenceSession(
"baby2008/nllb-200-distilled-600M-onnx/onnx/int8/decoder_with_past.onnx",
providers=["CPUExecutionProvider"]
)
# 翻译示例
text = "Hello, how are you?"
tokenizer.src_lang = "eng_Latn"
inputs = tokenizer(text, return_tensors="np")
# 编码
encoder_outputs = encoder.run(None, {
"input_ids": inputs["input_ids"].astype(np.int64),
"attention_mask": inputs["attention_mask"].astype(np.int64)
})
# 解码(需要实现自回归生成)
# ...
pip install optimum[onnxruntime]
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers import AutoTokenizer, pipeline
model = ORTModelForSeq2SeqLM.from_pretrained(
"baby2008/nllb-200-distilled-600M-onnx",
provider="CPUExecutionProvider"
)
tokenizer = AutoTokenizer.from_pretrained("baby2008/nllb-200-distilled-600M-onnx")
translator = pipeline(
"translation",
model=model,
tokenizer=tokenizer,
src_lang="eng_Latn",
tgt_lang="zho_Hans"
)
result = translator("Hello, world!")
print(result[0]['translation_text'])
测试环境:Intel CPU, ONNX Runtime 1.16.3
| 序列长度 | FP32 | INT8 | 加速比 |
|---|---|---|---|
| 16 tokens | 19.79 ms | 13.58 ms | 1.46x |
| 32 tokens | 34.36 ms | 28.11 ms | 1.22x |
| 64 tokens | 55.49 ms | 47.57 ms | 1.17x |
| 128 tokens | 86.69 ms | 58.33 ms | 1.49x |
NLLB-200 支持 200+ 语言,常用代码:
eng_Latn - Englishzho_Hans - Chinese (Simplified)zho_Hant - Chinese (Traditional)jpn_Jpan - Japanesekor_Hang - Koreanfra_Latn - Frenchdeu_Latn - Germanspa_Latn - Spanishrus_Cyrl - Russianara_Arab - Arabic完整语言列表请参考 NLLB 论文。
MIT License
注意: 此仓库包含已重新组织的模型文件,按精度分类到 fp32/ 和 int8/ 子目录中。