baby2008/nllb-200-distilled-600M-onnx
046
NLLB-200 Distilled 600M ONNX
NLLB-200 (No Language Left Behind) 翻译模型的 ONNX 格式版本,支持 200+ 语言互译。
模型特点
- ✅ ONNX 格式 - 跨平台部署
- ✅ FP32 + INT8 - 提供原始和量化版本
- ✅ CPU 优化 - INT8 量化提升 30% 速度
- ✅ 内存优化 - 量化版本减少 74% 内存占用
目录结构
.
├── 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)模型对比
使用建议
推荐使用 INT8 量化模型 - 适合:
- 生产部署
- 实时应用
- 内存受限环境
- CPU 推理
使用 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)
})
# 解码(需要实现自回归生成)
# ...方法二:使用 Optimum
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'])性能基准 (CPU)
测试环境:Intel CPU, ONNX Runtime 1.16.3
支持的语言
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 论文。
模型信息
- Base Model: facebook/nllb-200-distilled-600M
- Framework: ONNX
- Quantization: INT8 动态量化
- Model Type: Encoder-Decoder (M2M100)
- Vocabulary Size: 256206
- Hidden Size: 1024
- Encoder Layers: 12
- Decoder Layers: 12
- Attention Heads: 16
许可证
MIT License
参考资料
注意: 此仓库包含已重新组织的模型文件,按精度分类到 fp32/ 和 int8/ 子目录中。
