mirror of https://github.com/ollama/ollama
fs/ggml: write int32 and int64 values to gguf files (#13335)
This commit is contained in:
parent
c146a138e3
commit
5a41d69b2a
|
|
@ -597,6 +597,10 @@ func ggufWriteKV(ws io.WriteSeeker, arch, k string, v any) error {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
|
case int32:
|
||||||
|
err = writeGGUF(ws, ggufTypeInt32, v)
|
||||||
|
case int64:
|
||||||
|
err = writeGGUF(ws, ggufTypeInt64, v)
|
||||||
case uint32, FileType:
|
case uint32, FileType:
|
||||||
err = writeGGUF(ws, ggufTypeUint32, v)
|
err = writeGGUF(ws, ggufTypeUint32, v)
|
||||||
case uint64:
|
case uint64:
|
||||||
|
|
@ -611,6 +615,10 @@ func ggufWriteKV(ws io.WriteSeeker, arch, k string, v any) error {
|
||||||
err = writeGGUFArray(ws, ggufTypeInt32, v)
|
err = writeGGUFArray(ws, ggufTypeInt32, v)
|
||||||
case *array[int32]:
|
case *array[int32]:
|
||||||
err = writeGGUFArray(ws, ggufTypeInt32, v.values)
|
err = writeGGUFArray(ws, ggufTypeInt32, v.values)
|
||||||
|
case []int64:
|
||||||
|
err = writeGGUFArray(ws, ggufTypeInt64, v)
|
||||||
|
case *array[int64]:
|
||||||
|
err = writeGGUFArray(ws, ggufTypeInt64, v.values)
|
||||||
case []uint32:
|
case []uint32:
|
||||||
err = writeGGUFArray(ws, ggufTypeUint32, v)
|
err = writeGGUFArray(ws, ggufTypeUint32, v)
|
||||||
case *array[uint32]:
|
case *array[uint32]:
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ func TestWriteGGUF(t *testing.T) {
|
||||||
"general.architecture": "test",
|
"general.architecture": "test",
|
||||||
"general.alignment": uint32(16),
|
"general.alignment": uint32(16),
|
||||||
"test.key": "value",
|
"test.key": "value",
|
||||||
|
"test.int32_key": int32(-42),
|
||||||
|
"test.int64_key": int64(-9223372036854775808),
|
||||||
|
"test.int32_array": []int32{-1, 0, 1, 2147483647, -2147483648},
|
||||||
|
"test.int64_array": []int64{-1, 0, 1, 9223372036854775807, -9223372036854775808},
|
||||||
"attention.key": "value2",
|
"attention.key": "value2",
|
||||||
"tokenizer.key": "value3",
|
"tokenizer.key": "value3",
|
||||||
"adapter.key": "value4",
|
"adapter.key": "value4",
|
||||||
|
|
@ -55,7 +59,7 @@ func TestWriteGGUF(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
ff, err := Decode(r, 0)
|
ff, err := Decode(r, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -65,15 +69,19 @@ func TestWriteGGUF(t *testing.T) {
|
||||||
"general.alignment": uint32(16),
|
"general.alignment": uint32(16),
|
||||||
"general.parameter_count": uint64(54),
|
"general.parameter_count": uint64(54),
|
||||||
"test.key": "value",
|
"test.key": "value",
|
||||||
|
"test.int32_key": int32(-42),
|
||||||
|
"test.int64_key": int64(-9223372036854775808),
|
||||||
|
"test.int32_array": &array[int32]{size: 5, values: []int32{-1, 0, 1, 2147483647, -2147483648}},
|
||||||
|
"test.int64_array": &array[int64]{size: 5, values: []int64{-1, 0, 1, 9223372036854775807, -9223372036854775808}},
|
||||||
"test.attention.key": "value2",
|
"test.attention.key": "value2",
|
||||||
"tokenizer.key": "value3",
|
"tokenizer.key": "value3",
|
||||||
"adapter.key": "value4",
|
"adapter.key": "value4",
|
||||||
}, ff.KV()); diff != "" {
|
}, ff.KV(), cmp.AllowUnexported(array[int32]{}, array[int64]{})); diff != "" {
|
||||||
t.Errorf("Mismatch (-want +got):\n%s", diff)
|
t.Errorf("Mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := cmp.Diff(Tensors{
|
if diff := cmp.Diff(Tensors{
|
||||||
Offset: 800,
|
Offset: 992,
|
||||||
items: []*Tensor{
|
items: []*Tensor{
|
||||||
{Name: "blk.0.attn_k.weight", Offset: 0, Shape: []uint64{2, 3}},
|
{Name: "blk.0.attn_k.weight", Offset: 0, Shape: []uint64{2, 3}},
|
||||||
{Name: "blk.0.attn_norm.weight", Offset: 32, Shape: []uint64{2, 3}},
|
{Name: "blk.0.attn_norm.weight", Offset: 32, Shape: []uint64{2, 3}},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue