danbev commited on
Commit
0cae2d6
·
unverified ·
1 Parent(s): 1ee7297

whisper : remove whisper_load_backends function (#3196)

Browse files

* whisper : remove whisper_load_backends function

This commit removes the `whisper_load_backends` function, which was used
to load all GGML backends.

The motivation for this change push the responsibility of loading
backends to user applications to give them more control over which
backends to load and when. See the references below for more context.

Resolves: https://github.com/ggml-org/whisper.cpp/issues/3182
Refs: https://github.com/ggml-org/whisper.cpp/pull/3042#issuecomment-2801778733
Refs: https://github.com/ggml-org/whisper.cpp/pull/3042#issuecomment-2801928990

* ruby : add check for rwc is NULL

This commit adds a check to ensure that the `rwc` pointer is not NULL
before attempting to mark its members in the garbage collector.

The motivation for this is an attempt to see if this fixed the CI build
as I'm not able to reproduce the issue locally.

Refs: https://github.com/ggml-org/whisper.cpp/actions/runs/15299612277/job/43036694928?pr=3196

bindings/ruby/ext/ruby_whisper_params.c CHANGED
@@ -77,6 +77,8 @@ static ID id_vad_params;
77
  static void
78
  rb_whisper_callbcack_container_mark(ruby_whisper_callback_container *rwc)
79
  {
 
 
80
  rb_gc_mark(rwc->user_data);
81
  rb_gc_mark(rwc->callback);
82
  rb_gc_mark(rwc->callbacks);
 
77
  static void
78
  rb_whisper_callbcack_container_mark(ruby_whisper_callback_container *rwc)
79
  {
80
+ if (rwc == NULL) return;
81
+
82
  rb_gc_mark(rwc->user_data);
83
  rb_gc_mark(rwc->callback);
84
  rb_gc_mark(rwc->callbacks);
examples/bench/bench.cpp CHANGED
@@ -156,6 +156,8 @@ static int whisper_bench_full(const whisper_params & params) {
156
  }
157
 
158
  int main(int argc, char ** argv) {
 
 
159
  whisper_params params;
160
 
161
  if (whisper_params_parse(argc, argv, params) == false) {
 
156
  }
157
 
158
  int main(int argc, char ** argv) {
159
+ ggml_backend_load_all();
160
+
161
  whisper_params params;
162
 
163
  if (whisper_params_parse(argc, argv, params) == false) {
examples/cli/cli.cpp CHANGED
@@ -909,6 +909,8 @@ static void output_lrc(struct whisper_context * ctx, std::ofstream & fout, const
909
  static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
910
 
911
  int main(int argc, char ** argv) {
 
 
912
  #if defined(_WIN32)
913
  // Set the console output code page to UTF-8, while command line arguments
914
  // are still encoded in the system's code page. In this way, we can print
@@ -988,7 +990,6 @@ int main(int argc, char ** argv) {
988
  }
989
 
990
  // whisper init
991
-
992
  struct whisper_context_params cparams = whisper_context_default_params();
993
 
994
  cparams.use_gpu = params.use_gpu;
 
909
  static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
910
 
911
  int main(int argc, char ** argv) {
912
+ ggml_backend_load_all();
913
+
914
  #if defined(_WIN32)
915
  // Set the console output code page to UTF-8, while command line arguments
916
  // are still encoded in the system's code page. In this way, we can print
 
990
  }
991
 
992
  // whisper init
 
993
  struct whisper_context_params cparams = whisper_context_default_params();
994
 
995
  cparams.use_gpu = params.use_gpu;
examples/command/command.cpp CHANGED
@@ -678,6 +678,8 @@ static int process_general_transcription(struct whisper_context * ctx, audio_asy
678
  }
679
 
680
  int main(int argc, char ** argv) {
 
 
681
  whisper_params params;
682
 
683
  if (whisper_params_parse(argc, argv, params) == false) {
 
678
  }
679
 
680
  int main(int argc, char ** argv) {
681
+ ggml_backend_load_all();
682
+
683
  whisper_params params;
684
 
685
  if (whisper_params_parse(argc, argv, params) == false) {
examples/lsp/lsp.cpp CHANGED
@@ -424,6 +424,8 @@ static void process_loop(struct whisper_context * ctx, audio_async &audio, const
424
  }
425
 
426
  int main(int argc, char ** argv) {
 
 
427
  whisper_params params;
428
  if (whisper_params_parse(argc, argv, params) == false) {
429
  return 1;
 
424
  }
425
 
426
  int main(int argc, char ** argv) {
427
+ ggml_backend_load_all();
428
+
429
  whisper_params params;
430
  if (whisper_params_parse(argc, argv, params) == false) {
431
  return 1;
examples/quantize/quantize.cpp CHANGED
@@ -1,4 +1,5 @@
1
  #include "ggml.h"
 
2
 
3
  #include "common.h"
4
  #include "common-ggml.h"
@@ -176,6 +177,8 @@ static bool whisper_model_quantize(const std::string & fname_inp, const std::str
176
  }
177
 
178
  int main(int argc, char ** argv) {
 
 
179
  if (argc != 4) {
180
  fprintf(stderr, "usage: %s model-f32.bin model-quant.bin type\n", argv[0]);
181
  ggml_print_ftypes(stderr);
 
1
  #include "ggml.h"
2
+ #include "ggml-backend.h"
3
 
4
  #include "common.h"
5
  #include "common-ggml.h"
 
177
  }
178
 
179
  int main(int argc, char ** argv) {
180
+ ggml_backend_load_all();
181
+
182
  if (argc != 4) {
183
  fprintf(stderr, "usage: %s model-f32.bin model-quant.bin type\n", argv[0]);
184
  ggml_print_ftypes(stderr);
examples/server/server.cpp CHANGED
@@ -516,6 +516,8 @@ void get_req_parameters(const Request & req, whisper_params & params)
516
  } // namespace
517
 
518
  int main(int argc, char ** argv) {
 
 
519
  whisper_params params;
520
  server_params sparams;
521
 
 
516
  } // namespace
517
 
518
  int main(int argc, char ** argv) {
519
+ ggml_backend_load_all();
520
+
521
  whisper_params params;
522
  server_params sparams;
523
 
examples/stream/stream.cpp CHANGED
@@ -116,6 +116,8 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
116
  }
117
 
118
  int main(int argc, char ** argv) {
 
 
119
  whisper_params params;
120
 
121
  if (whisper_params_parse(argc, argv, params) == false) {
 
116
  }
117
 
118
  int main(int argc, char ** argv) {
119
+ ggml_backend_load_all();
120
+
121
  whisper_params params;
122
 
123
  if (whisper_params_parse(argc, argv, params) == false) {
examples/talk-llama/talk-llama.cpp CHANGED
@@ -291,6 +291,8 @@ The transcript only includes text, it does not include markup like HTML and Mark
291
  {0}{4})";
292
 
293
  int main(int argc, char ** argv) {
 
 
294
  whisper_params params;
295
 
296
  if (whisper_params_parse(argc, argv, params) == false) {
 
291
  {0}{4})";
292
 
293
  int main(int argc, char ** argv) {
294
+ ggml_backend_load_all();
295
+
296
  whisper_params params;
297
 
298
  if (whisper_params_parse(argc, argv, params) == false) {
examples/vad-speech-segments/speech.cpp CHANGED
@@ -83,6 +83,8 @@ static bool vad_params_parse(int argc, char ** argv, cli_params & params) {
83
  static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
84
 
85
  int main(int argc, char ** argv) {
 
 
86
  cli_params cli_params;
87
 
88
  if (!vad_params_parse(argc, argv, cli_params)) {
 
83
  static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
84
 
85
  int main(int argc, char ** argv) {
86
+ ggml_backend_load_all();
87
+
88
  cli_params cli_params;
89
 
90
  if (!vad_params_parse(argc, argv, cli_params)) {
examples/wchess/wchess.cmd/wchess.cmd.cpp CHANGED
@@ -168,6 +168,8 @@ bool get_audio(std::vector<float> & pcmf32_cur) {
168
  }
169
 
170
  int main(int argc, char ** argv) {
 
 
171
  whisper_params params;
172
 
173
  if (whisper_params_parse(argc, argv, params) == false) {
 
168
  }
169
 
170
  int main(int argc, char ** argv) {
171
+ ggml_backend_load_all();
172
+
173
  whisper_params params;
174
 
175
  if (whisper_params_parse(argc, argv, params) == false) {
src/whisper.cpp CHANGED
@@ -206,15 +206,6 @@ static bool ggml_graph_compute_helper(
206
  return t;
207
  }
208
 
209
- static void whisper_load_backends() {
210
- #ifdef GGML_BACKEND_DL
211
- static std::once_flag flag;
212
- std::call_once(flag, []() {
213
- ggml_backend_load_all();
214
- });
215
- #endif
216
- }
217
-
218
  // TODO: move these functions to ggml-base with support for ggml-backend?
219
 
220
  static ggml_tensor * whisper_set_f32(struct ggml_tensor * t, float v) {
@@ -1322,8 +1313,6 @@ static size_t aheads_masks_nbytes(struct whisper_aheads_masks & aheads_masks) {
1322
  static ggml_backend_t whisper_backend_init_gpu(const whisper_context_params & params) {
1323
  ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);
1324
 
1325
- whisper_load_backends();
1326
-
1327
  ggml_backend_dev_t dev = nullptr;
1328
 
1329
  int cnt = 0;
@@ -4335,8 +4324,6 @@ static int whisper_has_openvino(void) {
4335
  const char * whisper_print_system_info(void) {
4336
  static std::string s;
4337
 
4338
- whisper_load_backends();
4339
-
4340
  s = "";
4341
  s += "WHISPER : ";
4342
  s += "COREML = " + std::to_string(whisper_has_coreml()) + " | ";
@@ -8154,8 +8141,6 @@ WHISPER_API int whisper_bench_ggml_mul_mat(int n_threads) {
8154
  }
8155
 
8156
  WHISPER_API const char * whisper_bench_ggml_mul_mat_str(int n_threads) {
8157
- whisper_load_backends();
8158
-
8159
  static std::string s;
8160
  s = "";
8161
  char strbuf[256];
 
206
  return t;
207
  }
208
 
 
 
 
 
 
 
 
 
 
209
  // TODO: move these functions to ggml-base with support for ggml-backend?
210
 
211
  static ggml_tensor * whisper_set_f32(struct ggml_tensor * t, float v) {
 
1313
  static ggml_backend_t whisper_backend_init_gpu(const whisper_context_params & params) {
1314
  ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);
1315
 
 
 
1316
  ggml_backend_dev_t dev = nullptr;
1317
 
1318
  int cnt = 0;
 
4324
  const char * whisper_print_system_info(void) {
4325
  static std::string s;
4326
 
 
 
4327
  s = "";
4328
  s += "WHISPER : ";
4329
  s += "COREML = " + std::to_string(whisper_has_coreml()) + " | ";
 
8141
  }
8142
 
8143
  WHISPER_API const char * whisper_bench_ggml_mul_mat_str(int n_threads) {
 
 
8144
  static std::string s;
8145
  s = "";
8146
  char strbuf[256];