From eb8ca6996f5e3559505b3269d98e5d3ed860200e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Yusuf=20Sar=C4=B1g=C3=B6z?= Date: Fri, 11 Aug 2023 12:24:08 +0300 Subject: [PATCH] gguf : add gguf_get_kv_type --- ggml.c | 4 ++++ ggml.h | 9 +++++---- gguf-llama.cpp | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ggml.c b/ggml.c index df8dce7e8..ac45f12b0 100644 --- a/ggml.c +++ b/ggml.c @@ -19031,6 +19031,10 @@ const char * gguf_get_key(struct gguf_context * ctx, int i) { return ctx->header.kv[i].key.data; } +const enum gguf_type gguf_get_kv_type(struct gguf_context * ctx, int i) { + return ctx->header.kv[i].type; +} + const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i) { struct gguf_kv * kv = &ctx->header.kv[key_id]; struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i]; diff --git a/ggml.h b/ggml.h index f1673eed5..4490e076c 100644 --- a/ggml.h +++ b/ggml.h @@ -1744,10 +1744,11 @@ extern "C" { GGML_API size_t gguf_get_data_offset(struct gguf_context * ctx); GGML_API void * gguf_get_data (struct gguf_context * ctx); - GGML_API int gguf_get_n_kv(struct gguf_context * ctx); - GGML_API int gguf_find_key(struct gguf_context * ctx, const char * key); - GGML_API const char * gguf_get_key (struct gguf_context * ctx, int i); - GGML_API void gguf_get_val (struct gguf_context * ctx, int i, void * val); + GGML_API int gguf_get_n_kv(struct gguf_context * ctx); + GGML_API int gguf_find_key(struct gguf_context * ctx, const char * key); + GGML_API const char * gguf_get_key (struct gguf_context * ctx, int i); + GGML_API const enum gguf_type gguf_get_kv_type (struct gguf_context * ctx, int i); + GGML_API void gguf_get_val (struct gguf_context * ctx, int i, void * val); GGML_API const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i); GGML_API float gguf_get_arr_f32(struct gguf_context * ctx, int key_id, int i); diff --git a/gguf-llama.cpp b/gguf-llama.cpp index 08b700435..8b928c364 100644 --- a/gguf-llama.cpp +++ b/gguf-llama.cpp @@ -652,6 +652,9 @@ struct gguf_file_saver { const char * key = gguf_get_key(any_file_loader->gguf_ctx, i); if (strcmp(key, "general.quantization_version") == 0) { file.write_val("general.quantization_version", GGUF_TYPE_UINT32, new_ftype); + } else { + const gguf_type vtype = gguf_get_kv_type(any_file_loader->gguf_ctx, i); + GGML_UNUSED(vtype); } }