gguf : add gguf_get_kv_type

This commit is contained in:
M. Yusuf Sarıgöz 2023-08-11 12:24:08 +03:00
parent b2440f1943
commit eb8ca6996f
3 changed files with 12 additions and 4 deletions

4
ggml.c
View File

@ -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];

9
ggml.h
View File

@ -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);

View File

@ -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<uint32_t>("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);
}
}