Repository navigation
feat(bridge): generate() for Whisper - #1970
Merged
Merged
Conversation
bridge.generate(input_features) now transcribes:
bridge.tokenizer.set_prefix_tokens(language="english", task="transcribe")
bridge.generate(input_features, do_sample=False, return_type="str")
- Takes the audio features tensor. The decoder starts from decoder_input
(one row shared by every clip, or one per clip) or, by default, the
tokenizer's prefix tokens. Returns the decoder tokens, prompt included;
return_type="str" gives the transcripts.
- Encodes the audio once per call, as HF's generate does, instead of once per
token. Encoder hooks fire on that pass and decoder hooks every step. The pass
sets output_attentions=False so HF does not hold every layer's attention
weights: two whisper-large-v3-turbo clips now peak at 5.6 GB instead of
running out of memory at 15 GB.
- The encoder-decoder loop applies generation_config.suppress_tokens and
begin_suppress_tokens with transformers' own processors, as HF's generate
does by default. Whisper sets both.
- A prompt plus max_new_tokens beyond the decoder's positions raises, and so
does text input. generate_stream raises NotImplementedError for audio seq2seq.
- hf_generate sends temperature only when sampling. Whisper's generate samples
whenever it gets a temperature above 0, so greedy hf_generate calls sampled.
Greedy output matches HF's Whisper generate token for token on two LibriSpeech
clips, with whisper-tiny and whisper-large-v3-turbo.
Tests: tiny random-weight parity against HF's GenerationMixin.generate (default
and explicit prompts, suppressed tokens, string output, encoder hooks once and
decoder hooks every step, error paths); slow whisper-tiny parity against HF's
Whisper generate and through hf_generate; a unit test for the temperature change.
Part of TransformerLensOrg#1938
Collaborator
|
Looks good @dipo101, thank you for putting this together! |
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.
bridge.generate(input_features) now transcribes:
Greedy output matches HF's Whisper generate token for token on two LibriSpeech clips, with whisper-tiny and whisper-large-v3-turbo.
Tests: tiny random-weight parity against HF's GenerationMixin.generate (default and explicit prompts, suppressed tokens, string output, encoder hooks once and decoder hooks every step, error paths); slow whisper-tiny parity against HF's Whisper generate and through hf_generate; a unit test for the temperature change.
Part of #1938
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist: