Skip to content

update attention mask handling#19385

Merged
ArthurZucker merged 2 commits into
huggingface:mainfrom
ArthurZucker:fix-whisper-for-pipeline
Oct 7, 2022
Merged

update attention mask handling#19385
ArthurZucker merged 2 commits into
huggingface:mainfrom
ArthurZucker:fix-whisper-for-pipeline

Conversation

@ArthurZucker
Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes error when using whisper with inference API.

Working script :

>>> from transformers import WhisperForConditionalGeneration, WhisperProcessor, AutomaticSpeechRecognitionPipeline, , load_dataset, AutoModel
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-large")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")

>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")

>>> model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(task="transcribe", language = "en")
>>> model.config.max_length = 224
>>> pipeline = AutomaticSpeechRecognitionPipeline(
    model = model, 
    tokenizer = processor.tokenizer, 
    feature_extractor = processor.feature_extractor)
>>> print(pipeline(ds[0]["audio"]["array"]))
{'text': ' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.'}

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

HuggingFaceDocBuilderDev commented Oct 6, 2022

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

@ArthurZucker ArthurZucker self-assigned this Oct 7, 2022
@ArthurZucker ArthurZucker requested a review from sgugger October 7, 2022 14:22
@ArthurZucker
Copy link
Copy Markdown
Collaborator Author

Using the pipeline wrapper also works : pipe = pipeline("automatic-speech-recognition", model="openai/whisper-medium.en", device=0).

Copy link
Copy Markdown
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing! Pinging @Narsil for the change in pipeline.

@ArthurZucker ArthurZucker merged commit 994b7a4 into huggingface:main Oct 7, 2022
Copy link
Copy Markdown
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Nice!

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.

4 participants