File size: 2,927 Bytes
793878e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d7a5e0
913d510
2d7a5e0
 
 
793878e
 
 
 
 
 
2d7a5e0
 
793878e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
license: cc-by-4.0
language:
- fr
- ar
pipeline_tag: translation
library_name: transformers.js
base_model: Helsinki-NLP/opus-mt-fr-ar
tags:
- translation
- marian
- opus-mt
- onnx
---

# OptimaMT fr → ar (French to Arabic)

Drop-in copy of an ONNX export of [Helsinki-NLP/opus-mt-fr-ar](https://huggingface.co/Helsinki-NLP/opus-mt-fr-ar) at revision `5469dc759cd9` (same layout as the Xenova exports) with a lighter merged decoder: ONNX Runtime's fast mode (`disable_quant_qdq = 1`, 2.3–2.5× faster) at half the memory. Same weights, same tokens.
Part of [OptimaMT](https://github.com/AmerAlreyahi/OptimaMT): [all 51 pairs](https://huggingface.co/collections/OptimaMT/optimamt-lighter-opus-mt-onnx-models-6af228dc9cd91f015e56e869), named `OptimaMT/<src>-<tgt>`.

**Used in production:**
- [OpenCircle](https://github.com/AmerAlreyahi/OpenCircle), a desktop screen translator for Windows and Linux, ships these models since v0.1.4.

| Memory after load | Linux | Windows | Identical tokens |
|---|---:|---:|---|
| `disable_quant_qdq = 1` | 525 → 281 MiB (-47 %) | 500 → 257 MiB (-49 %) | yes |
| ONNX Runtime defaults | 281 → 220 MiB (-22 %) | 196 → 165 MiB (-16 %) | yes |

FLORES-200 devtest (1,012 sentences): the same translations as the original, BLEU 13.61, chrF 45.82 (greedy).

ONNX Runtime 1.31.1, CPU, 4 threads (Linux; Windows in a VM). Interactive results: [OptimaMT/results](https://huggingface.co/spaces/OptimaMT/results) ·
method: [REPORT.md](https://github.com/AmerAlreyahi/OptimaMT/blob/main/REPORT.md).

## Use

```js
import { pipeline } from "@huggingface/transformers";

const translator = await pipeline("translation", "OptimaMT/fr-ar", {
  dtype: "q8",
  session_options: { extra: { session: { disable_quant_qdq: "1" } } },
});
const [out] = await translator(">>ara<< Le phare se dresse sur la côte.");
console.log(out.translation_text);
```

Python ([translate.py](https://github.com/AmerAlreyahi/OptimaMT/blob/main/scripts/translate.py): onnxruntime, sentencepiece, numpy):

```bash
python translate.py OptimaMT/fr-ar "Le phare se dresse sur la côte." --lang ">>ara<<"
```

Start every input with `>>ara<<` (the target variant). Use transformers.js 3.x: 4.3.2 splits this token, with the original export too.

## Files

`onnx/decoder_model_merged_quantized.onnx` is rebuilt; `tokenizer.json`, `special_tokens_map.json` and `tokenizer_config.json` were written in the Xenova layout; every other file is the original, byte for byte.
Vocabulary: 62,419 tokens.

## Licence and credits

- Weights: [OPUS-MT](https://huggingface.co/Helsinki-NLP/opus-mt-fr-ar) by the University of Helsinki, CC BY 4.0.
- ONNX export: an ONNX export of [Helsinki-NLP/opus-mt-fr-ar](https://huggingface.co/Helsinki-NLP/opus-mt-fr-ar) at revision `5469dc759cd9` (same layout as the Xenova exports).
- Modified: the decoder's output projection was moved out of its two branches (graph change only). CC BY 4.0.