-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Whisper] Refactor whisper #21252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ArthurZucker
merged 17 commits into
huggingface:main
from
ArthurZucker:refactor-whisper
Jan 25, 2023
+231
−55
Merged
[Whisper] Refactor whisper #21252
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ffb6350
update whisper logit processor
ArthurZucker 68b7f71
add generate for whisper
ArthurZucker 9237431
remove part of the whisper specific code from pipeline
ArthurZucker 4dda544
update logit processes
ArthurZucker bd5b1e8
Merge branch 'main' of https://github.com/huggingface/transformers in…
ArthurZucker d2f3e16
Merge branch 'main' of https://github.com/huggingface/transformers in…
ArthurZucker 6fbb110
major update
ArthurZucker 19c7c97
enforce first timestamp
ArthurZucker 35a810f
update generate
ArthurZucker 60b7575
add more tests
ArthurZucker e455131
update new decoding strategy
ArthurZucker 8bd6ee8
Merge branch 'main' of https://github.com/huggingface/transformers in…
ArthurZucker 148f077
Apply suggestions from code review
ArthurZucker 7a40626
update docstring
ArthurZucker b6ec3c4
fixup
ArthurZucker b14b6c8
default config will not have multilingual ar
ArthurZucker b20a59b
update expected tokenizer size, see pull on the hub for whisper-tiny
ArthurZucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,6 @@ | |
| logger = logging.get_logger(__name__) | ||
|
|
||
| if is_torch_available(): | ||
| from transformers.generation.logits_process import WhisperTimeStampLogitsProcessor | ||
|
|
||
| from ..models.auto.modeling_auto import MODEL_FOR_CTC_MAPPING, MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING | ||
|
|
||
|
|
||
|
|
@@ -413,13 +411,6 @@ def _sanitize_parameters( | |
| if return_timestamps is not None: | ||
| forward_params["return_timestamps"] = return_timestamps | ||
| postprocess_params["return_timestamps"] = return_timestamps | ||
| if self.model.config.model_type == "whisper": | ||
| # Whisper is highly specific, if we want timestamps, we need to | ||
| # force whisper to output timestamp tokens, which means we need | ||
| # to set this variable to prevent `no_timestamp_token` to be | ||
| # used in the decoder. | ||
| if "forced_decoder_ids" not in forward_params.get("generate_kwargs", {}): | ||
| forward_params["generate_kwargs"]["forced_decoder_ids"] = None | ||
|
|
||
| return preprocess_params, forward_params, postprocess_params | ||
|
|
||
|
|
@@ -529,10 +520,11 @@ def preprocess(self, inputs, chunk_length_s=0, stride_length_s=None, ignore_warn | |
| def _forward(self, model_inputs, return_timestamps=False, generate_kwargs=None): | ||
| if generate_kwargs is None: | ||
| generate_kwargs = {} | ||
|
|
||
| if return_timestamps and self.type == "seq2seq_whisper": | ||
| generate_kwargs["return_timestamps"] = return_timestamps | ||
| is_last = model_inputs.pop("is_last") | ||
|
|
||
| if self.type == "seq2seq": | ||
| if self.type in {"seq2seq", "seq2seq_whisper"}: | ||
| encoder = self.model.get_encoder() | ||
| # Consume values so we can let extra information flow freely through | ||
| # the pipeline (important for `partial` in microphone) | ||
|
|
@@ -557,16 +549,10 @@ def _forward(self, model_inputs, return_timestamps=False, generate_kwargs=None): | |
| **generate_kwargs, | ||
| ) | ||
| out = {"tokens": tokens} | ||
| elif self.type == "seq2seq_whisper": | ||
| stride = model_inputs.pop("stride", None) | ||
| tokens = self.model.generate( | ||
| input_features=model_inputs.pop("input_features"), | ||
| logits_processor=[WhisperTimeStampLogitsProcessor()] if return_timestamps else None, | ||
| **generate_kwargs, | ||
| ) | ||
| out = {"tokens": tokens} | ||
| if stride is not None: | ||
| out["stride"] = stride | ||
| if self.type == "seq2seq_whisper": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed to If there's no need for it to pop before we can simplify be simply setting something like:
|
||
| stride = model_inputs.pop("stride", None) | ||
| if stride is not None: | ||
| out["stride"] = stride | ||
|
|
||
| else: | ||
| stride = model_inputs.pop("stride", None) | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we first introduced the generation config. Unless the task and language were passed as inputs, we'd default to speech transcription with language detection