Repository navigation
Conversation
Author
|
@ArthurZucker hey, could you revisit this one please? |
This branch has not been deployed
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.
A compact version of @Yikai-Liao's parallel BPE trainer in #2501, for the review question there of how small the engine can be: ~470 lines of code (+544 with comments) instead of ~14,500, with the same merges. It keeps the three ideas that give the speed:
do_train: highest count first, ties to the smaller pair.(A, A)rule and no crossed endpoints. The corpus is cut at word boundaries, one chunk per thread, and pair changes are committed by shard in parallel.Everything else in #2501 is left out: compressed lists, radix grouping, active-ID reuse mode, the parallel feed, affixes, the alphabet limit and the birth length rule. With an affix,
limit_alphabetormax_token_length,do_trainfalls back to the existing trainer, unchanged. A rule whose result already exists, or(A, A), runs alone.It also adds
do_train_entries(Vec<(CompactString, u64)>), to train from counts the caller already made, without a map.Exact: vocab and merges are identical to
mainand to #2501 on 48 settings (4 datasets × 11 pre-tokenizers, plus NFKC + lowercase, 100 MB each) and in all 40 runs of #2501's harness. Existingtk-traintests pass.Results
These use #2501's own harness (tokenizers-bpe-benchmarks @
0fa8d08): 512 MiB per corpus, vocab 100,000,min_frequency = 2, 8 workers, median of 3 runs. Machine: 2× AMD EPYC 7742, pinned cores.Feed + train, seconds (lower is better):
mainmainTrain only, seconds:
mainmainPeak memory, GiB:
mainmainMemory growth with input size, 8 workers (
main: one point, at 512 MiB):The gap to #2501 has three causes:
main's serial feed, where perf(bpe trainer): 10–32× faster with 8 threads #2501 counts words in parallel;Vec<u32>, where perf(bpe trainer): 10–32× faster with 8 threads #2501 compresses them;That is the trade: under 4% of the code for 35–75% of #2501's speed.
Broader benchmarks (threads, vocab, 11 pre-tokenizers, 10 normalizers, 1 and 10 GB, 4 datasets) are in nov3o/toki.