Skip to content

Conversation

@sanchit-gandhi
Copy link
Contributor

@sanchit-gandhi sanchit-gandhi commented Sep 14, 2023

What does this PR do?

Fixes #25422: adds a check for the combined length of prompt + max new tokens. If this total exceeds the model's max length (max_target_positions), we throw an error.

cc @connor-henderson @Helene-Maxcici

decoder_start_token_id, *text_prompt_ids = prompt_ids
# Slicing the text prompt ids in a manner consistent with the OpenAI implementation
# to accomodate context space for the prefix (see https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/decoding.py#L599)
text_prompt_ids = text_prompt_ids[-self.config.max_length // 2 - 1 :]
Copy link
Contributor Author

@sanchit-gandhi sanchit-gandhi Sep 14, 2023

Choose a reason for hiding this comment

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

The equivalent variable for the slicing in the OAI implementation is n_ctx: https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/decoding.py#L599

This corresponds to our max_target_positions:

max_target_positions (`int`, *optional*, defaults to 448):

=> I've corrected this in our implementation. Note that for the pre-trained checkpoints, we set max_length = max_target_positions, so this won't change the behaviour here.

However, it will fix the behaviour for newly initialised checkpoints, where max_length does not match max_target_positions (former defaults to 20, latter defaults to 448).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 14, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Nice! It's not backward comp but it's fix as you mentioned so let's go with this! 💉

@sanchit-gandhi sanchit-gandhi merged commit c7b4d0b into huggingface:main Sep 15, 2023
@sanchit-gandhi sanchit-gandhi deleted the whisper-max-len branch September 15, 2023 14:46
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
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.

Whisper Prompting max_new_tokens

3 participants