Skip to content

Count decoded internal whitespace in byte lookup tables - #2175

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/count-decoded-whitespace-bytes
Open

sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/count-decoded-whitespace-bytes

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Oct 5, 2026 •

Copy link
Copy Markdown

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▁beta is 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

  • 24 tests passed using the actual PyTorch and MLX helpers. Unchanged code fails 12 cases and passes 12 controls.
  • Tests train tiny SentencePiece models entirely in memory from synthetic text, with and without word-boundary splitting. They compare lookup totals with actual decoding for repeated/internal spaces and Unicode text.
  • Piece-level counts, control/unknown tokens, extra vocabulary slots, and fixed-likelihood BPB calculations are checked. MLX cases are optional on unsupported hosts and all ran on CPU here.
  • Ruff syntax/error checks and git diff --check passed. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant