Skip to content

whisper : run encoder_begin_callback on the language auto-detect path - #3936

Merged
danbev merged 1 commit into
ggml-org:masterfrom
javierdejesusda:lang-detect-encoder-callback
Sep 8, 2026
Merged

danbev merged 1 commit into
ggml-org:masterfrom
javierdejesusda:lang-detect-encoder-callback

Conversation

@javierdejesusda

Copy link
Copy Markdown
Contributor

encoder_begin_callback is documented as a hook to abort before the encoder runs, but on the language auto-detection path it never gets consulted. When language is null/empty/"auto" or detect_language is set, whisper_full_with_state calls whisper_lang_auto_detect_with_state, which runs the encoder without ever checking the callback. So a caller that returns false to cancel gets ignored during auto-detect and the encode proceeds anyway.

This invokes encoder_begin_callback (when set) right before whisper_lang_auto_detect_with_state. If it returns false, we log and return -3, the same abort behavior already used for the encoder call later in the function. The non-auto-detect paths are unchanged.

Verified against current master that the auto-detect path previously reached the encoder with no callback consultation, and that the callback now fires first and aborts cleanly when it returns false. No automated test added since it is a small control-flow guard.

The language auto-detect path in whisper_full_with_state ran the encoder
without firing encoder_begin_callback, unlike the main transcription loop.
Callers that gate, observe, or abort whisper's encode through the callback
had no control over the auto-detection pass. Guard the auto-detect encode
with the callback the same way the main loop does.

Fixes ggml-org#3888

@danbev danbev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note that this does not fully resolve #3888, that would require to also add the abort_callback and user data to be passed down to the encode and decode functions.

@danbev
danbev merged commit c44b60b into ggml-org:master Sep 8, 2026
bygreencn added a commit to bygreencn/whisper.cpp that referenced this pull request Sep 8, 2026
* ggerganov/master:
  whisper : call encoder_begin_callback before language auto-detect (ggml-org#3936)
  whisper : re-seed decoder 0 between calls (ggml-org#4025)
  ci : update close-issue job to not close issues (ggml-org#4045)
  tests : load backends before init when built with GGML_BACKEND_DL (ggml-org#4031)
  server : return language in detect response (ggml-org#4035)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants