AmerAlreyahi commited on
Commit
6eabef1
·
verified ·
1 Parent(s): 3fcc25d

Add OptimaMT en-zh

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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ language:
4
+ - en
5
+ - zh
6
+ pipeline_tag: translation
7
+ library_name: transformers.js
8
+ base_model: Xenova/opus-mt-en-zh
9
+ tags:
10
+ - translation
11
+ - marian
12
+ - opus-mt
13
+ - onnx
14
+ ---
15
+
16
+ # OptimaMT en → zh (English to Chinese)
17
+
18
+ Drop-in copy of [Xenova/opus-mt-en-zh](https://huggingface.co/Xenova/opus-mt-en-zh) at revision `046f55aec303` with a lighter merged decoder: same weights, same tokens, less memory.
19
+ Part of [OptimaMT](https://github.com/AmerAlreyahi/OptimaMT) (49 pairs, `OptimaMT/<src>-<tgt>`).
20
+
21
+ | Memory after load | Linux | Windows | Identical tokens |
22
+ |---|---:|---:|---|
23
+ | `disable_quant_qdq = 1` | 545 → 291 MiB (-47 %) | 519 → 263 MiB (-49 %) | yes |
24
+ | ONNX Runtime defaults | 291 → 227 MiB (-22 %) | 201 → 173 MiB (-14 %) | yes |
25
+
26
+ ONNX Runtime 1.31.1, CPU, 4 threads (Linux; Windows in a VM). Interactive results: [OptimaMT/results](https://huggingface.co/spaces/OptimaMT/results) ·
27
+ method: [REPORT.md](https://github.com/AmerAlreyahi/OptimaMT/blob/main/REPORT.md).
28
+
29
+ ## Use
30
+
31
+ ```js
32
+ import { pipeline } from "@huggingface/transformers";
33
+
34
+ const translator = await pipeline("translation", "OptimaMT/en-zh", {
35
+ dtype: "q8",
36
+ session_options: { extra: { session: { disable_quant_qdq: "1" } } },
37
+ });
38
+ const [out] = await translator(">>cmn_Hans<< The lighthouse stands on the coast.");
39
+ console.log(out.translation_text);
40
+ ```
41
+
42
+ Python ([translate.py](https://github.com/AmerAlreyahi/OptimaMT/blob/main/scripts/translate.py): onnxruntime, sentencepiece, numpy):
43
+
44
+ ```bash
45
+ python translate.py OptimaMT/en-zh "The lighthouse stands on the coast." --lang ">>cmn_Hans<<"
46
+ ```
47
+
48
+ Start every input with `>>cmn_Hans<<` (the target variant). Use transformers.js 3.x: 4.3.2 splits this token, with the original export too.
49
+
50
+ ## Files
51
+
52
+ Only `onnx/decoder_model_merged_quantized.onnx` is rebuilt; every other file is the original, byte for byte.
53
+ Vocabulary: 65,001 tokens.
54
+
55
+ ## Licence and credits
56
+
57
+ - Weights: [OPUS-MT](https://huggingface.co/Helsinki-NLP/opus-mt-en-zh) by the University of Helsinki, CC BY 4.0.
58
+ - ONNX export: [Xenova/opus-mt-en-zh](https://huggingface.co/Xenova/opus-mt-en-zh) at revision `046f55aec303`.
59
+ - 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-zh",
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:47ab6181e8b241c54dd17c9ec088e122d671c49425627e82bee7080d2de07eba
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:d3b7912bf6a9bd27e4c074c2df91d4ff3d5b4bc5f7f6c8d7cc9c805c98fbafee
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
+ "decoder_model": {
6
+ "op_types": [
7
+ "Slice",
8
+ "Where",
9
+ "Sqrt",
10
+ "Pow",
11
+ "Concat",
12
+ "Add",
13
+ "Equal",
14
+ "Sub",
15
+ "Gather",
16
+ "Mul",
17
+ "Range",
18
+ "Cast",
19
+ "ConstantOfShape",
20
+ "MatMul",
21
+ "ReduceMean",
22
+ "Constant",
23
+ "Expand",
24
+ "Unsqueeze",
25
+ "Sigmoid",
26
+ "Shape",
27
+ "Reshape",
28
+ "Div",
29
+ "Squeeze",
30
+ "Transpose",
31
+ "Softmax",
32
+ "Less"
33
+ ],
34
+ "weight_type": "QInt8"
35
+ },
36
+ "encoder_model": {
37
+ "op_types": [
38
+ "Where",
39
+ "Sqrt",
40
+ "Pow",
41
+ "Concat",
42
+ "Add",
43
+ "Equal",
44
+ "Sub",
45
+ "Gather",
46
+ "Mul",
47
+ "Range",
48
+ "Cast",
49
+ "ConstantOfShape",
50
+ "ReduceMean",
51
+ "MatMul",
52
+ "Constant",
53
+ "Expand",
54
+ "Unsqueeze",
55
+ "Sigmoid",
56
+ "Shape",
57
+ "Reshape",
58
+ "Div",
59
+ "Transpose",
60
+ "Softmax"
61
+ ],
62
+ "weight_type": "QInt8"
63
+ },
64
+ "decoder_model_merged": {
65
+ "op_types": [
66
+ "Slice",
67
+ "Where",
68
+ "Sqrt",
69
+ "Pow",
70
+ "Concat",
71
+ "Add",
72
+ "Equal",
73
+ "Sub",
74
+ "Gather",
75
+ "Mul",
76
+ "Range",
77
+ "Cast",
78
+ "ConstantOfShape",
79
+ "If",
80
+ "MatMul",
81
+ "ReduceMean",
82
+ "Constant",
83
+ "Expand",
84
+ "Unsqueeze",
85
+ "Sigmoid",
86
+ "Shape",
87
+ "Reshape",
88
+ "Div",
89
+ "Squeeze",
90
+ "Transpose",
91
+ "Softmax",
92
+ "Less"
93
+ ],
94
+ "weight_type": "QInt8"
95
+ },
96
+ "decoder_with_past_model": {
97
+ "op_types": [
98
+ "Where",
99
+ "Sqrt",
100
+ "Pow",
101
+ "Concat",
102
+ "Add",
103
+ "Equal",
104
+ "Sub",
105
+ "Gather",
106
+ "Mul",
107
+ "Range",
108
+ "Cast",
109
+ "ConstantOfShape",
110
+ "ReduceMean",
111
+ "MatMul",
112
+ "Constant",
113
+ "Expand",
114
+ "Unsqueeze",
115
+ "Sigmoid",
116
+ "Shape",
117
+ "Reshape",
118
+ "Div",
119
+ "Transpose",
120
+ "Softmax"
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:5775ddc9e3ff2fae91554da56468ad35ff56edaba870fea74447bc7234bfdaa8
3
+ size 806435
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:81dc94efa84e4025ef38d25d5d07429fe41e3eb29d44003f1db6fe98487b0052
3
+ size 804600
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": "eng",
8
+ "sp_model_kwargs": {},
9
+ "target_lang": "zho",
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