From 06130452b64f2a8e0304dd47a38bd1cae670ca47 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 8 Jan 2023 12:56:02 +0200 Subject: [PATCH] whisper : adding needed for size_t + code style --- whisper.cpp | 8 +++++--- whisper.h | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/whisper.cpp b/whisper.cpp index 51449fb..433b735 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -463,7 +463,7 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con uint32_t magic; read_safe(loader, magic); if (magic != 0x67676d6c) { - fprintf(stderr, "%s: invalid model file (bad magic)\n", __func__); + fprintf(stderr, "%s: invalid model data (bad magic)\n", __func__); return false; } } @@ -2236,7 +2236,7 @@ struct whisper_context * whisper_init_from_file(const char * path_model) { whisper_model_loader loader = {}; fprintf(stderr, "%s: loading model from '%s'\n", __func__, path_model); - + auto fin = std::ifstream(path_model, std::ios::binary); if (!fin) { fprintf(stderr, "%s: failed to open '%s'\n", __func__, path_model); @@ -2276,6 +2276,7 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s fprintf(stderr, "%s: loading model from buffer\n", __func__); loader.context = &ctx; + loader.read = [](void * ctx, void * output, size_t read_size) { buf_context * buf = reinterpret_cast(ctx); @@ -2293,7 +2294,7 @@ struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_s return buf->current_offset >= buf->size; }; - loader.close = [](void * ctx) { }; + loader.close = [](void * /*ctx*/) { }; return whisper_init(&loader); } @@ -2315,6 +2316,7 @@ struct whisper_context * whisper_init(struct whisper_model_loader * loader) { } ctx->t_load_us = ggml_time_us() - t_start_us; + loader->close(loader->context); return ctx; diff --git a/whisper.h b/whisper.h index f38d3aa..582138f 100644 --- a/whisper.h +++ b/whisper.h @@ -1,6 +1,7 @@ #ifndef WHISPER_H #define WHISPER_H +#include #include #include @@ -85,15 +86,16 @@ extern "C" { } whisper_token_data; typedef struct whisper_model_loader { - void* context; + void * context; size_t (*read)(void * ctx, void * output, size_t read_size); - bool (*eof)(void * ctx); - void (*close)(void * ctx); + bool (*eof)(void * ctx); + void (*close)(void * ctx); } whisper_model_loader; - // Allocates all memory needed for the model and loads the model from the given file. - // Returns NULL on failure. + // Various function to load a ggml whisper model. + // Allocates (almost) all memory needed for the model. + // Return NULL on failure WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model); WHISPER_API struct whisper_context * whisper_init_from_buffer(void * buffer, size_t buffer_size); WHISPER_API struct whisper_context * whisper_init(struct whisper_model_loader * loader);