Train BasicTokenizer on GPU with PyTorch, 100x speedup#38
Open
kuprel wants to merge 34 commits intokarpathy:masterfrom
Open
Train BasicTokenizer on GPU with PyTorch, 100x speedup#38kuprel wants to merge 34 commits intokarpathy:masterfrom
kuprel wants to merge 34 commits intokarpathy:masterfrom
Conversation
Author
|
Using an H100 and int16, it's now 108x speedup over the original implementation on M2 air |
Author
Owner
|
Ok I'll step through this soon to take a look. |
Author
|
Thanks for the feedback! I made the diff more surgical. Now the only added files are:
And the following files are lightly modified:
|
|
How do I actually train with a vocab size of 10000. The code says to concat the whole dataset to a giant string. This is breaking my computer. |
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.

The following files are added:
merge_torchBasicTokenizerTorch, overrides thetrainandencodemethods ofBasicTokenizerRegexTokenizerTorch, overrides theencode_ordinarymethod ofRegexTokenizerGPT4TokenizerTorch, mostly inherits fromGPT4Tokenizer, but usesRegexTokenizerTorch'sencodemethodBasicTokenizerTorchThe following files are modified:
It takes 67.4 seconds on an H100 80GB SXM5 to train the
BasicTokenizerTorchwith a vocab_size of 512 on 308MB of Enron emails. The original code takes 2hrs 15min on an M2 Air with Python 3.11 to do this.I'm not sure if
RegexTokenizerTorchorGPT4TokenizerTorchcan benefit much from pytorch since there are many chunks of varying lengths, i.e. a "ragged tensor". These tokenizers are helpful for sanity checks though. For example, thetest_gpt4_tiktoken_equalitytests all pass suggesting thatmerge_torchis correctly implemented.I also made a new repository minbpe-pytorch in case adding pytorch support is beyond the scope of this project.