NLLB Russian–Tuvan v3 — MLX (4-bit)
MLX port of Agisight/nllb-rus-tyv-v3-dict_16.5k, a Russian ↔ Tuvan translation model fine-tuned from Meta's NLLB-200-distilled-600M with a vocabulary pruned to 16.5K tokens. Runs fully offline on Apple Silicon (Mac, iPhone, iPad) via MLX.
mlx-lm does not support encoder-decoder models, so the M2M100 architecture is
re-implemented in nllb_mlx.py (included), with a KV cache for fast greedy decoding.
The float32 port reproduces the PyTorch model exactly: 100/100 identical translations on a
spot check and identical chrF++/BLEU on the full clean test set.
Results
Clean test set: held-out test split of Agisight/tyv-rus-200k used for NLLB v3
(shuffle(seed=42), pairs 2000–4000), with pairs whose Tuvan or Russian side also appears
in training removed — 1,369 pairs. Greedy decoding, same preprocessing as NLLB v3 training.
Latency: median over 30 random test sentences per direction, one sentence at a time,
MacBook Air M4 (16 GB).
| Variant | Size | chrF++ ru→tyv | chrF++ tyv→ru | BLEU ru→tyv | BLEU tyv→ru | Latency ru→tyv | Latency tyv→ru | Peak memory |
|---|---|---|---|---|---|---|---|---|
| float32 (exact) | 1413 MB | 49.2 | 49.1 | 19.8 | 23.5 | 0.19 s | 0.12 s | 1491 MB |
| 8-bit | 400 MB | 49.3 | 48.8 | 19.9 | 23.4 | 0.07 s | 0.06 s | 596 MB |
| 4-bit | 224 MB | 48.5 | 48.1 | 19.3 | 22.2 | 0.05 s | 0.03 s | 420 MB |
This repository: 4-bit. 8-bit is lossless versus float32 and ~3× faster; 4-bit loses ~1 chrF++.
Usage
pip install mlx transformers sentencepiece huggingface_hub
import sys
from huggingface_hub import snapshot_download
from transformers import AutoTokenizer
path = snapshot_download("Agisight/nllb-rus-tyv-v3-mlx-q4")
sys.path.insert(0, path)
from nllb_mlx import generate, load_model
tok = AutoTokenizer.from_pretrained(path)
model = load_model(path)
def translate(text, src="rus_Cyrl", tgt="tyv_Cyrl"):
tok.src_lang = src
enc = tok([text], return_tensors="np")
out = generate(model, enc["input_ids"].astype("int32"), enc["attention_mask"].astype("int32"),
tok.convert_tokens_to_ids(tgt), tok.eos_token_id, max_new_tokens=128)
return tok.batch_decode(out, skip_special_tokens=True)[0]
print(translate("Завтра я поеду в Кызыл к родителям."))
print(translate("Экии!", src="tyv_Cyrl", tgt="rus_Cyrl"))
For best quality, apply the same text normalization as in training (Moses punctuation
normalization + NFKC); see preproc() in the evaluation script of the project.
Code
Conversion, evaluation, and benchmarking scripts: Agisight/tyv-translation-mlx.
Credits
- Base model: Meta AI, NLLB-200 (CC-BY-NC-4.0).
- Fine-tuning pipeline adapted from David Dale's NLLB fine-tuning code, with his consultation.
- Fine-tuning, vocabulary pruning, MLX port: Ali Kuzhuget.