Embeddings and the output head are indexed by token ID, so a tokenizer swap scrambles inputs. You need embedding surgery plus an adaptation phase, and pre- and post-swap losses are not comparable.
Imagine a library where every book is stored by a slip number. You spent a year teaching a student which slip number leads to which book. Then management renumbers the entire library. Slip number 47 used to mean a physics textbook; now it might mean a cookbook. If the student opens a slip without re-learning the new numbers, they walk into the wrong room. You cannot just hand them a new directory and expect them to keep studying; you have to relearn the mapping, and even after that, asking how many slips per minute they read does not compare across the two systems, because the slip counts work differently.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The right answer to this question requires precision about which parts of a transformer are vocabulary-dependent and which are not. The middle of the model, the attention and feedforward stack, operates on continuous vectors and does not know or care which token IDs produced those vectors. The two ends of the model, the input embedding and the output projection, are lookup tables indexed by token ID. A tokenizer swap breaks the ends without touching the middle.
This deep dive walks the structural argument, the three-stage migration plan, the role of embedding initialization for new tokens, why an adaptation phase with a re-warmed learning rate is mandatory, and why pre-swap and post-swap loss curves cannot be compared directly. The takeaway: a tokenizer swap is a structural migration, almost never worth doing mid-run, and best deferred to a model-version boundary.
Which layers are vocabulary-dependent
Two layers depend directly on the token ID space: the input embedding matrix and the output projection. The input embedding has shape (V, d_model): row i is the learned vector for token ID i. The output projection has shape (d_model, V) and produces a logit per token ID, often with weights tied to the input embedding.
Everything between these two layers is vocabulary-agnostic. The attention layers receive d_model-dimensional vectors and produce d_model-dimensional vectors. The feedforward layers do the same. None of these middle layers care which token ID produced a given input vector; they only care about the vector's content.
This structural fact is what tempts the wrong intuition. Engineers see that the bulk of the parameters live in the middle, observe that the middle is token-agnostic, and conclude that the whole model is. The two thin layers at the ends are what carries the vocabulary contract.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Llama 3 expanded its tokenizer to 128k tokens for the new generation rather than swap mid-run; the migration was at a model-version boundary.
- Code-focused models like DeepSeek-Coder use specialized tokenizers chosen up front for code compression rather than swapping later.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf the new tokenizer is a strict superset of the old, can you skip the adaptation phase?
No. Even with a superset, the segmentation of common text changes when new merges are introduced. The model has to adapt to the new segmentation distribution, not just learn embeddings for novel tokens.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Assuming the transformer body is token-agnostic and treating a tokenizer swap as a configuration change rather than a structural model migration.
60 second bullets to scan on the way to the call.
Which weight matrices are indexed directly by token ID?
Why is the transformer body itself token-agnostic?
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.