-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Using assistant in AutomaticSpeechRecognitionPipeline with different encoder size #30637
Using assistant in AutomaticSpeechRecognitionPipeline with different encoder size #30637
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thanks for taking this up @kamilakesbi - left some comments below!
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.
Small comment regarding the generality of the check (note that in generation/utils.py
, we are assuming that all checks + functionality can be applied to all models in the library that are generate-compatible, not just speech recognition ones)
Is there a test that confirms correctness after the fix? There's likely a relevant slow pipeline test that was either failing, or was not rigorous enough |
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.
Pipeline changes LGTM, just some minor suggestions regarding the slow tests. Would love a second opinion from generate expert @gante on the assistant model validation!
I think this PR is ready to be merged! cc @amyeroberts @gante if you want to have a look ;) |
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.
Thanks for working on this!
I've just done a quick pass over and have some outstanding Qs. I'll review again once @gante has confirmed the update to the generation validation is OK
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.
LGTM, thank you for fixing! 💪 I've added a few minor nits to help with readability.
(I see that you've included the diff from #30726, I'm going to close that PR :D)
Thanks @gante for the review :) |
@kamilakesbi It still needs a final core maintainer review and approval before merge (+ resolution of conflicts) :). I'll review now |
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.
Thanks for adding and iterating on this!
Only thing left to add are tests for _validate_assistant
- there should be tests making sure that it correctly raises exceptions for the two cases it's checking for
hi @amyeroberts, I've added a slow test which pass :) I think quality checks fails are unrelated to this PR, and will be fixed by #30932. |
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.
Thanks for adding the tests - looks great!
Quick checklist before merge:
|
f8fad64
to
2c48d6c
Compare
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: Sanchit Gandhi <[email protected]>
Co-authored-by: amyeroberts <[email protected]>
Co-authored-by: amyeroberts <[email protected]>
Co-authored-by: Joao Gante <[email protected]>
Co-authored-by: Joao Gante <[email protected]>
Co-authored-by: Joao Gante <[email protected]>
06e5839
to
3a35145
Compare
Nice work @kamilakesbi! |
…encoder size (#30637) * fiw input to generate in pipeline * fixup * pass input_features to generate with assistant * error if model and assistant with different enc size * fix * apply review suggestions * use self.config.is_encoder_decoder * pass inputs to generate directly * add slow tests * Update src/transformers/generation/utils.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * apply review * Update src/transformers/generation/utils.py Co-authored-by: amyeroberts <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: amyeroberts <[email protected]> * apply code review * update attributes encoder_xyz to check * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * add slow test * solve conflicts --------- Co-authored-by: Sanchit Gandhi <[email protected]> Co-authored-by: amyeroberts <[email protected]> Co-authored-by: Joao Gante <[email protected]>
…encoder size (huggingface#30637) * fiw input to generate in pipeline * fixup * pass input_features to generate with assistant * error if model and assistant with different enc size * fix * apply review suggestions * use self.config.is_encoder_decoder * pass inputs to generate directly * add slow tests * Update src/transformers/generation/utils.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: Sanchit Gandhi <[email protected]> * apply review * Update src/transformers/generation/utils.py Co-authored-by: amyeroberts <[email protected]> * Update tests/pipelines/test_pipelines_automatic_speech_recognition.py Co-authored-by: amyeroberts <[email protected]> * apply code review * update attributes encoder_xyz to check * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * Update src/transformers/generation/utils.py Co-authored-by: Joao Gante <[email protected]> * add slow test * solve conflicts --------- Co-authored-by: Sanchit Gandhi <[email protected]> Co-authored-by: amyeroberts <[email protected]> Co-authored-by: Joao Gante <[email protected]>
This PR aims at fixing issue #30611:
First: an error will be thrown if the assistant and main models encoders don't have the same size, and the assistant is loaded using
AutoModelForCausalLM
.Second: This PR makes the pipeline work when using an assistant with a different encoder size (loaded with
AutoModelForSpeechSeq2Seq
) than the main model:When using AutomaticSpeechRecognitionPipeline, If we use an assistant with a different encoder size than the main model , the pipeline is broken and we get the following error message:
Explanation of the solution
When doing short form generation with the pipeline,
input_features
aren't passed to the generate method, which instead takes the output of the main model's encoder.If the main model and the assistant don't share the same encoder, the encoder_output passed to generate cannot be used by the assistant for generation, and we get an error.
The solution here is to also pass the
input_features
to the generate method to be used by the assistant.Who can review?
@sanchit-gandhi