-
Notifications
You must be signed in to change notification settings - Fork 33.9k
[🛠️] Fix-whisper-breaking-changes #21965
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
Changes from 5 commits
389f35b
10a2175
25c0711
2262ca6
ea0eca4
5d18c67
a7d706f
f3c4556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,9 +14,9 @@ | |||||
| # limitations under the License. | ||||||
| """ PyTorch Whisper model.""" | ||||||
|
|
||||||
|
|
||||||
| import math | ||||||
| import random | ||||||
| import warnings | ||||||
| from typing import Optional, Tuple, Union | ||||||
|
|
||||||
| import numpy as np | ||||||
|
|
@@ -36,6 +36,7 @@ | |||||
| from ...modeling_utils import PreTrainedModel | ||||||
| from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings | ||||||
| from .configuration_whisper import WhisperConfig | ||||||
| from .tokenization_whisper import TASK_IDS, TO_LANGUAGE_CODE | ||||||
|
|
||||||
|
|
||||||
| logger = logging.get_logger(__name__) | ||||||
|
|
@@ -1504,11 +1505,16 @@ def generate( | |||||
| generation_config = self.generation_config | ||||||
|
|
||||||
| if return_timestamps is not None: | ||||||
| generation_config.return_timestamps = return_timestamps | ||||||
|
|
||||||
| if task is not None: | ||||||
| generation_config.task = task | ||||||
| if not hasattr(generation_config, "no_timestamps_token_id"): | ||||||
| raise ValueError( | ||||||
| "You are trying to return timestamps, but the generation config is not properly set." | ||||||
| "Make sure to initialize the generation config with the correct `no_timestamps_token_id`." | ||||||
| "For more details on how to generate the approtiate config, refer to [#21878](https://github.com/huggingface/transformers/issues/21878)" | ||||||
| ) | ||||||
|
|
||||||
| generation_config.return_timestamps = return_timestamps | ||||||
| else: | ||||||
| generation_config.return_timestamps = False | ||||||
| if is_multilingual is not None: | ||||||
| generation_config.is_multilingual = is_multilingual | ||||||
|
|
||||||
|
|
@@ -1519,18 +1525,37 @@ def generate( | |||||
|
|
||||||
| if hasattr(generation_config, "is_multilingual") and generation_config.is_multilingual: | ||||||
| if hasattr(generation_config, "language"): | ||||||
| forced_decoder_ids.append((1, generation_config.lang_to_id[generation_config.language])) | ||||||
| if generation_config.language in generation_config.lang_to_id.keys(): | ||||||
| language_token = generation_config.language | ||||||
| elif generation_config.language in TO_LANGUAGE_CODE.keys(): | ||||||
| language_token = f"<|{TO_LANGUAGE_CODE[generation_config.language]}|>" | ||||||
| else: | ||||||
| raise ValueError(f"The `{generation_config.language}` language token is not supported.") | ||||||
|
ArthurZucker marked this conversation as resolved.
Outdated
|
||||||
| forced_decoder_ids.append((1, generation_config.lang_to_id[language_token])) | ||||||
| else: | ||||||
| forced_decoder_ids.append((1, None)) | ||||||
|
|
||||||
| if hasattr(generation_config, "task"): | ||||||
| forced_decoder_ids.append((2, generation_config.task_to_id[generation_config.task])) | ||||||
| if generation_config.task in TASK_IDS: | ||||||
| forced_decoder_ids.append((2, generation_config.task_to_id[generation_config.task])) | ||||||
| else: | ||||||
| raise ValueError( | ||||||
| f"The `{generation_config.task}`task is not supported. The task should be one of `{TASK_IDS}`" | ||||||
|
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. Nice |
||||||
| ) | ||||||
| else: | ||||||
| forced_decoder_ids.append((2, generation_config.task_to_id["transcribe"])) | ||||||
|
|
||||||
| if ( | ||||||
| hasattr(generation_config, "return_timestamps") and generation_config.return_timestamps | ||||||
| ) or return_timestamps: | ||||||
| # Legacy code for backward compatibility | ||||||
| if hasattr(self.config, "forced_decoder_ids") and forced_decoder_ids != self.generation.forced_decoder_ids: | ||||||
|
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. Should this be
Suggested change
I think we should favour What I think we should do is only set This way, a user can still control the forced decoder ids using the generate args even if they've set WDYT?
Collaborator
Author
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. Agreed! Thanks for the suggestion |
||||||
| warnings.warn( | ||||||
| "You have modified the pretrained model configuration to control generation. This is a" | ||||||
| " deprecated strategy to control generation and will be removed soon, in a future version." | ||||||
| " Please use a generation configuration file (see" | ||||||
| " https://huggingface.co/docs/transformers/main_classes/text_generation)" | ||||||
| ) | ||||||
| forced_decoder_ids = self.config.forced_decoder_ids | ||||||
|
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. this line is hit when neither |
||||||
|
|
||||||
| if generation_config.return_timestamps: | ||||||
| logits_processor = [WhisperTimeStampLogitsProcessor(generation_config)] | ||||||
| else: | ||||||
| if forced_decoder_ids and forced_decoder_ids[-1][0] != generation_config.no_timestamps_token_id: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Don't think markdown formatting applies to python logger / print statements no? Running the following in a Python shell:
Print Output:
Think we can also point to the specific fix? Up to you!