Sync with tiktoken - #87
Draft
l0rinc wants to merge 4 commits into
Draft
Conversation
l0rinc
commented
Feb 12, 2024
| ranks.set(nextIndex, DUMMY_RANK); | ||
|
|
||
| length--; | ||
| if (length < 3) { |
Contributor
Author
There was a problem hiding this comment.
micro-optimization, let's simplify
l0rinc
commented
Feb 12, 2024
| Map<String, Integer> specialTokens | ||
| ) { | ||
| Pattern regex = compileRegex("'(?:[sdmt]|ll|ve|re)| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)|\\s+", false); | ||
| Pattern regex = compileRegex("'(?:[sdmt]|ll|ve|re)| ?\\p{L}++| ?\\p{N}++| ?[^\\s\\p{L}\\p{N}]++|\\s+(?!\\S)|\\s++", false); |
Contributor
Author
There was a problem hiding this comment.
except for \\s+(?!\\S) all groups should be possessive, no need to step back on match failure
l0rinc
marked this pull request as ready for review
February 13, 2024 13:33
l0rinc
marked this pull request as draft
February 13, 2024 13:34
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.
After porting the optimizations ending in #77 back to tiktoken, this is a synchronization PR based on the reviews there.
Especially openai/tiktoken#245, which revealed that the legacy encodings have a severe backtracking problem - though it seems that Java's engine can handle it properly, since adding the possessives made it a tiny bit slower - but at least the regex is in sync with tiktoken (note that cl100k is unaffected by the regex changes, only the
tokenCount > 2change is related):Before:
After - a bit slower for some reason, but at least it's synchronized with tiktoken:
Made this a draft since the tiktoken PRs aren't fully finished yet, so I expect to have a few more changes here as well.