Skip to content

Commit 05042a7

Browse files
authored
Revert "whisper : remove extra backend instance (huh?)" (ggml-org#2182)
This reverts commit 4caa64b.
1 parent a7dc2aa commit 05042a7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

whisper.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ struct whisper_state {
818818

819819
whisper_decoder decoders[WHISPER_MAX_DECODERS];
820820

821+
ggml_backend_t backend = nullptr;
822+
821823
// ggml-alloc:
822824
// - stores meta info about the intermediate tensors into the `meta` buffers
823825
// - stores the actual tensor data into the `data` buffers
@@ -2261,7 +2263,7 @@ static bool whisper_encode_internal(
22612263
}
22622264

22632265
if (!whisper_encode_external(wstate)) {
2264-
if (!ggml_graph_compute_helper(wctx.backend, gf, n_threads)) {
2266+
if (!ggml_graph_compute_helper(wstate.backend, gf, n_threads)) {
22652267
return false;
22662268
}
22672269
} else {
@@ -2284,7 +2286,7 @@ static bool whisper_encode_internal(
22842286
return false;
22852287
}
22862288

2287-
if (!ggml_graph_compute_helper(wctx.backend, gf, n_threads)) {
2289+
if (!ggml_graph_compute_helper(wstate.backend, gf, n_threads)) {
22882290
return false;
22892291
}
22902292
}
@@ -2300,7 +2302,7 @@ static bool whisper_encode_internal(
23002302
return false;
23012303
}
23022304

2303-
if (!ggml_graph_compute_helper(wctx.backend, gf, n_threads)) {
2305+
if (!ggml_graph_compute_helper(wstate.backend, gf, n_threads)) {
23042306
return false;
23052307
}
23062308
}
@@ -2801,7 +2803,7 @@ static bool whisper_decode_internal(
28012803

28022804
logits = gf->nodes[gf->n_nodes - 1];
28032805

2804-
if (!ggml_graph_compute_helper(wctx.backend, gf, n_threads)) {
2806+
if (!ggml_graph_compute_helper(wstate.backend, gf, n_threads)) {
28052807
return false;
28062808
}
28072809
}
@@ -3248,6 +3250,13 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
32483250

32493251
whisper_state * state = new whisper_state;
32503252

3253+
state->backend = whisper_backend_init(ctx->params);
3254+
if (!state->backend) {
3255+
WHISPER_LOG_ERROR("%s: whisper_backend_init() failed\n", __func__);
3256+
whisper_free_state(state);
3257+
return nullptr;
3258+
}
3259+
32513260
// at this point, we don't know yet how many decoders will be used, so we overallocate 3x ctx
32523261
// in theory, there can be a case where this is not enough, but in practice it should always be enough
32533262
const int factor = 3;
@@ -3684,6 +3693,8 @@ void whisper_free_state(struct whisper_state * state) {
36843693
ggml_gallocr_free(state->alloc_cross.alloc);
36853694
ggml_gallocr_free(state->alloc_decode.alloc);
36863695

3696+
ggml_backend_free(state->backend);
3697+
36873698
// [EXPERIMENTAL] Token-level timestamps with DTW
36883699
aheads_masks_free(state->aheads_masks);
36893700

0 commit comments

Comments
 (0)