You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
npu tokenizer: a Gemma-family tokenizer.json encodes to the wrong ids (31 for the reference's 21) and replies keep the raw word-boundary symbols #2215
The NPU route's own tokenizer reader (npu/tokenizer.cpp) mis-reads the Gemma family's tokenizer.json. Prompts are encoded to different ids than the reference library gives, and replies come back with ▁ where spaces belong.
Found on FastFlowLM/Nemotron-3.5-Bolt-E4B-NPU2 while taking #1780's target to the device (see #2213 for the other defect on that pack).
Measured (device-free)
Same tokenizer.json, same text, engine reader against Hugging Face tokenizers 0.23.3:
Across the 19 distinct tokenizer.json files on this box, 8 texts each: 16 files match the reference 8 of 8. Three match 1 of 8, all of this shape: bolt-e4b, gemma3-270m-npu2, gemma22b-awq.
On the device the reply to that prompt read Here▁is▁a▁Python▁function▁that▁returns▁the▁....
Cause
The file is BPE with merges, a normalizer that only rewrites spaces ({Replace " " -> "▁"}, no Prepend), a Split pre-tokenizer on the space, and a decoder that turns ▁ back into a space. The reader recognises SentencePiece pieces when the merge list is empty or when the normalizer prepends the symbol; this shape is neither, so it goes down the byte-level path, which splits on spaces and byte-maps them, and its decode leaves the symbol alone.
After that normalizer no space is left for the pre-tokenizer to split on, so a run of text is one word merged by rank, with no prefix.
Fix
Recognise the shape, encode by rank without the prefix, decode the symbol to a space without stripping a leading one. PR follows, with a synthetic nine-token fixture whose expected ids come from the reference library.
Taking this row. The measurement reproduces, and the reason it was invisible is that the goldens are wired to a different reader.
Measured on main today, device-free, with the engine's own reader.npu/tokenizer.cpp has not changed between the build I used and current main (git log HEAD..origin/main -- npu/tokenizer.cpp → 0 commits), so the reader under test is the one that ships.
I paired two committed goldens with the exact tokenizer.json files they name by sha256, both present on this box:
The first failing case is the symptom in this issue: a single space should be the ▁ piece (236743) and the reader gives 245237. That is the here▁is▁a▁Python output, at the smallest possible input.
Why nothing caught it
The 18 goldens in tests/data/tokenizers/ are registered against hf_tokenizer_test — the Rust tokenizer behind the C ABI — and only under two switches that are both off by default:
option(ONEBIT_HF_TOKENIZERS"…"OFF) # needs cargoset(ONEBIT_TOKENIZER_ROOT ""CACHEPATH"…") # must point at a models dirforeach(_g ${_tok_golden}) add_test(NAMEhf_tokenizer_${_m}COMMANDhf_tokenizer_test…)
The engine's own reader (tokenizer_test, linked against onebit_npu) is registered against one fixture — tests/data/spm_bpe_tokenizer.json — plus an optional ${ONEBIT_NPU_MODEL} case. So the goldens validate the Rust path, and the reader that actually serves the NPU route is not measured against them at all. Two committed gemma goldens fail the reader by 15 of 17 cases and main is green.
Slice I am taking
register tokenizer_test against tests/data/tokenizers/*.json the way hf_tokenizer_test already is, so this cannot be invisible again — gated on the golden's own named sha256 so a mismatched pack is a skip with a printed reason, not a fail on the wrong file;
the reader fix for the space/▁ handling the issue describes, verified by those goldens going 17/17.
ORCH: (2) needs a build and this box is at 169 G against the 175 G build threshold — incremental only, in an existing tree, if that is acceptable; otherwise it waits for disk. (1) I can prepare on a branch now, but it must land with (2): registering a failing golden would red main, which is the opposite of what a ratchet is for.
Activity
tokenizer: hold the NPU reader to the reference cases kept for Gemma4…
bong-water-water-bong commentedon Nov 11, 2026
Taking this row. The measurement reproduces, and the reason it was invisible is that the goldens are wired to a different reader.
Measured on
maintoday, device-free, with the engine's own reader.npu/tokenizer.cpphas not changed between the build I used and currentmain(git log HEAD..origin/main -- npu/tokenizer.cpp→ 0 commits), so the reader under test is the one that ships.I paired two committed goldens with the exact
tokenizer.jsonfiles they name by sha256, both present on this box:Gemma4-E2B-IT-NPU2.jsoncc8d3a0ce3~/scratch-packs/gemma4-e2b-npu2/tokenizer.jsoncc8d3a0ce364✓Gemma3-1B-NPU2.json4667f2089529~/.config/flm/models/Medgemma-4B-NPU2/tokenizer.json4667f2089529✓The first failing case is the symptom in this issue: a single space should be the
▁piece (236743) and the reader gives245237. That is thehere▁is▁a▁Pythonoutput, at the smallest possible input.Why nothing caught it
The 18 goldens in
tests/data/tokenizers/are registered againsthf_tokenizer_test— the Rust tokenizer behind the C ABI — and only under two switches that are both off by default:The engine's own reader (
tokenizer_test, linked againstonebit_npu) is registered against one fixture —tests/data/spm_bpe_tokenizer.json— plus an optional${ONEBIT_NPU_MODEL}case. So the goldens validate the Rust path, and the reader that actually serves the NPU route is not measured against them at all. Two committed gemma goldens fail the reader by 15 of 17 cases andmainis green.Slice I am taking
tokenizer_testagainsttests/data/tokenizers/*.jsonthe wayhf_tokenizer_testalready is, so this cannot be invisible again — gated on the golden's own named sha256 so a mismatched pack is a skip with a printed reason, not a fail on the wrong file;▁handling the issue describes, verified by those goldens going 17/17.ORCH: (2) needs a build and this box is at 169 G against the 175 G build threshold — incremental only, in an existing tree, if that is acceptable; otherwise it waits for disk. (1) I can prepare on a branch now, but it must land with (2): registering a failing golden would red
main, which is the opposite of what a ratchet is for.