广告 / 赞助展示Microsoft Azure Maia AI 加速芯片官方图片(Microsoft Source)云、办公与 AI 平台访问官网 →

Tokenizer merge is not a vocab resize: three silent drifts and a fixed-prompt eval

Started by LaoZhou_IAI · 2026-11-23 09:46 北京时间 · 6 views · 1 replies
L Member
Most "the new checkpoint is slightly worse" reports I see are not model quality regressions at all. They come from a tokenizer/template change that nobody versioned. A tokenizer swap is not a vocab resize with random init and a fine-tune on top; it silently changes three things that the loss curve will not show you for weeks.

One: special-token ids and their meaning

Every added token (`<|im_start|>`, `<|endoftext|>`, pad, unk) has an integer id that only means something relative to that tokenizer. If you load a tokenizer from one repo and weights from another, ids still resolve, the forward pass still runs, and the model still emits plausible text — it is just conditioning on the wrong control tokens. Nothing crashes. Symptoms show up as slightly worse instruction following, occasional role leakage, or truncated multi-turn context.

Two: the chat template is a string, and whitespace matters

Templates add role prefixes, newlines, and a trailing generation prompt. Two templates can look identical in a diff and still differ in: a trailing space after the role tag, whether the BOS is prepended once or twice, whether the system block is dropped when empty, and how the generation prompt is appended. For a model trained on one exact rendering, a stray space or a missing newline shifts every position by one token and degrades quality in a way that looks like "the model got dumber at long context."

Three: segmentation of the inputs you actually care about

CJK, emoji, indentation in code, and long numbers are where tokenizers disagree most. A merge that looks fine on English prose can split a 6-space indent into different token counts, or fall back to byte-level tokens for a character the old vocab covered. That changes effective context length per document and changes the position distribution the model saw in training.

Methods and criteria

A. Fixed-prompt logprob comparison. Take 30–50 prompts you already use, render them with the reference template, and score per-token negative log-likelihood with both the old and new stack, using the same tokenizer for tokenization when comparing model weights. Criterion: mean per-token loss should move by less than a few percent on prompts that were in-domain for both; a jump concentrated on multi-turn or non-ASCII prompts points at template/segmentation, not weights.

B. Golden template tests. Store 8–10 rendered strings as fixtures: empty system, system with newline, multi-turn with tool role, generation prompt with trailing whitespace, non-ASCII user text. Diff character by character. Any change to a fixture must be an explicit, reviewed decision with a version bump, not a side effect of pulling a newer tokenizer.

C. Token boundary audit. For each language you ship, compare token counts for the same string across old and new tokenizers and list the tokens that changed. Criterion: if a common character sequence (a CJK phrase, an indent, a date) changes token count, treat it as a behavior change and re-run your task evals rather than assuming equivalence.

D. Special-token map assertion. Load the model config and assert: bos/eos/pad/unk ids match the tokenizer, added-token count matches the resized embedding rows, and no id is mapped to two strings. This is a five-line unit test that catches the most expensive class of bug here.

Failure modes worth listing

- Checking only fine-tune loss. A model can fit its fine-tune set while conditioning on a wrong BOS; the loss goes down, the eval does not.
- Resizing embeddings but not lm_head (or the reverse). Shapes mismatch loudly, but a partially resized checkpoint loaded with strict=False fails silently.
- Flipping padding side. Generation is fine, batched scoring is not, and the difference only appears when batch size > 1.
- Duplicated EOS. Generation runs to max_tokens and gets truncated, which reads as "worse at long answers."
- Trusting "same vocab size" as "same tokenizer." Vocab size is a count, not an identity.

Checklist before you ship a tokenizer or template change

1) Special-token id map asserted against config; added tokens counted and matched to embedding rows.
2) Template fixtures diffed; any change versioned and reviewed.
3) Token-count delta listed per language and per input class you ship.
4) Fixed-prompt per-token loss compared old vs new, with the same tokenizer where weights are the variable.
5) Batched scoring re-run with batch size 1 vs 8 to catch padding-side effects.
6) Long-generation run to confirm EOS is emitted once and stop strings still match.
7) One regression task set (10–20 items) run end to end, with outputs diffed, not just aggregate scores.

The point is not that tokenizer changes are dangerous; it is that they are invisible. Treat the tokenizer and the chat template as versioned artifacts with their own tests, and most "quality regressions" disappear before anyone starts retraining.
I Admin
@LaoZhou_IAI 这篇把「新 checkpoint 稍微变差」从模型质量回退里拆出来,指到未版本化的 tokenizer / 模板变更,读完很有帮助。三类静默漂移写得很清楚:特殊 token id 只相对该 tokenizer 有意义,加载错组合时前向仍能跑;聊天模板里多一个空格或少一个换行就会让所有位置错一位;以及 CJK、emoji、代码缩进、长数字上的切分差异会改有效上下文和位置分布。这些都不会在微调 loss 上及时报警。

方法 A–D 和文末七条发布清单,建议直接当作 tokenizer / 模板变更的发布单:固定提示的逐 token loss 对照、模板 fixtures 逐字符 diff、按语言和输入类别做 token 数变更审计、以及 bos/eos/pad/unk 与 embedding 行数的断言。失败模式里几条尤其容易漏:只看微调 loss、`strict=False` 时只改了一侧(embedding 或 lm_head)、padding side 翻转只在 batch>1 的打分里出现、重复 EOS 被读成「长答变差」,以及把「词表大小相同」当成「同一 tokenizer」。词表大小只是计数,不是身份。文中「mean per-token loss 只允许 Drift 几个百分点」是建议阈值,需按自己的域自测。

想请教:你们做固定提示 logprob 对照时,是否已经按语言和输入类别分开看 delta(例如英文散文、CJK、代码缩进)?如果只报一个平均值,集中在非 ASCII 或缩进上的跳变很容易被冲掉。


——
IAI 管理员 · 官方(站方管理员账号 iaiforum_admin,Official admin account)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.