Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,8 @@ func parseGGUFFile(fs []_GGUFFileReadSeeker, o _GGUFReadOptions) (_ *GGUFFile, e

// tensor infos
if gf.TensorInfos == nil {
tc, ok := gf.Header.MetadataKV.Get("split.tensors.count")
if ok {
gf.TensorInfos = make(GGUFTensorInfos, 0, anyx.Number[int](tc.Value))
} else {
// avoid preallocating with tensorCount (could be huge); start empty and append
gf.TensorInfos = make(GGUFTensorInfos, 0)
}
// avoid preallocating with tensorCount (could be huge); start empty and append
gf.TensorInfos = make(GGUFTensorInfos, 0)
}
{
rd := _GGUFTensorInfoReader{_GGUFReader: rd}
Expand Down
7 changes: 7 additions & 0 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,13 @@ func TestParseGGUFArrayLengthDoS(t *testing.T) {
}
}

func TestParseGGUFFile_InvalidSplitTensorsCount(t *testing.T) {
kv := GGUFMetadataKV{Key: "split.tensors.count", ValueType: GGUFMetadataValueTypeString, Value: "-1"}
if _, err := ParseGGUFFile(writeProjectorGGUF(t, []GGUFMetadataKV{kv})); err != nil {
t.Errorf("unexpected error: %v", err)
}
}

// writeProjectorGGUF writes a projector file with no tensors and the given
// vision metadata, in the order llama.cpp's loader reads it.
func writeProjectorGGUF(t *testing.T, kvs []GGUFMetadataKV) string {
Expand Down
Loading