Skip to content

Commit d93ce40

Browse files
Add an env var to set the self attn text context factor
Add an env var to set the text context factor WHISPER_SELFATTN_CACHE_TEXT_CTX_FACTOR same default to 3. Resolve: ggerganov#2334
1 parent 69339af commit d93ce40

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/whisper.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static bool whisper_kv_cache_find_slot(
10051005
}
10061006

10071007
if (n_tested >= n_ctx) {
1008-
//WHISPER_LOG_ERROR("%s: failed to find a slot for %d tokens\n", __func__, n_tokens);
1008+
WHISPER_LOG_ERROR("%s: failed to find a slot for %d tokens. n_tested=%d n_ctx=%d cache.head=%d\n", __func__, n_tokens, n_tested, n_ctx, cache.head);
10091009
return false;
10101010
}
10111011
}
@@ -3409,8 +3409,11 @@ struct whisper_state * whisper_init_state(whisper_context * ctx) {
34093409
}
34103410

34113411
// at this point, we don't know yet how many decoders will be used, so we overallocate 3x ctx
3412-
// in theory, there can be a case where this is not enough, but in practice it should always be enough
3413-
const int factor = 3;
3412+
// Note: there are cases where 3 is not enough specially when increasing beamsize
3413+
static const char* text_ctx_factor_evstr = getenv("WHISPER_SELFATTN_CACHE_TEXT_CTX_FACTOR");
3414+
static const int text_ctx_factor_ev = text_ctx_factor_evstr ? atoi(text_ctx_factor_evstr) : 0;
3415+
const int factor = text_ctx_factor_ev > 0 ? text_ctx_factor_ev : 3;
3416+
WHISPER_LOG_DEBUG("%s: init self-attn cache: n_ctx: %d factor: %d\n", __func__, factor*ctx->model.hparams.n_text_ctx, factor);
34143417

34153418
if (!whisper_kv_cache_init(state->kv_self, state->backends[0], ctx->itype,
34163419
ctx->model.hparams.n_text_state,

0 commit comments

Comments
 (0)