tf-bao commited on
Commit
ea8061c
·
verified ·
1 Parent(s): d996814

Upload Interpreter-Qwen3-1.7B-ReTok (piece tokenizer, SFT->CPO->GRPO)

Browse files
README.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - zh
5
+ - en
6
+ pipeline_tag: translation
7
+ tags:
8
+ - translation
9
+ - zh-en
10
+ - en-zh
11
+ - piece-tokenizer
12
+ - retok
13
+ - sft
14
+ - cpo
15
+ - grpo
16
+ ---
17
+
18
+ # Interpreter-Qwen3-1.7B-ReTok
19
+
20
+ A 1.7B Chinese↔English translation model — the **PieceTokenizer (ReTok) A/B sibling** of
21
+ [`Ismantic/Interpreter-Qwen3-1.7B`](https://huggingface.co/Ismantic/Interpreter-Qwen3-1.7B).
22
+ Same SFT→CPO→GRPO pipeline, same data, same losses and rewards; the only differences are
23
+ the **tokenizer** (a custom SentencePiece-style *piece* tokenizer instead of Qwen3's HF BPE)
24
+ and the base checkpoint (a retokenized "phase-2 v18" piece base).
25
+
26
+ > ⚠️ **This is not a plug-and-play HF model.** The weights are standard, but the tokenizer is
27
+ > a compiled C++ `piece_tokenizer` extension + 5 sidecar files — `AutoTokenizer.from_pretrained`
28
+ > does **not** work. You must load it through the `PieceTokenizerWrapper` from the
29
+ > [Interpreter repo](https://github.com/Ismantic/Interpreter) (`ReTok/lib/`). See **Usage** below.
30
+
31
+ ## Results (WMT23, COMET = `Unbabel/wmt22-comet-da`)
32
+
33
+ | Stage | zh→en BLEU / COMET | en→zh BLEU / COMET |
34
+ |---|---|---|
35
+ | base (5-shot) | 17.44 / 0.7582 | 38.10 / 0.8255 |
36
+ | SFT | 19.34 / 0.7762 | 40.09 / 0.8392 |
37
+ | CPO | 18.11 / 0.7941 | 31.38 / 0.8480 |
38
+ | **GRPO (this model)** | 18.43 / **0.7967** | 31.79 / **0.8511** |
39
+
40
+ COMET climbs monotonically from base → GRPO (+0.039 zh→en, +0.026 en→zh). Compared to the
41
+ HF-BPE sibling `Interpreter-Qwen3-1.7B`, the piece tokenizer costs ≈ −0.016 COMET at SFT but
42
+ the gap shrinks to ≈ −0.003 by GRPO — i.e. **CPO/GRPO recover most of the tokenizer-swap tax.**
43
+
44
+ ## Files
45
+
46
+ Standard weights (`config.json`, `generation_config.json`, `model.safetensors`) plus the 5
47
+ self-contained piece-tokenizer artifacts: `piece.model`, `dict.txt`, `token_mapping.json`,
48
+ `special_tokens_map.json`, `tokenizer_config.json`.
49
+
50
+ ## Usage
51
+
52
+ Requires the compiled `piece_tokenizer` extension and `PieceTokenizerWrapper` from the
53
+ Interpreter repo. Chat format is `<bos><user>{prompt}<assistant>{response}<eos>` (**not** ChatML),
54
+ `</s>` (id 2) is the stop token.
55
+
56
+ ```python
57
+ # 1) get the loader: git clone https://github.com/Ismantic/Interpreter
58
+ # and build/install the piece_tokenizer C++ extension into your venv.
59
+ import sys, torch
60
+ sys.path.insert(0, "Interpreter/ReTok/lib")
61
+ from tokenizer_wrapper import PieceTokenizerWrapper
62
+ from transformers import AutoModelForCausalLM
63
+
64
+ model_dir = "path/to/Interpreter-Qwen3-1.7B-ReTok" # this repo, downloaded
65
+ tok = PieceTokenizerWrapper(model_dir)
66
+ model = AutoModelForCausalLM.from_pretrained(model_dir, torch_dtype=torch.bfloat16).cuda().eval()
67
+
68
+ def translate(text, direction="zh2en"):
69
+ if direction == "zh2en":
70
+ instr = f"Translate the following text from Chinese to English.\nChinese: {text}\nEnglish:"
71
+ else:
72
+ instr = f"Translate the following text from English to Chinese.\nEnglish: {text}\nChinese:"
73
+ ids = tok.apply_chat_template([{"role": "user", "content": instr}],
74
+ tokenize=True, add_generation_prompt=True)
75
+ out = model.generate(torch.tensor([ids]).cuda(), max_new_tokens=256,
76
+ do_sample=False, eos_token_id=tok.eos_token_id)
77
+ return tok.decode(list(out[0][len(ids):]), skip_special_tokens=True).strip()
78
+
79
+ print(translate("人工智能正在深刻改变我们的生活方式。", "zh2en"))
80
+ ```
81
+
82
+ vLLM works with `skip_tokenizer_init=True` + `TokensPrompt(prompt_token_ids=...)` — see
83
+ `ReTok/eval/eval_vllm_piece.py` and `ReTok/RUN_BEST_MODEL.md` in the repo for a batch runner.
84
+
85
+ ## Training
86
+
87
+ - Base: retokenized piece "phase-2 v18_tie" checkpoint (1.7B).
88
+ - SFT: full fine-tune on piece-format translation pairs (ALMA + X-ALMA, ~36.8K).
89
+ - CPO: LoRA preference training (DPO loss + NLL) on ~44K self-generated pairs, then merged.
90
+ - GRPO: full-parameter RL, reward = `wmt22-comet-da` COMET (1.0) + 4-gram repetition penalty (0.3),
91
+ WMT17–21 source prompts. Reward/hyperparams are identical to the Qwen sibling (A/B contract).
92
+
93
+ ## License & attribution
94
+
95
+ Apache-2.0. Derived from the Qwen3-1.7B model family and the ALMA / X-ALMA parallel & preference
96
+ corpora + WMT test sets; respect the upstream licenses. Piece tokenizer built for this project.
config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "dtype": "bfloat16",
9
+ "eos_token_id": 2,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 2048,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 6144,
15
+ "layer_types": [
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention"
44
+ ],
45
+ "max_position_embeddings": 32768,
46
+ "max_window_layers": 28,
47
+ "model_type": "qwen3",
48
+ "num_attention_heads": 16,
49
+ "num_hidden_layers": 28,
50
+ "num_key_value_heads": 8,
51
+ "pad_token_id": 81899,
52
+ "rms_norm_eps": 1e-06,
53
+ "rope_scaling": null,
54
+ "rope_theta": 1000000,
55
+ "sliding_window": null,
56
+ "tie_word_embeddings": true,
57
+ "transformers_version": "4.57.6",
58
+ "use_cache": false,
59
+ "use_sliding_window": false,
60
+ "vocab_size": 81903
61
+ }
dict.txt ADDED
The diff for this file is too large to render. See raw diff
 
generation_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 1,
3
+ "eos_token_id": [
4
+ 2
5
+ ],
6
+ "max_new_tokens": 2048,
7
+ "pad_token_id": 81899,
8
+ "transformers_version": "4.57.6"
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12dd61b56529a494d820eb9048811706ecec94f1019bce07c749f56c37454c78
3
+ size 3154330384
piece.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9b81cefcaa5d47cd3aa6e653dda0a80f90b7863b3cfff790dfc07c662dda50f
3
+ size 2707732
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "unk_token": "<unk>",
5
+ "pad_token": "<pad>"
6
+ }
token_mapping.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "base_vocab_size": 81903,
3
+ "total_vocab_size": 81903,
4
+ "special_tokens": {
5
+ "<pad>": 81899,
6
+ "<user>": 81900,
7
+ "<assistant>": 81901,
8
+ "<system>": 81902
9
+ },
10
+ "bos_id": 1,
11
+ "eos_id": 2,
12
+ "unk_id": 0,
13
+ "pad_id": 81899,
14
+ "user_id": 81900,
15
+ "assistant_id": 81901,
16
+ "system_id": 81902
17
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "qwen3",
3
+ "bos_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "unk_token": "<unk>",
6
+ "pad_token": "<pad>",
7
+ "clean_up_tokenization_spaces": false,
8
+ "tokenizer_class": "PreTrainedTokenizerFast"
9
+ }