-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various script cleanups/fixes + convert merges and special token handling #2842
Merged
ggerganov
merged 17 commits into
ggml-org:master
from
KerfuffleV2:feat-scripts-improvements
Aug 30, 2023
+738
−758
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1793f25
convert: Fix permute calls and method/func definitions
KerfuffleV2 084dd21
Cleanups for gguf-py
KerfuffleV2 795c0c6
Minor types cleanups.
KerfuffleV2 ea43267
Initial implementation of handling merges and special tokens
KerfuffleV2 c7b0952
convert: Handle special tokens and merges in vocab only mode
KerfuffleV2 531746e
gguf: Refactor tensor name mapping
KerfuffleV2 120ed64
convert: Fix type hint for special_token_types in SpecialVocab
KerfuffleV2 bb6b64d
Use common special vocab handling in various conversion scripts
KerfuffleV2 f82aec9
First pass at implementing suggested changes
KerfuffleV2 4a3d783
Second pass
KerfuffleV2 8534197
gguf: SpecialVocab: Fix issue with special token content not in a dict
KerfuffleV2 61911ca
convert-falcon-hf-to-gguf: Support --vocab-only option, bail out if n…
KerfuffleV2 0c620ef
convert-gptneox-hf-to-gguf and convert: Only handle merges for BPE to…
KerfuffleV2 2ea1338
gguf: SpecialVocab: Actually set load_merges in object
KerfuffleV2 58fa4dc
Uniform args parsing and vocab only mode for convert examples
KerfuffleV2 ce00528
convert.py: Set gpt2 as tokenizer model when using BPE
KerfuffleV2 d77b74b
Squish last type warning in gguf.py - yay!
KerfuffleV2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes shut up the type warnings but I'm not 100% sure they're correct. The alternative would be to leave it
List[str]
and then convert the token text to a string. I assume it's already UTF-8 bytes so there probably isn't a functional difference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types are correct this way, because when we get to
tokens.append(text)
, 'text' is explicitly a bytearray.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I meant my change fixes the type warning but the part I wasn't sure about was whether
text
actually is supposed to be abytearray
there and what is supposed to get submitted togguf
to write out the tokens. The type annotation foradd_token_list
method is also justList
and doesn't specify what the element is supposed to be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decision was made to accept several types as input to the token list depending on type of he tokenizer output (spm vs bpe)
https://github.com/ggerganov/llama.cpp/blob/dd0dc366dab10e8df28d3924e7f313b5c695e908/gguf-py/gguf/gguf.py#L373-L375
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we'd want
Correct? Or would you want to allow the items to be non-homogenous like
List[Union[str, bytes, bytearray]]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the differences of the python types
str
,bytes
andbytearray
? If they all resolve to the same when written to disk then any of them could be used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it as simple it could be as long there is no difference in how the tokens are written to disk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str is unicode text which will be encoded as utf-8 before being written to disk. bytes and bytearray are binary data. Those two are subclasses of ByteString, but we can't use that because it also allows memoryview. The least repetitive way to write this would be to use a TypeVar:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should merges actually support all of those?