Downloads · 30 days
13
32% of all-time downloads
TigreGotico/m2m100-1.2B-onnx
m2m100-1.2B-onnx is a translation model from TigreGotico. Use it when you need text moved from one language to another. It is set up for optimum. The card lists the license as mit.
ONNX export of facebook/m2m1001.2B, a many-to-many multilingual translation model. It translates directly between any pair of its 100 languages. No English pivot is necessary.
Downloads · 30 days
13
32% of all-time downloads
All-time downloads
41
Public
Repo size
11.6 GB
Likes
0
Public
Click a slice to open those files.
.onnx_data9.3 GB · 80%
From the Hugging Face model README
ONNX export of facebook/m2m100_1.2B, a many-to-many multilingual translation model. It translates directly between any pair of its 100 languages. No English pivot is necessary.
Two precisions are in this repository:
int8/ folder (dynamic quantization of the weights)For a smaller model, see TigreGotico/m2m100-418M-onnx.
optimum-cli export onnx \
--model facebook/m2m100_1.2B \
--task text2text-generation-with-past \
--no-post-process \
m2m100_1.2B_onnx
--no-post-process keeps the decoder graphs separate. It prevents a protobuf
EncodeError on graphs that are larger than 2 GB.
The int8 folder was made with onnxruntime.quantization.quantize_dynamic
(QuantType.QInt8, EnableSubgraph=True).
| Path | Precision | Size |
|---|---|---|
encoder_model.onnx, decoder_model.onnx, decoder_with_past_model.onnx + their .onnx_data files | fp32 | 8.7 GB total |
int8/ (same three graphs, single file each) | int8 | 2.2 GB total |
The fp32 graphs keep their weights in external *.onnx_data files. You must
download those files together with the .onnx files. The graphs do not load without
them. The int8 graphs are each below 2 GB, so they need no external data.
Both folders hold the full SentencePiece tokenizer (sentencepiece.bpe.model,
vocab.json, tokenizer_config.json, special_tokens_map.json, added_tokens.json).
M2M100 is not a prefix-token model. Do these two steps:
tokenizer.src_lang = "en".generate() as
forced_bos_token_id=tokenizer.get_lang_id("pt").If you forget forced_bos_token_id, the model gives unreliable output. Language codes
are plain ISO-639-1 or ISO-639-3 strings such as en, pt, gl, ca, ar, ast.
M2M100 does not include Basque (
eu).tokenizer.lang_code_to_idholds the full list of the 100 supported codes.
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers import AutoTokenizer
repo = "TigreGotico/m2m100-1.2B-onnx"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = ORTModelForSeq2SeqLM.from_pretrained(repo) # fp32
# model = ORTModelForSeq2SeqLM.from_pretrained(repo, subfolder="int8") # int8
tokenizer.src_lang = "en"
inputs = tokenizer("The library opens at nine in the morning.", return_tensors="pt")
ids = model.generate(
**inputs,
forced_bos_token_id=tokenizer.get_lang_id("gl"),
num_beams=4,
max_new_tokens=64,
)
print(tokenizer.batch_decode(ids, skip_special_tokens=True)[0])
# A biblioteca abre ás nove da mañá.
12 sentences over 6 language directions (en→pt, en→gl, en→ca, en→ast, en→ar, pt→en),
num_beams=4, max_new_tokens=64, greedy string comparison against
M2M100ForConditionalGeneration.
| Precision | Exact-match output |
|---|---|
| fp32 | 12/12 (100%) |
| int8 | 8/12 (66.7%) |
Each of the 4 int8 differences is still a correct translation. The differences are word
choice and number formatting, for example surt en 20 minuts against
surt en vint minuts. Use fp32 if you need output that is identical to PyTorch. Use
int8 for a 4x smaller model with translation quality that is very close.
The parity set uses Asturian (
ast) in place of Basque, because M2M100 has no Basque support.
MIT, the same as the original model.