Skip to content

Add char BPE incomplete coverage fallback - #864

Merged
gkielian merged 1 commit into
ReaLLMASIC:masterfrom
klei22:codex/add-option-for-incomplete-coverage-bpe
Jul 18, 2026
Merged

Add char BPE incomplete coverage fallback#864
gkielian merged 1 commit into
ReaLLMASIC:masterfrom
klei22:codex/add-option-for-incomplete-coverage-bpe

Conversation

@klei22

@klei22 klei22 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@gkielian
gkielian merged commit 1fb403d into ReaLLMASIC:master Jul 18, 2026
2 of 10 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_bpe CLI flag to control whether incomplete character coverage is allowed.
  • Update CharBPETokenizerWithByteFallback to 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 thread data/template/prepare.py
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.")
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.

3 participants