Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
fs/ggml: write int32 and int64 values to gguf files (#13335)
Jeffrey Morgan5a41d69b2ab7
diff --git a/fs/ggml/gguf.go b/fs/ggml/gguf.goindex b694deadb..e093efea1 100644--- a/fs/ggml/gguf.go+++ b/fs/ggml/gguf.go@@ -597,6 +597,10 @@ func ggufWriteKV(ws io.WriteSeeker, arch, k string, v any) error {var err errorswitch v := v.(type) {+ case int32:+ err = writeGGUF(ws, ggufTypeInt32, v)+ case int64:+ err = writeGGUF(ws, ggufTypeInt64, v)case uint32, FileType:err = writeGGUF(ws, ggufTypeUint32, v)case uint64:@@ -611,6 +615,10 @@ func ggufWriteKV(ws io.WriteSeeker, arch, k string, v any) error {err = writeGGUFArray(ws, ggufTypeInt32, v)case *array[int32]:err = writeGGUFArray(ws, ggufTypeInt32, v.values)+ case []int64:+ err = writeGGUFArray(ws, ggufTypeInt64, v)+ case *array[int64]:+ err = writeGGUFArray(ws, ggufTypeInt64, v.values)case []uint32:err = writeGGUFArray(ws, ggufTypeUint32, v)case *array[uint32]:diff --git a/fs/ggml/gguf_test.go b/fs/ggml/gguf_test.goindex f0c2826c3..51430e3b7 100644--- a/fs/ggml/gguf_test.go+++ b/fs/ggml/gguf_test.go@@ -42,6 +42,10 @@ func TestWriteGGUF(t *testing.T) {"general.architecture": "test","general.alignment": uint32(16),"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","tokenizer.key": "value3","adapter.key": "value4",@@ -55,7 +59,7 @@ func TestWriteGGUF(t *testing.T) {}defer r.Close()- ff, err := Decode(r, 0)+ ff, err := Decode(r, -1)if err != nil {t.Fatal(err)}@@ -65,15 +69,19 @@ func TestWriteGGUF(t *testing.T) {"general.alignment": uint32(16),"general.parameter_count": uint64(54),"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","tokenizer.key": "value3","adapter.key": "value4",- }, ff.KV()); diff != "" {+ }, ff.KV(), cmp.AllowUnexported(array[int32]{}, array[int64]{})); diff != "" {t.Errorf("Mismatch (-want +got):\n%s", diff)}if diff := cmp.Diff(Tensors{- Offset: 800,+ Offset: 992,items: []*Tensor{{Name: "blk.0.attn_k.weight", Offset: 0, Shape: []uint64{2, 3}},{Name: "blk.0.attn_norm.weight", Offset: 32, Shape: []uint64{2, 3}},