Repository navigation
Count decoded internal whitespace in byte lookup tables - #2175
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <[email protected]>
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.
Problem
The byte lookup tables remove one leading SentencePiece whitespace marker, but count internal or repeated markers as their three-byte U+2581 encoding. Those markers decode to one-byte ASCII spaces. A multiword piece such as
▁alpha▁betais therefore assigned 12 base bytes instead of the decoder's 10.This overstates the byte denominator for affected custom tokenizers and can understate bits per byte without improving the model. SentencePiece documents whitespace-marker replacement in its detokenization description.
Changes
Convert the remaining whitespace markers to spaces before measuring UTF-8 length in both baseline helpers. Preserve the separate leading-space flag and boundary adjustment. No tokenizer, training data, stored checkpoint, or competition submission is changed.
Validation
git diff --checkpassed. Both baselines remain below 1,500 lines.Python 3.12.14, SentencePiece 0.2.2, PyTorch 2.14.1, MLX 0.32.3 on macOS arm64. No real datasets, GPU training, full validation run, or leaderboard measurement was used.
This addresses markers inside ordinary pieces. It does not resolve the separate byte-fallback problem in #897 or the leading-space double-credit in #1719. The optimizer and rotary paths are unchanged.
Reproduced against
f5c079314c4877fbb0af378c0abade5a8ca33d3a.Maintenance validation on 6 November 2026
Revalidated the real SentencePiece decoder against both byte-lookup implementations, including repeated whitespace and Unicode. No further source changes were needed.
Focused validation at
3a6ae9979f30: 24 CPU tests passed. The combined six-PR checkout passed 121 tests, including the actual PyTorch and MLX CPU implementations. The two baseline scripts remain below 1,500 lines; archived record scripts were not modified.Python 3.12.14, PyTorch 2.15.0 and SentencePiece 0.2.3 on macOS arm64. Tests used synthetic inputs with external sockets disabled. No pretrained checkpoint, external dataset, GPU training, full validation benchmark or leaderboard measurement was used. There are no hosted test runs on these PR heads. Earlier validation counts above are historical.