whisper: opt-in adaptive encoder window for short-form audio (~3x on short clips) - #149
Open
random1st wants to merge 1 commit into
Open
whisper: opt-in adaptive encoder window for short-form audio (~3x on short clips)#149random1st wants to merge 1 commit into
random1st wants to merge 1 commit into
Conversation
Whisper encodes a fixed 30 s window, so a 4 s utterance pays for 26 s of silence: measured encode cost is a flat ~275 ms per clip at any length (M3 Max, Metal, large-v3-turbo Q8_0). The encoder graph is already rebuilt per window — run_whisper_encoder_on_window takes n_mel_frames and reallocates on T_enc change — so the window can be sized to the audio instead. On 2-6 s utterances this cut end-to-end latency ~3x in our deployment. Only short-form is touched, deliberately. Shrinking the window globally also re-chunks long-form, and that destroys it (measured: long-form Russian WER 4.31% -> 85.34% at a 20 s window) — the seek/stitch path assumes the native window size. Positional embeddings were trained at 30 s, so a shorter window is a real accuracy trade. The feature is therefore opt-in via TRANSCRIBE_ADAPTIVE_WINDOW, with TRANSCRIBE_WINDOW_MIN_SECS (default 10) and TRANSCRIBE_WINDOW_MARGIN_SECS (default 2) so the trade can be priced per deployment. With the default floor of 10 s we measured no WER regression on a 26-clip ru/en/code-switching corpus; clips near the window edge are protected by the margin. Default behaviour is bit-for-bit unchanged: without the env var the window stays at the model's native size for both forms.
Contributor
|
I'll get to reviewing this, but I'm not confident I will pull it in. I do appreciate the thought that went into this, and it's not a wide sweeping set of changes. But I generally don't like adding ENV flags as they feel like a hack, and for the most part I am okay with some latency penalty at the cost of correctness. Especially when there are so many other models to choose from for lower latency |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Whisper's encoder always processes a fixed 30 s window, so a 4 s utterance pays for 26 s of silence. Measured on M3 Max (Metal, large-v3-turbo Q8_0): encode cost is a flat ~275 ms per clip regardless of length. Since
run_whisper_encoder_on_windowalready rebuilds the graph per window (it takesn_mel_framesand reallocates onT_encchange), the window can be sized to the audio instead. On 2–6 s utterances this cut end-to-end latency ~3× in our deployment (a voice assistant, where short utterances dominate).Why opt-in, and why short-form only
is_short_formsizing; long-form is bit-for-bit unchanged.TRANSCRIBE_ADAPTIVE_WINDOW, withTRANSCRIBE_WINDOW_MIN_SECS(default 10) andTRANSCRIBE_WINDOW_MARGIN_SECS(default 2) so each deployment can price the trade. With the default 10 s floor we measured no WER regression on a 26-clip ru/en/code-switching corpus (clean + noisy).Validation
transcribe-cpp-sysbindings (patched crate) on macOS/Metal for several weeks of daily use.enc_max_source_positions, and against odd frame counts.transcribe::envhelpers; no new dependencies.Happy to adjust knobs/naming or move the gate into
run_paramsif you'd prefer a non-env API.