From 2906d5492d1ee01187de770797a019a5d3e22a0b Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 15 Aug 2023 20:46:18 +0300 Subject: [PATCH] gguf : remove obosolete gguf_get_arr_xxx API --- ggml.c | 4 ++++ ggml.h | 5 +---- gguf-llama.cpp | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ggml.c b/ggml.c index 7549566aa..7c90f44ec 100644 --- a/ggml.c +++ b/ggml.c @@ -19073,6 +19073,10 @@ float gguf_get_arr_f32(struct gguf_context * ctx, int key_id, int i) { return ((float *) ctx->kv[key_id].value.arr.data)[i]; } +const void * gguf_get_arr_data(struct gguf_context * ctx, int i) { + return ctx->kv[i].value.arr.data; +} + const char * gguf_get_arr_str(struct gguf_context * ctx, int key_id, int i) { struct gguf_kv * kv = &ctx->kv[key_id]; struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i]; diff --git a/ggml.h b/ggml.h index 3eb6acb10..4dc3ff977 100644 --- a/ggml.h +++ b/ggml.h @@ -1753,9 +1753,6 @@ extern "C" { GGML_API enum gguf_type gguf_get_kv_type (struct gguf_context * ctx, int i); GGML_API enum gguf_type gguf_get_arr_type(struct gguf_context * ctx, int i); - GGML_API int32_t gguf_get_arr_i32(struct gguf_context * ctx, int key_id, int i); // TODO: remove - GGML_API float gguf_get_arr_f32(struct gguf_context * ctx, int key_id, int i); // TODO: remove - GGML_API uint8_t gguf_get_val_u8 (struct gguf_context * ctx, int i); GGML_API int8_t gguf_get_val_i8 (struct gguf_context * ctx, int i); GGML_API uint16_t gguf_get_val_u16 (struct gguf_context * ctx, int i); @@ -1766,7 +1763,7 @@ extern "C" { GGML_API bool gguf_get_val_bool(struct gguf_context * ctx, int i); GGML_API const char * gguf_get_val_str (struct gguf_context * ctx, int i); GGML_API int gguf_get_arr_n (struct gguf_context * ctx, int i); - GGML_API void gguf_get_arr_data(struct gguf_context * ctx, int i, void * data); + GGML_API const void * gguf_get_arr_data(struct gguf_context * ctx, int i); GGML_API const char * gguf_get_arr_str (struct gguf_context * ctx, int key_id, int i); GGML_API int gguf_get_n_tensors (struct gguf_context * ctx); diff --git a/gguf-llama.cpp b/gguf-llama.cpp index bc9559130..9bf6cc9a9 100644 --- a/gguf-llama.cpp +++ b/gguf-llama.cpp @@ -528,6 +528,7 @@ struct llama_state { llama_log_callback log_callback = llama_log_callback_default; void * log_callback_user_data = nullptr; }; + // global state static llama_state g_state; @@ -647,6 +648,8 @@ struct gguf_file_loader { throw std::runtime_error("cannot find token scores list in GGUF file\n"); } + const float * scores = (const float * ) gguf_get_arr_data(gguf_ctx, score_idx); + for (uint32_t i = 0; i < hparams.n_vocab; i++) { std::string word = gguf_get_arr_str(gguf_ctx, token_idx, i); @@ -654,7 +657,7 @@ struct gguf_file_loader { auto & tok_score = vocab.id_to_token[i]; tok_score.tok = std::move(word); - tok_score.score = gguf_get_arr_f32(gguf_ctx, score_idx, i); + tok_score.score = scores[i]; } }