-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
convert-hf : reduce repeated boilerplate from write_tensors #7031
Closed
Closed
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
47e02eb
convert-hf : begin refactoring write_tensor
compilade 0d720ac
Merge branch 'master' into compilade/convert-hf-refactor
compilade c33775b
convert : upgrade to sentencepiece v0.2.0
compilade 698f0b3
convert-hf : remove unused n_dims in extra_*_tensors
compilade cde9ea6
convert-hf : simplify MoE weights stacking
compilade 56f60f5
convert-hf : flake8 linter doesn't like semicolons
compilade 3870164
convert-hf : allow unusual model part names
compilade dcd8dfa
convert : use a string for the SentencePiece tokenizer path
compilade 21068b6
convert-hf : display tensor shape
compilade 639b374
convert-hf : convert norms to f32 by default
compilade 644c269
convert-hf : sort model part names
compilade ce067af
convert-hf : use an ABC for Model again
compilade 13f4cf7
convert-hf : use a plain class for Model, and forbid direct instantia…
compilade 6a54973
Merge branch 'master' into compilade/convert-hf-refactor
compilade 3e5e0dc
Merge branch 'master' into compilade/convert-hf-refactor
compilade 98f2d0e
convert-hf : more consistent formatting of cmdline args
compilade f2099c5
convert-hf : align the message logged for converted tensors
compilade 215a0d3
convert-hf : fix Refact conversion
compilade c32d39c
Merge branch 'master' into compilade/convert-hf-refactor
mofosyne 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extraPaths": ["gguf-py"], | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
numpy~=1.24.4 | ||
sentencepiece~=0.1.98 | ||
sentencepiece~=0.2.0 | ||
transformers>=4.35.2,<5.0.0 | ||
gguf>=0.1.0 | ||
protobuf>=4.21.0,<5.0.0 |
Oops, something went wrong.
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.
Any particular reason for coercing shape to list here (and not elsewhere)?
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.
It's passed to
GGUFWriter.add_tensor_info
, which expects aSequence[int]
for the shape, and this shape is of typeNDArray[uint32]
which caused the error:This comes from the
shape
field of aReaderTensor
, and it is coerced to list in other places, like ingguf-dump.py
:llama.cpp/gguf-py/scripts/gguf-dump.py
Line 93 in b0d943d
llama.cpp/gguf-py/scripts/gguf-dump.py
Line 54 in b0d943d
But the
shape
field ofReaderTensor
is only used in 7 places (including its definition). In other places, the "shape" usually directly come from either Numpy or PyTorch, which usetuple[int, ...]
for the shape type, which is compatible withSequence[int]
.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.
I see, although
GGUFWriter.add_tensor_info
s typing is then perhaps not correct I understand why it's simpler to just make it a list.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.
GGUFWriter.add_tensor_info
's typing seems correct to me; it's used in 2 other places, and both use shapes which are already compatible withSequence[int]
.llama.cpp/gguf-py/gguf/gguf_writer.py
Lines 247 to 248 in b0d943d
llama.cpp/convert.py
Line 1145 in b0d943d
So using
Sequence[int]
there seems appropriate, as it's the most general type (I think?) which can be indexed (it avoids having to casttuple[int, ...]
intolist[int]
, orlist[int]
intotuple[int, ...]
).This is how the shape is used in
add_tensor_info
:llama.cpp/gguf-py/gguf/gguf_writer.py
Lines 210 to 211 in b0d943d
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.
Sure, all I'm saying is that that also works with NDArray[uint32] (even though it's not compatible with Sequence[int]).