AmerAlreyahi commited on
Commit
bbbabe8
·
verified ·
1 Parent(s): 27afb47

Add OptimaMT en-pt

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ source.spm filter=lfs diff=lfs merge=lfs -text
37
+ target.spm filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language:
4
+ - en
5
+ - pt
6
+ pipeline_tag: translation
7
+ library_name: transformers.js
8
+ base_model: Xenova/opus-mt-en-ROMANCE
9
+ tags:
10
+ - translation
11
+ - marian
12
+ - opus-mt
13
+ - onnx
14
+ ---
15
+
16
+ # OptimaMT en → pt (English to Portuguese)
17
+
18
+ Drop-in copy of [Xenova/opus-mt-en-ROMANCE](https://huggingface.co/Xenova/opus-mt-en-ROMANCE) at revision `9d2ba69ac80c` 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.
19
+ 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>`.
20
+
21
+ **Used in production:**
22
+ - [OpenCircle](https://github.com/AmerAlreyahi/OpenCircle), a desktop screen translator for Windows and Linux, ships these models since v0.1.4.
23
+
24
+ | Memory after load | Linux | Identical tokens |
25
+ |---|---:|---|
26
+ | `disable_quant_qdq = 1` | 542 → 289 MiB (-47 %) | yes |
27
+ | ONNX Runtime defaults | 291 → 225 MiB (-22 %) | yes |
28
+
29
+ FLORES-200 devtest (1,012 sentences): the same translations as the original, BLEU 41.73, chrF 66.59 (greedy).
30
+
31
+ ONNX Runtime 1.31.1, CPU, 4 threads (Linux only, not yet measured on Windows). Interactive results: [OptimaMT/results](https://huggingface.co/spaces/OptimaMT/results) ·
32
+ method: [REPORT.md](https://github.com/AmerAlreyahi/OptimaMT/blob/main/REPORT.md).
33
+
34
+ ## Use
35
+
36
+ ```js
37
+ import { pipeline } from "@huggingface/transformers";
38
+
39
+ const translator = await pipeline("translation", "OptimaMT/en-pt", {
40
+ dtype: "q8",
41
+ session_options: { extra: { session: { disable_quant_qdq: "1" } } },
42
+ });
43
+ const [out] = await translator(">>pt_br<< The lighthouse stands on the coast.");
44
+ console.log(out.translation_text);
45
+ ```
46
+
47
+ Python ([translate.py](https://github.com/AmerAlreyahi/OptimaMT/blob/main/scripts/translate.py): onnxruntime, sentencepiece, numpy):
48
+
49
+ ```bash
50
+ python translate.py OptimaMT/en-pt "The lighthouse stands on the coast." --lang ">>pt_br<<"
51
+ ```
52
+
53
+ Start every input with `>>pt_br<<` (the target variant). Use transformers.js 3.x: 4.3.2 splits this token, with the original export too.
54
+
55
+ ## Files
56
+
57
+ Only `onnx/decoder_model_merged_quantized.onnx` is rebuilt; every other file is the original, byte for byte.
58
+ Vocabulary: 65,001 tokens.
59
+
60
+ ## Licence and credits
61
+
62
+ - Weights: [OPUS-MT](https://huggingface.co/Helsinki-NLP/opus-mt-en-ROMANCE) by the University of Helsinki, CC BY 4.0.
63
+ - ONNX export: [Xenova/opus-mt-en-ROMANCE](https://huggingface.co/Xenova/opus-mt-en-ROMANCE) at revision `9d2ba69ac80c`.
64
+ - Modified: the decoder's output projection was moved out of its two branches (graph change only). CC BY 4.0.
config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Helsinki-NLP/opus-mt-en-ROMANCE",
3
+ "activation_dropout": 0.0,
4
+ "activation_function": "swish",
5
+ "add_bias_logits": false,
6
+ "add_final_layer_norm": false,
7
+ "architectures": [
8
+ "MarianMTModel"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "bad_words_ids": [
12
+ [
13
+ 65000
14
+ ]
15
+ ],
16
+ "bos_token_id": 0,
17
+ "classif_dropout": 0.0,
18
+ "classifier_dropout": 0.0,
19
+ "d_model": 512,
20
+ "decoder_attention_heads": 8,
21
+ "decoder_ffn_dim": 2048,
22
+ "decoder_layerdrop": 0.0,
23
+ "decoder_layers": 6,
24
+ "decoder_start_token_id": 65000,
25
+ "decoder_vocab_size": 65001,
26
+ "do_blenderbot_90_layernorm": false,
27
+ "dropout": 0.1,
28
+ "encoder_attention_heads": 8,
29
+ "encoder_ffn_dim": 2048,
30
+ "encoder_layerdrop": 0.0,
31
+ "encoder_layers": 6,
32
+ "eos_token_id": 0,
33
+ "extra_pos_embeddings": 0,
34
+ "force_bos_token_to_be_generated": false,
35
+ "forced_eos_token_id": 0,
36
+ "gradient_checkpointing": false,
37
+ "id2label": {
38
+ "0": "LABEL_0",
39
+ "1": "LABEL_1",
40
+ "2": "LABEL_2"
41
+ },
42
+ "init_std": 0.02,
43
+ "is_encoder_decoder": true,
44
+ "label2id": {
45
+ "LABEL_0": 0,
46
+ "LABEL_1": 1,
47
+ "LABEL_2": 2
48
+ },
49
+ "max_length": 512,
50
+ "max_position_embeddings": 512,
51
+ "model_type": "marian",
52
+ "normalize_before": false,
53
+ "normalize_embedding": false,
54
+ "num_beams": 4,
55
+ "num_hidden_layers": 6,
56
+ "pad_token_id": 65000,
57
+ "scale_embedding": true,
58
+ "share_encoder_decoder_embeddings": true,
59
+ "static_position_embeddings": true,
60
+ "transformers_version": "4.34.0.dev0",
61
+ "use_cache": true,
62
+ "vocab_size": 65001
63
+ }
generation_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bad_words_ids": [
3
+ [
4
+ 65000
5
+ ]
6
+ ],
7
+ "bos_token_id": 0,
8
+ "decoder_start_token_id": 65000,
9
+ "eos_token_id": 0,
10
+ "forced_eos_token_id": 0,
11
+ "max_length": 512,
12
+ "num_beams": 4,
13
+ "pad_token_id": 65000,
14
+ "renormalize_logits": true,
15
+ "transformers_version": "4.34.0.dev0"
16
+ }
onnx/decoder_model_merged_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ffccf13013399c33978b08b0cde841be23705e45e7e9a203a318e4aeb1377f0
3
+ size 60212472
onnx/encoder_model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4ddfd9338ba3d7c6b9c2d1410ed94fb7e06741226918cef6148031101bbd019
3
+ size 52899742
quantize_config.json ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "per_channel": true,
3
+ "reduce_range": true,
4
+ "per_model_config": {
5
+ "encoder_model": {
6
+ "op_types": [
7
+ "Add",
8
+ "Constant",
9
+ "Gather",
10
+ "Cast",
11
+ "Pow",
12
+ "Unsqueeze",
13
+ "Transpose",
14
+ "MatMul",
15
+ "Where",
16
+ "Div",
17
+ "Softmax",
18
+ "Expand",
19
+ "ReduceMean",
20
+ "Sqrt",
21
+ "Equal",
22
+ "Shape",
23
+ "Range",
24
+ "Reshape",
25
+ "Mul",
26
+ "Sub",
27
+ "ConstantOfShape",
28
+ "Sigmoid",
29
+ "Concat"
30
+ ],
31
+ "weight_type": "QInt8"
32
+ },
33
+ "decoder_with_past_model": {
34
+ "op_types": [
35
+ "Add",
36
+ "Constant",
37
+ "Gather",
38
+ "Cast",
39
+ "Pow",
40
+ "Unsqueeze",
41
+ "Transpose",
42
+ "MatMul",
43
+ "Where",
44
+ "Div",
45
+ "Softmax",
46
+ "Expand",
47
+ "ReduceMean",
48
+ "Sqrt",
49
+ "Equal",
50
+ "Shape",
51
+ "Range",
52
+ "Reshape",
53
+ "Mul",
54
+ "Sub",
55
+ "ConstantOfShape",
56
+ "Sigmoid",
57
+ "Concat"
58
+ ],
59
+ "weight_type": "QInt8"
60
+ },
61
+ "decoder_model_merged": {
62
+ "op_types": [
63
+ "Add",
64
+ "Constant",
65
+ "Gather",
66
+ "Cast",
67
+ "Pow",
68
+ "Unsqueeze",
69
+ "Transpose",
70
+ "MatMul",
71
+ "Where",
72
+ "Div",
73
+ "Softmax",
74
+ "Expand",
75
+ "If",
76
+ "ReduceMean",
77
+ "Slice",
78
+ "Sqrt",
79
+ "Equal",
80
+ "Less",
81
+ "Shape",
82
+ "Range",
83
+ "Reshape",
84
+ "Mul",
85
+ "Sub",
86
+ "ConstantOfShape",
87
+ "Sigmoid",
88
+ "Squeeze",
89
+ "Concat"
90
+ ],
91
+ "weight_type": "QInt8"
92
+ },
93
+ "decoder_model": {
94
+ "op_types": [
95
+ "Add",
96
+ "Constant",
97
+ "Gather",
98
+ "Cast",
99
+ "Pow",
100
+ "Unsqueeze",
101
+ "Transpose",
102
+ "MatMul",
103
+ "Where",
104
+ "Div",
105
+ "Softmax",
106
+ "Expand",
107
+ "ReduceMean",
108
+ "Slice",
109
+ "Sqrt",
110
+ "Equal",
111
+ "Less",
112
+ "Shape",
113
+ "Range",
114
+ "Reshape",
115
+ "Mul",
116
+ "Sub",
117
+ "ConstantOfShape",
118
+ "Sigmoid",
119
+ "Squeeze",
120
+ "Concat"
121
+ ],
122
+ "weight_type": "QInt8"
123
+ }
124
+ }
125
+ }
source.spm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1f89e7b05828846baf19109a61029a36838f1c4f3defc218e6aee0ee2787864
3
+ size 779155
special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "eos_token": "</s>",
3
+ "pad_token": "<pad>",
4
+ "unk_token": "<unk>"
5
+ }
target.spm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e54632fe5ce5ef4108a827daccc121b7cd4ea589fbb4bd856b8dd06086166b2
3
+ size 799001
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "eos_token": "</s>",
4
+ "model_max_length": 512,
5
+ "pad_token": "<pad>",
6
+ "separate_vocabs": false,
7
+ "source_lang": "en",
8
+ "sp_model_kwargs": {},
9
+ "target_lang": "fr+fr_BE+fr_CA+fr_FR+wa+frp+oc+ca+rm+lld+fur+lij+lmo+es+es_AR+es_CL+es_CO+es_CR+es_DO+es_EC+es_ES+es_GT+es_HN+es_MX+es_NI+es_PA+es_PE+es_PR+es_SV+es_UY+es_VE+pt+pt_br+pt_BR+pt_PT+gl+lad+an+mwl+it+it_IT+co+nap+scn+vec+sc+ro+la",
10
+ "tokenizer_class": "MarianTokenizer",
11
+ "unk_token": "<unk>"
12
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff