Skip to content

BUG: bpb underestimated when tokenizer does not contain U+2581 (ie the space) token #897

Open

Description

@riccardoalberghi

build_sentencepiece_luts (train_gpt.py:180) tries to estimate how many UTF-8 bytes each token corresponds to.

For normal tokens, it removes the leading ▁, treats that as a single space byte, and then counts the UTF-8 bytes in the rest of the token string. For byte-fallback tokens (sp.is_byte()), it just counts 1 byte per token.

The issue shows up when ▁ (U+2581) is not present as its own token. In that case, SentencePiece encodes it as three separate byte tokens: <0xE2>, <0x96>, and <0x81>, since ▁ is three bytes in UTF-8. Because each of those fallback tokens is counted as 1 byte, the code ends up treating ▁ as 3 bytes.

But in practice, ▁ is only used to represent a single ASCII space (0x20), which is just 1 byte. So every word boundary gets overcounted by 2 bytes.

That makes val_byte_count too large, which then makes tokens_per_byte look smaller than it really is and pushes BPB artificially low. I have run a few tests, we are talking roughly about a 20% decrease in reported bpb compared to the true one.

The standard fineweb_1024_bpe.model does include ▁ as token 939, so the normal stripping logic handles it correctly and this edge case never happens. It only appears with a custom SentencePiece model that does not contain a standalone ▁ token.

Hope this helps.
Riccardo

Activity

  1. anthony-maio commented on Mar 26, 2026

    @anthony-maio

    Hey I took a look at this also and Riccardo is 100% spot on here. This bug could be gamed for reward hacking if the tokenizer ignores certain bytes rather than actually compressing the data more efficiently. We need a fix that validates against raw UTF-8 byte stream to ensure BRB is truly representative of the original data.

  2. riccardoalberghi commented on Mar 26, 2026

    @riccardoalberghi
    Author

    Also if a token ends or have within U+2581 the same problem arises.

    Riccardo

  3. MatoTeziTanka commented on Apr 12, 2026

    @MatoTeziTanka

    The corrected tokenizer and pre-tokenized shards are now published.

    Scylla v2 — a byte-exact tokenizer that fixes the BPB underestimation described in this issue — is available at LightSpeedUp/parameter-golf-data on HuggingFace:

    huggingface-cli download LightSpeedUp/parameter-golf-data --include "fineweb_scylla_v2/*" --local-dir ./data

    Includes the corrected .yaml tokenizer config, .meta.npz, and 81 pre-tokenized shards (~16.9 GB). The tokenizer path is the same one in PR #1314.

    This bug was one of the reasons we built the full dataset drop — while fixing the Scylla tokenizer we realized none of the larger vocab variants (sp4096, sp8192, sp12288, sp16384, byte260) were available on HuggingFace either. All six variants are now in the same repo (~89 GB total).


    @MatoTeziTanka — The Agora

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions