Add char BPE incomplete coverage fallback - #864
Merged
gkielian merged 1 commit intoJul 18, 2026
Merged
Conversation
gkielian
approved these changes
Jul 18, 2026
There was a problem hiding this comment.
Pull request overview
This PR adds a configurable fallback behavior for the CharBPETokenizerWithByteFallback when the requested vocab_size cannot include all observed characters in addition to the 256 byte-fallback tokens, and introduces tests to validate the new behavior.
Changes:
- Add
--char_bpe_incomplete_coverage_uses_bpe/--no-char_bpe_incomplete_coverage_uses_bpeCLI flag to control whether incomplete character coverage is allowed. - Update
CharBPETokenizerWithByteFallbackto optionally keep only the highest-frequency characters and rely on byte fallback for the rest. - Add unit tests covering the incomplete-coverage success path and the “require complete coverage” error path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
data/template/nanogpt_tokenizers.py |
Adds incomplete-coverage selection logic and persists related metadata for the char-BPE tokenizer. |
data/template/prepare.py |
Exposes a new CLI flag controlling incomplete-coverage behavior for char-BPE tokenization. |
data/template/tests.py |
Adds tests validating byte-fallback behavior under incomplete coverage and the strict-coverage error path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
585
to
589
| def _train_merges(self, text): | ||
| tokens = list(text) | ||
| tokens = self._initial_bpe_tokens(text) | ||
| # Nothing to merge if text empty or target vocab already satisfied | ||
| if len(tokens) < 2: | ||
| return |
Comment on lines
+116
to
+117
| parser.add_argument("--char_bpe_incomplete_coverage_uses_bpe", action=argparse.BooleanOptionalAction, default=True, | ||
| help="When char_bpe vocab_size cannot fit every observed character plus byte fallback, keep the highest-frequency characters/BPE tokens and rely on byte fallback for the rest (default: true). Use --no-char_bpe_incomplete_coverage_uses_bpe to require complete character coverage.") |
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.
No description provided.