Downloads · 30 days
11
22% of all-time downloads
TigreGotico/m2m100-418M-smugri-onnx
m2m100-418M-smugri-onnx is a translation model from TigreGotico. Use it when you need text moved from one language to another. It is set up for transformers.js. The card lists the license as mit.
ONNX export (fp32 + dynamic int8) of tartuNLP/m2m100418Msmugri, a fine-tune of Facebook's m2m100-418M for Finno-Ugric / Uralic minority languages: Livonian (liv), Võro (vro), North Sami (sme), South Sami (sma), plus E…
Downloads · 30 days
11
22% of all-time downloads
All-time downloads
49
Public
Repo size
6 GB
Likes
0
Public
Click a slice to open those files.
.onnx6 GB · 100%
From the Hugging Face model README
ONNX export (fp32 + dynamic int8) of
tartuNLP/m2m100_418M_smugri,
a fine-tune of Facebook's m2m100-418M for Finno-Ugric / Uralic minority
languages: Livonian (liv), Võro (vro), North Sami (sme), South
Sami (sma), plus Estonian, Finnish, Latvian and English.
Livonian has fewer than 20 remaining native speakers and essentially no other machine translation coverage. This model, produced by TartuNLP (University of Tartu), is one of the few MT systems that touches it at all.
All credit for the underlying model and training data goes to TartuNLP /
University of Tartu. This repository only adds an ONNX export for
CPU/edge/offline inference (e.g. via optimum.onnxruntime or
transformers.js); no model weights were retrained.
encoder_model.onnx fp32 encoder
decoder_model.onnx fp32 decoder (no past)
decoder_with_past_model.onnx fp32 decoder (with KV cache)
int8/encoder_model.onnx dynamic-int8 encoder
int8/decoder_model.onnx dynamic-int8 decoder (no past)
int8/decoder_with_past_model.onnx dynamic-int8 decoder (with KV cache)
sentencepiece.bpe.model, vocab.json, tokenizer_config.json,
special_tokens_map.json, added_tokens.json tokenizer files
config.json, generation_config.json
No external-data (*.onnx.data) files were produced — all three ONNX graphs
are individually under the 2GB protobuf inline-data limit at this model size.
Exported with:
optimum-cli export onnx --model tartuNLP/m2m100_418M_smugri \
--task text2text-generation-with-past --no-post-process m2m100-smugri-onnx
(--no-post-process is required — optimum's decoder-merge step is
memory-hungry and was skipped; the three ONNX graphs are loaded separately,
which optimum.onnxruntime.ORTModelForSeq2SeqLM handles natively.)
int8 quantization: dynamic quantization (AutoQuantizationConfig.avx2,
per-tensor, not per-channel) applied independently to each of the three
graphs via optimum.onnxruntime.ORTQuantizer.
This model does not use the stock m2m100 language list. The tokenizer's
hard-coded language table only knows the ~100 original m2m100 languages; four
extra language tokens were added on top of that for the fine-tune:
__liv__, __vro__, __sma__, __sme__. Loading the tokenizer with plain
AutoTokenizer.from_pretrained will not know about these four extra
codes and tokenizer.get_lang_id("liv") / tokenizer.src_lang = "liv" will
raise or silently misbehave unless you patch the tokenizer's lookup tables
first, exactly as documented on the source model card:
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM
MID_FOR_TOKENIZER = "tartuNLP/m2m100_418M_smugri" # tokenizer only, weights come from this repo
tokenizer = AutoTokenizer.from_pretrained(MID_FOR_TOKENIZER)
# Fix the language code tables -- REQUIRED, do this before using the tokenizer
tokenizer.id_to_lang_token = dict(list(tokenizer.id_to_lang_token.items()) + list(tokenizer.added_tokens_decoder.items()))
tokenizer.lang_token_to_id = dict(list(tokenizer.lang_token_to_id.items()) + list(tokenizer.added_tokens_encoder.items()))
tokenizer.lang_code_to_token = {k.replace("_", ""): k for k in tokenizer.additional_special_tokens}
tokenizer.lang_code_to_id = {k.replace("_", ""): v for k, v in tokenizer.lang_token_to_id.items()}
model = ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/m2m100-418M-smugri-onnx")
tokenizer.src_lang = "liv"
enc = tokenizer("Līvõ kēļ jelāb!", return_tensors="pt")
out = model.generate(**enc, forced_bos_token_id=tokenizer.lang_code_to_id["sme"], num_beams=4, max_new_tokens=64)
print(tokenizer.batch_decode(out, skip_special_tokens=True))
Supported / trained language codes (verified by inspecting
tokenizer.additional_special_tokens and the model card of the source
model — only these directions were actually fine-tuned, even though the
tokenizer vocabulary contains the full ~100-language m2m100 token set):
| Code | Language |
|---|---|
liv | Livonian (added token, non-standard) |
vro | Võro (added token, non-standard) |
sme | North Sami (added token, non-standard) |
sma | South Sami (added token, non-standard) |
et | Estonian (standard m2m100 code) |
fi | Finnish (standard m2m100 code) |
lv | Latvian (standard m2m100 code) |
en | English (standard m2m100 code) |
Using the wrong code (e.g. forgetting the tokenizer patch, or using an
unrelated ISO code the base m2m100 vocabulary happens to also define) does
not raise an error — it silently forces generation toward the wrong
target language. Always apply the patch above and always select the target
language via tokenizer.lang_code_to_id[<one of the 8 codes above>], not by
guessing a raw token id.
Seto is not a separate token in this model; text in Seto will most likely
need to go through the vro code (Võro and Seto are closely related South
Estonian varieties) — this was not separately verified with native Seto
sentences.
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM
REPO = "TigreGotico/m2m100-418M-smugri-onnx"
tokenizer = AutoTokenizer.from_pretrained("tartuNLP/m2m100_418M_smugri")
tokenizer.id_to_lang_token = dict(list(tokenizer.id_to_lang_token.items()) + list(tokenizer.added_tokens_decoder.items()))
tokenizer.lang_token_to_id = dict(list(tokenizer.lang_token_to_id.items()) + list(tokenizer.added_tokens_encoder.items()))
tokenizer.lang_code_to_token = {k.replace("_", ""): k for k in tokenizer.additional_special_tokens}
tokenizer.lang_code_to_id = {k.replace("_", ""): v for k, v in tokenizer.lang_token_to_id.items()}
# fp32
model = ORTModelForSeq2SeqLM.from_pretrained(REPO)
# int8
model_int8 = ORTModelForSeq2SeqLM.from_pretrained(
REPO, subfolder="int8",
encoder_file_name="encoder_model.onnx",
decoder_file_name="decoder_model.onnx",
decoder_with_past_file_name="decoder_with_past_model.onnx",
)
tokenizer.src_lang = "liv"
enc = tokenizer("Līvõ kēļ jelāb!", return_tensors="pt")
out = model.generate(**enc, forced_bos_token_id=tokenizer.lang_code_to_id["sme"], num_beams=4, max_new_tokens=64)
print(tokenizer.batch_decode(out, skip_special_tokens=True))
Compared against the original PyTorch model (AutoModelForSeq2SeqLM), exact
string match after decoding:
Observed low-resource output samples (fp32, exact match with the original PyTorch model in all cases below):
| Direction | Input | Output |
|---|---|---|
| liv -> sme | Līvõ kēļ jelāb! | iļļõ jïjnjh! |
| vro -> et | Tere, ku sa käut? | Tere, kui sina käid? |
| en -> vro | Good morning, how are you? | garbled/degenerate output — this direction is not reliable in the base model |
The en -> vro direction produces degenerate repeated-token output in both
the original PyTorch model and this ONNX export (verified identical), i.e.
this is a known limitation of the base checkpoint, not an artifact of the
ONNX conversion.
Re-downloaded and reloaded from a cleared local HF cache after upload;
ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/m2m100-418M-smugri-onnx")
loads and generates correctly, matching the pre-upload fp32 outputs above.
tartuNLP/m2m100_418M_smugrim2m100-418M