Repository navigation
Tokenizer: request gaps with no normalized added spelling stay on the memo - #2844
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/tokenizer-memo-gaps
branch
from
November 14, 2026 03:24
67ffeab to
2ff7317
Compare
ashhart
added a commit
that referenced
this pull request
Nov 18, 2026
ashhart
force-pushed
the
lead/tokenizer-memo-gaps
branch
from
November 18, 2026 02:40
2ff7317 to
6d0d4b7
Compare
ashhart
added a commit
that referenced
this pull request
Nov 19, 2026
ashhart
force-pushed
the
lead/tokenizer-memo-gaps
branch
from
November 19, 2026 01:17
6d0d4b7 to
3cf692a
Compare
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
…pelling (#2844) -- 2.54.0 (Apple Git-157)
ashhart
force-pushed
the
lead/tokenizer-memo-gaps
branch
from
November 21, 2026 13:06
3cf692a to
d3076fd
Compare
A request gap whose normalized text has no t.normalized match encodes through encodeSegment exactly as the clipped-span mask would, so test the normalized gap and skip the mask; MaskWork.masked counts the slow path. Golden ids from 96 base-commit cases replay identically, warm memo included.
…r.zig within 600 lines
…malized text goes into the encode step The gap check normalized a request gap, then encodeTextMasked (masked branch) or encodeText (memo miss or short gap) normalized it again. The check's text and first-piece offset now pass into encodeTextMasked, the same computation done once, so the ids are unchanged. encodeText had no callers left and is gone.
…pelling (#2844) -- 2.54.0 (Apple Git-157)
ashhart
force-pushed
the
lead/tokenizer-memo-gaps
branch
from
November 21, 2026 17:37
d3076fd to
2b2a918
Compare
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
…pelling (#2844) -- 2.54.0 (Apple Git-157)
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a tokenizer with normalized added tokens (DeepSeek-style ones have them; our Qwen, Nemotron and LFM tokenizers don't), every gap between a request's message spans took the masked path (
encodeTextMasked), which re-encodes the gap cold, even when the gap's normalized text holds no added-token spelling at all.What changes (
tokenizer.zig): before choosing the masked path, the gap is normalized the same wayencodeTextMaskednormalizes it, and when it holds not.normalizedmatch it takes the same memoised path a non-request gap takes. Gaps that do carry a spelling keep the mask, unchanged.MaskWork.maskedcounts the masked gaps.Exactness: with no normalized match, the masked path's split returns the whole normalized gap as one segment and encodes it exactly as the fast path does, so the ids are the same; the decision is made on the normalized gap because a normalizer can create a spelling (
eplus U+0301 under NFC).Checks: three new tests in
masked_test.zig: a gap with no spelling takes the memo (second call hits; fails on main: expected 0 masked, found 1), a gap carrying a spelling still takes the mask, and a golden replay of 96 random and adversarial texts over four fixtures (ASCII with normalized and plain added tokens, Unicode NFC and NFD) whose ids were recorded on main fb8fdf3, cold and with a warm memo. All 57 tokenizer tests pass;zig fmt --checkclean; no new lean findings. On a 32K-word request the host benchmark goes from 268-271 µs to 152-171 µs a call.Still to run: an end-to-end
/tokenizecomparison on a DeepSeek-style tokenizer, ids equal.