-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios): make option for enable/disable Core ML (#145)
* feat(ios): make option for enable/disable Core ML * fix(ios): use whisper_init_from_file_no_coreml if defined WHISPER_USE_COREML * fix(example): update env * fix(cpp): patch
- Loading branch information
Showing
12 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- whisper.cpp.orig 2023-10-12 11:44:51 | ||
+++ whisper.cpp 2023-10-12 11:43:31 | ||
@@ -770,6 +770,9 @@ | ||
whisper_state * state = nullptr; | ||
|
||
std::string path_model; // populated by whisper_init_from_file() | ||
+#ifdef WHISPER_USE_COREML | ||
+ bool load_coreml = true; | ||
+#endif | ||
}; | ||
|
||
static void whisper_default_log(const char * text) { | ||
@@ -2854,6 +2857,7 @@ | ||
} | ||
|
||
#ifdef WHISPER_USE_COREML | ||
+if (ctx->load_coreml) { // Not in correct layer for easy patch | ||
const auto path_coreml = whisper_get_coreml_path_encoder(ctx->path_model); | ||
|
||
log("%s: loading Core ML model from '%s'\n", __func__, path_coreml.c_str()); | ||
@@ -2869,6 +2873,7 @@ | ||
} else { | ||
log("%s: Core ML model loaded\n", __func__); | ||
} | ||
+} | ||
#endif | ||
|
||
state->logits.reserve(ctx->vocab.n_vocab * ctx->model.hparams.n_text_ctx); | ||
@@ -2987,7 +2992,24 @@ | ||
state->rng = std::mt19937(0); | ||
|
||
return state; | ||
+} | ||
+ | ||
+#ifdef WHISPER_USE_COREML | ||
+struct whisper_context * whisper_init_from_file_no_coreml(const char * path_model) { | ||
+ whisper_context * ctx = whisper_init_from_file_no_state(path_model); | ||
+ if (!ctx) { | ||
+ return nullptr; | ||
+ } | ||
+ ctx->load_coreml = false; | ||
+ ctx->state = whisper_init_state(ctx); | ||
+ if (!ctx->state) { | ||
+ whisper_free(ctx); | ||
+ return nullptr; | ||
+ } | ||
+ | ||
+ return ctx; | ||
} | ||
+#endif | ||
|
||
int whisper_ctx_init_openvino_encoder( | ||
struct whisper_context * ctx, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- whisper.h.orig 2023-10-12 10:41:41 | ||
+++ whisper.h 2023-10-12 10:38:11 | ||
@@ -99,6 +99,9 @@ | ||
// Various functions for loading a ggml whisper model. | ||
// Allocate (almost) all memory needed for the model. | ||
// Return NULL on failure | ||
+#ifdef WHISPER_USE_COREML | ||
+ WHISPER_API struct whisper_context * whisper_init_from_file_no_coreml(const char * path_model); | ||
+#endif | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters