Repository navigation
Conversation
Duplicated words share one subgraph object via the build cache, but UnconnectedGraphs.merge re-ran the merge per occurrence, so on the first merge that changed a word its occurrences diverged into equal-but-distinct copies, each re-memoizing get_merges separately. Merging per unique object keeps duplicates shared for the whole training run. Zipf corpus (20k words, 2k vocab), byte-identical output: - BPE: 1.92s -> 1.61s (-16%), peak 35.7MB -> 31.2MB (-13%) - BNE: 2.98s -> 2.33s (-22%), peak 37.8MB -> 32.2MB (-15%) - Boundless: neutral Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Superseded by the trainer-level version in #42 (per review discussion): deduping once in the trainer and training on unique subgraphs with weights is both simpler and faster than deduping inside |
This was referenced Jul 22, 2026
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.
What
Gigatoken-inspired (marcelroed/gigatoken): its BPE trainer never iterates word occurrences — everything is keyed on unique words with counts. Our equivalent: duplicated words already share one subgraph object (the
_build_graphscache), butUnconnectedGraphs.mergere-ran the merge once per occurrence. Worse, on the first merge that changed a word, its occurrences diverged into equal-but-distinct copies — each then re-memoizingget_mergesand re-scanning merges separately for the rest of training (measured: 16 unique words ballooning to ~290 distinct objects mid-training).Now
mergecomputes each distinct object's result once and reuses it for every occurrence, so duplicates stay shared (one object, one memo) for the whole run.Benchmarks (Python 3.14, best of 3, byte-identical digests)
Zipf-distributed corpus (20k words, 2k-word vocabulary, seeded):
Honest tradeoff: an adversarial corpus where every word is unique pays ~+12% (0.39s → 0.46s) for the per-step unique-object dict. Real text is Zipf-distributed, so duplication is the norm; the win grows with corpus size / dup ratio.
Verification
🤖 Generated with Claude Code