Views
No views yet
int8/ folder (dynamic quantization of the weights)1optimum-cli export onnx \
2 --model facebook/m2m100_1.2B \
3 --task text2text-generation-with-past \
4 --no-post-process \
5 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.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 |
*.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.sentencepiece.bpe.model,
vocab.json, tokenizer_config.json, special_tokens_map.json, added_tokens.json).tokenizer.src_lang = "en".generate() as
forced_bos_token_id=tokenizer.get_lang_id("pt").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.
1from optimum.onnxruntime import ORTModelForSeq2SeqLM
2from transformers import AutoTokenizer
3
4repo = "TigreGotico/m2m100-1.2B-onnx"
5tokenizer = AutoTokenizer.from_pretrained(repo)
6model = ORTModelForSeq2SeqLM.from_pretrained(repo) # fp32
7# model = ORTModelForSeq2SeqLM.from_pretrained(repo, subfolder="int8") # int8
8
9tokenizer.src_lang = "en"
10inputs = tokenizer("The library opens at nine in the morning.", return_tensors="pt")
11ids = model.generate(
12 **inputs,
13 forced_bos_token_id=tokenizer.get_lang_id("gl"),
14 num_beams=4,
15 max_new_tokens=64,
16)
17print(tokenizer.batch_decode(ids, skip_special_tokens=True)[0])
18# A biblioteca abre ás nove da mañá.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%) |
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.