--- license: apache-2.0 language: - zh - en pipeline_tag: translation tags: - translation - zh-en - en-zh - piece-tokenizer - retok - sft - cpo - grpo --- # Interpreter-Qwen3-1.7B-ReTok A 1.7B Chinese↔English translation model — the **PieceTokenizer (ReTok) A/B sibling** of [`Ismantic/Interpreter-Qwen3-1.7B`](https://huggingface.co/Ismantic/Interpreter-Qwen3-1.7B). Same SFT→CPO→GRPO pipeline, same data, same losses and rewards; the only differences are the **tokenizer** (a custom SentencePiece-style *piece* tokenizer instead of Qwen3's HF BPE) and the base checkpoint (a retokenized "phase-2 v18" piece base). > ⚠️ **This is not a plug-and-play HF model.** The weights are standard, but the tokenizer is > a compiled C++ `piece_tokenizer` extension + 5 sidecar files — `AutoTokenizer.from_pretrained` > does **not** work. You must load it through the `PieceTokenizerWrapper` from the > [Interpreter repo](https://github.com/Ismantic/Interpreter) (`ReTok/lib/`). See **Usage** below. ## Results (WMT23, COMET = `Unbabel/wmt22-comet-da`) | Stage | zh→en BLEU / COMET | en→zh BLEU / COMET | |---|---|---| | base (5-shot) | 17.44 / 0.7582 | 38.10 / 0.8255 | | SFT | 19.34 / 0.7762 | 40.09 / 0.8392 | | CPO | 18.11 / 0.7941 | 31.38 / 0.8480 | | **GRPO (this model)** | 18.43 / **0.7967** | 31.79 / **0.8511** | COMET climbs monotonically from base → GRPO (+0.039 zh→en, +0.026 en→zh). Compared to the HF-BPE sibling `Interpreter-Qwen3-1.7B`, the piece tokenizer costs ≈ −0.016 COMET at SFT but the gap shrinks to ≈ −0.003 by GRPO — i.e. **CPO/GRPO recover most of the tokenizer-swap tax.** ## Files Standard weights (`config.json`, `generation_config.json`, `model.safetensors`) plus the 5 self-contained piece-tokenizer artifacts: `piece.model`, `dict.txt`, `token_mapping.json`, `special_tokens_map.json`, `tokenizer_config.json`. ## Usage Requires the compiled `piece_tokenizer` extension and `PieceTokenizerWrapper` from the Interpreter repo. Chat format is `{prompt}{response}` (**not** ChatML), `` (id 2) is the stop token. ```python # 1) get the loader: git clone https://github.com/Ismantic/Interpreter # and build/install the piece_tokenizer C++ extension into your venv. import sys, torch sys.path.insert(0, "Interpreter/ReTok/lib") from tokenizer_wrapper import PieceTokenizerWrapper from transformers import AutoModelForCausalLM model_dir = "path/to/Interpreter-Qwen3-1.7B-ReTok" # this repo, downloaded tok = PieceTokenizerWrapper(model_dir) model = AutoModelForCausalLM.from_pretrained(model_dir, torch_dtype=torch.bfloat16).cuda().eval() def translate(text, direction="zh2en"): if direction == "zh2en": instr = f"Translate the following text from Chinese to English.\nChinese: {text}\nEnglish:" else: instr = f"Translate the following text from English to Chinese.\nEnglish: {text}\nChinese:" ids = tok.apply_chat_template([{"role": "user", "content": instr}], tokenize=True, add_generation_prompt=True) out = model.generate(torch.tensor([ids]).cuda(), max_new_tokens=256, do_sample=False, eos_token_id=tok.eos_token_id) return tok.decode(list(out[0][len(ids):]), skip_special_tokens=True).strip() print(translate("人工智能正在深刻改变我们的生活方式。", "zh2en")) ``` vLLM works with `skip_tokenizer_init=True` + `TokensPrompt(prompt_token_ids=...)` — see `ReTok/eval/eval_vllm_piece.py` and `ReTok/RUN_BEST_MODEL.md` in the repo for a batch runner. ## Training - Base: retokenized piece "phase-2 v18_tie" checkpoint (1.7B). - SFT: full fine-tune on piece-format translation pairs (ALMA + X-ALMA, ~36.8K). - CPO: LoRA preference training (DPO loss + NLL) on ~44K self-generated pairs, then merged. - GRPO: full-parameter RL, reward = `wmt22-comet-da` COMET (1.0) + 4-gram repetition penalty (0.3), WMT17–21 source prompts. Reward/hyperparams are identical to the Qwen sibling (A/B contract). ## License & attribution Apache-2.0. Derived from the Qwen3-1.7B model family and the ALMA / X-ALMA parallel & preference corpora + WMT test sets; respect the upstream licenses. Piece tokenizer built for this project.