The same tokenizer file gives a browser and Python different ids
A program that runs for 150,000 ticks goes wrong if a single id is wrong, and the machine's own rules say what every tick must give, without asking any tokenizer library. So the machines became a test of the runtimes that read tokenizer.json: the Rust library behind Python's transformers, and the JavaScript ports that run models in web pages. The same checks then ran on the most-downloaded models on the Hugging Face Hub. This is the difference that reaches the most of them.
ΟΔΟΣ
"Street" in capitals, as on a sign, through the tokenizer of bert-base-multilingual-uncased (mBERT), which lowercases text before splitting it.
JavaScript's toLowerCase follows Unicode: a capital Σ that ends a word becomes ς. The Rust library lowercases one character at a time, so it becomes σ, which Greek never writes at the end of a word. The browser's ids are exactly those of the word typed in lowercase; Python's are not. Python's own "ΟΔΟΣ".lower() gives ς, and so does the tokenizer Google released BERT with, run on Python 3.
This browser lowercases it to ….
Search over Greek text with an index built in Python and questions tokenized in the browser. 900 questions from Belebele, typed in capitals, each looking for its passage among 488. The same weights and the same code embed both sides; only the ids differ.
| Model | Top passage changes | Found first, Python | Found first, browser |
|---|---|---|---|
| all-MiniLM-L6-v2 | 12% | 2.1% | 2.2% |
| bge-small-en-v1.5 | 18% | 9.0% | 9.4% |
| mBERT | 44% | 23.3% | 31.9% |
Typed normally, mBERT finds the right passage first for 31.9% of the questions in both runtimes. In capitals, the browser keeps 31.9%; Python drops to 23.3%. The two English models barely read Greek, so for them the rankings reshuffle without getting better or worse.
tokenizer.json differ this way: BERT-style models such as bert-base-uncased, all-MiniLM, BGE and E5, and CLIPIf you use these models: embed your documents and your queries with the same runtime, or check that the two agree on your text. python -m tokcpu check your/model lists every text on which the JavaScript runtimes differ from Python. Which lowercasing mBERT was trained with is not certain, since Google's code also ran on Python 2, which gives σ; but the browser's version is the one that matches the word written normally.
Changing: tokenizers.js, which transformers.js 4 builds on, has merged a change to σ, like the Rust library (tokenizers.js#56, 25 November 2026). It is not in a release yet, so the transformers.js 4.3.2 this page runs still gives ς.
Tested in October 2026: transformers.js 3.7.6 and 4.3.1 and tokenizers.js 0.2.0 on Node 22, against tokenizers 0.23.3 and transformers 5.20.2. The search experiment used transformers.js 4.3.1's ids, and PyTorch for every embedding. The count of models is from the run of 29 November 2026, with transformers.js 3.8.1 and 4.3.2.
llama.cpp skips a step Qwen's tokenizer asks for, and answers change
llama.cpp, and Ollama and LM Studio built on it, never read tokenizer.json: the GGUF file carries the vocabulary, and llama.cpp's own code does the rest. The same checks, run on the most-downloaded GGUF repos, found that llama.cpp skips the NFC normalization Qwen 2 and 3 ask for. NFC is usually explained with accents, but it also rewrites ordinary letters in Bengali, Punjabi, Odia and Hindi.
হয়
"Is", one of the commonest words in Bengali, through the tokenizer of Qwen2.5-1.5B-Instruct. Its last letter, য়, is typed as one character, U+09DF. NFC always splits it in two: য and a dot below (U+09BC).
The dot has no token of its own, so Python spells it in two byte pieces. llama.cpp's single token looks tidier, but Python never produces it: NFC splits the letter before tokenizing, every time. The model's own tokenizer.json asks for NFC, and the model finds llama.cpp's version more surprising almost every time (below).
This browser's NFC splits it the same way: U+09DF becomes ….
Belebele again: a passage, a question and four options in the model's chat template; the answer is the likeliest of A to D. Both id sequences go through the same weights and PyTorch code. 200 questions per language, as written and decomposed (NFD), the form macOS file names and some copied text arrive in: Python composes it back, llama.cpp does not.
Accuracy with Python's ids → with llama.cpp's. Chance is 25%.
| Text | Qwen2.5-1.5B | Qwen3-1.7B |
|---|---|---|
| Korean, decomposed | 69.0% → 25.0% | 54.0% → 24.5% |
| Vietnamese, decomposed | 71.0% → 40.0% | 64.0% → 34.0% |
| Bengali, as written | 46.5% → 44.0% | 44.5% → 36.5% |
| French, decomposed | 80.0% → 78.0% | 68.0% → 68.0% |
| English, as written | 84.5% → 84.5% | 81.0% → 81.0% |
Decomposed Korean falls to chance. In Bengali as written, 23% of answers change in both models, and Qwen3 loses 8 points: 23 questions only Python's ids get right, against 7 only llama.cpp's (p = 0.005). Qwen2.5's fall in Bengali is not significant, nor is any change in French, German, Punjabi, Odia, Hindi or Yoruba. English, the control, gives the same ids.
tokenizer.json asks for NFCIf you run these models in llama.cpp: normalize text to NFC before it reaches the tokenizer, with unicodedata.normalize("NFC", text) in Python or text.normalize("NFC") in JavaScript. For all 4,000 prompts here, that gives llama.cpp exactly Python's ids.
Tested in October 2026: llama.cpp 0.7.0, with the vocabularies of Qwen's official GGUFs, against tokenizers 0.23.3 and transformers 5.22.0. Both id sequences ran through the full-precision model in PyTorch, to isolate the tokenizer; llama.cpp users run quantized weights. Two small models and the first 200 questions of each language.
llama.cpp gives Gemma 4 a second <bos>, and accuracy falls
A model's ids usually start with <bos>, a token that marks the beginning of the text. Gemma 4's chat template writes it itself, so its tokenizer.json adds none. llama.cpp adds one anyway. A program that renders the template and hands llama.cpp the text sends Gemma 4 two.
Hi
One word from the user, in the chat template of gemma-4-E2B-it, which turns it into <bos><|turn>user, the word, and the start of the model's turn.
llama-server's chat endpoint gets this right: it renders the template itself, drops the template's <bos> and sends one. Its /completion and /v1/completions endpoints, given text the template already rendered, send two.
Belebele again, as for Qwen: the same weights and PyTorch code read both id sequences, 200 questions each in English, German, Hindi and Chinese. Two settings: the chat template, and the same question as plain text ending in "Answer:", where Python's ids have no <bos> at all.
Accuracy over 800 questions. With the template, Python's ids hold one <bos> and llama.cpp's two; with plain text, none and one. Chance is 25%.
| Text | Python's ids | llama.cpp's ids |
|---|---|---|
| Chat template | 71.0% | 65.0% |
| Plain text | 35.5% | 66.8% |
With the template, accuracy falls in every language, by 9 points in English and 8 in Chinese; German's 2 are not significant. Without a template, it is Python's ids that fail: with no <bos>, Gemma 4 does little better than chance. It wants exactly one, and neither tokenizer gives it one every time.
<bos> that tokenizer.json does not; 24 of them are Gemma 4<bos>; 65% change when the only one is missingIf you run Gemma 4 in llama.cpp: send messages to llama-server's chat endpoint, or, if you render the template yourself, tokenize the result with add_special=false. For plain text with no template, keep llama.cpp's <bos>.
Tested in November 2026: llama.cpp 0.7.0 (llama-server b11669), with the vocabulary of ggml-org's GGUF, against tokenizers 0.23.3 and transformers 5.23.0. Both id sequences ran through the full-precision model in PyTorch (bfloat16), scored on the same tokens. One small model, four languages, the first 200 questions of each. The doubled prompt is slightly less surprising to the model, so here surprise does not say which side is right.
One tick
The tape is a string. Exactly one character on it is the head: a marker that stands for a machine state and reads the character beside it. The tokenizer has one merge rule for every pair the head can form with a cell, and no other merges.
Find the head
BPE can only merge the head with the cell it reads, so the tape splits into single characters plus one two-character token.
Look up the rule
Each such pair has its own id. That id is the rule: which symbol to write, which way to move, which state comes next.
Print the result
The same id is also an added token whose text is the rule's output. Decoding prints it where the pair was. Every other character decodes to itself.
Stop when nothing changes
A halting state has no merge rules, so its tape decodes to itself. The loop stops when the tape stops changing.
The catch: every step would have to be reversible
A token id decodes to exactly one string, and the library keeps one string per id when it saves a tokenizer. So if two rules wrote the same output, they would need two added tokens with the same text, which a tokenizer cannot hold. Taken plainly, the trick only runs machines whose every step can be undone: reversible computers.
Ordinary programs throw information away all the time. So each output carries a short tag of private-use characters that makes it unique, and the decoder has one generic rule: delete those characters. That deletion is the only place the machine forgets anything. It is a single find-and-replace with an empty replacement, the same for every machine.
One pass is not enough; the loop is the point
A single encode is a weak computer. Cognetta and Okazaki showed that BPE tokenization is a finite-state transduction: one pass can only look a bounded distance ahead. One tick here rewrites just the two characters around the head.
Repeating the tick is what makes it unbounded. With a tape that can grow, which the rules allow at either edge, repeated tokenizing can run any program a Turing machine can. The loop is three lines of Python, the same way the famous "CSS is Turing complete" demos need someone clicking.
The ladder
Rung 1, small machines. A binary counter (7 rules) and the 4-state busy beaver (24 rules), which halts after exactly 107 ticks with 13 ones on the tape, its known record.
Rung 2, one program per tokenizer. A compiler turns a Brainfuck program into a machine whose states are the program. Each instruction is one tick, and printing walks the byte to the output at the left of the tape, one nibble at a time. Hello World becomes 38,265 rules and prints in 1,194 ticks.
Your own machine. The last tab compiles a Turing machine you type into a new tokenizer, right in this page, and runs it. The compiler is a JavaScript port of the Python one and writes the same file, byte for byte.
Rung 3, one tokenizer for every program. A universal interpreter of 17,210 rules. The program is written on the tape. The head carries each instruction from ▼, the instruction pointer, to ▲, the data pointer, executes it there and walks back. Data cells are Braille characters, whose dots spell the byte. Loops can nest 64 deep. Input waits at the right end of the tape after ¦, and , takes its first character.
Parallel ticks
One encode reads the whole tape, but a single head uses two characters of it. Heads that never meet each get their rule applied in the same tick: two busy beavers on one tape finish together in 107 ticks.
Going further, a stock Split pre-tokenizer can cut the tape into two-character blocks before BPE runs. With a merge for every block, one tick rewrites the whole tape: a block cellular automaton. A phase mark after the left edge shifts the blocks by one character every other tick, so information crosses block boundaries. One demo sorts letters, odd-even transposition sort, one round per tick: ⊢◦thequickbrownfoxjumpsoverthelazydog⊣ is sorted after 30 ticks, with 704 rules.
The other runs Rule 110, which is Turing complete, in 29 rules. Every cell updates in every generation, which takes two ticks: in the first, each cell learns the value of the other cell in its block; in the second, the blocks have shifted, each cell learns its other neighbour and updates. The edges grow the tape by a cell on each side every generation. Rule 110 computes on a background that repeats forever, its ether, and the edges can grow that too: it takes 146 rules. Below, the tokenizer compiles in this page for any of the 256 elementary rules, and every row is one more encode and decode.
The start of the tape, as the tokenizer splits it: every two-character block is one token. Between generations a cell is · or █; after the first tick of a generation, a–d is a cell that knows its left neighbour and e–h one that knows its right.
Numbers
| Tokenizer | Merge rules | File | Program | Ticks |
|---|---|---|---|---|
| 4-state busy beaver | 24 | 4 KB | itself | 107 |
| Hello World, compiled | 38,265 | 5.7 MB | Hello World | 1,194 |
| Universal Brainfuck | 17,210 | 2.6 MB | Hello World | 154,137 |
| Alphabet | 27,053 | |||
| Grid (nested loops) | 17,474 | |||
| Jumps (skipped and nested) | 21,415 | |||
Reverse, input stressed | 1,904 | |||
| Sort, a block automaton | 704 | 95 KB | the pangram's 35 letters | 30 |
| Rule 110 | 29 | 5 KB | one cell, any number of generations | 2 a generation |
| Rule 110 on its ether | 146 | 22 KB | 56 cells, any number of generations | 2 a generation |
Clock speed on the universal tokenizer running Hello World, best of three runs on an Apple M4: about 9,200 ticks a second with the tokenizers library, 5,900 through transformers' AutoTokenizer, 11,700 with transformers.js in Node, and 17,300 with this page in headless Chromium. Every tick of every run in the test suite is checked against the machine's own rules, and every output against a plain Brainfuck interpreter, in Python and in transformers.js.
Run it yourself
pip install -r requirements.txt python -m tokcpu build # writes tokenizers/ python -m tokcpu run tokenizers/brainfuck programs/hello.bf --auto python -m tokcpu run tokenizers/brainfuck programs/reverse.bf --input stressed python -m tokcpu run tokenizers/4-state-busy-beaver --show 1 python -m tokcpu run tokenizers/sort --show 2 python -m tokcpu ca tokenizers/rule110 --gens 24 python -m tokcpu check google-bert/bert-base-multilingual-uncased # after cd fuzz && npm install
The tokenizer folders load with AutoTokenizer.from_pretrained, so they can go on the Hugging Face Hub like any other. check compares any Hub model's tokenizer, or a folder holding one, across Python and the JavaScript runtimes.