gguf : remove obosolete gguf_get_arr_xxx API

This commit is contained in:
Georgi Gerganov 2023-08-15 20:46:18 +03:00
parent 1751bd4693
commit 2906d5492d
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
3 changed files with 9 additions and 5 deletions

4
ggml.c
View file

@ -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]; 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) { 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_kv * kv = &ctx->kv[key_id];
struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i]; struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[i];

5
ggml.h
View file

@ -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_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 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 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 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); 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 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 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 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 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); GGML_API int gguf_get_n_tensors (struct gguf_context * ctx);

View file

@ -528,6 +528,7 @@ struct llama_state {
llama_log_callback log_callback = llama_log_callback_default; llama_log_callback log_callback = llama_log_callback_default;
void * log_callback_user_data = nullptr; void * log_callback_user_data = nullptr;
}; };
// global state // global state
static llama_state g_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"); 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++) { for (uint32_t i = 0; i < hparams.n_vocab; i++) {
std::string word = gguf_get_arr_str(gguf_ctx, token_idx, 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]; auto & tok_score = vocab.id_to_token[i];
tok_score.tok = std::move(word); tok_score.tok = std::move(word);
tok_score.score = gguf_get_arr_f32(gguf_ctx, score_idx, i); tok_score.score = scores[i];
} }
} }