Skip to content
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

Generate: models with custom generate() return True in can_generate() #25838

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

gante
Copy link
Member

@gante gante commented Aug 29, 2023

What does this PR do?

See discussion in #25532

This PR updates GenerationMixin.can_generate() to also return True when a model has a custom generate() -- which means that the model is allowed to call generate(). While at it, removes a few overloads, as they are redundant with the change in the PR ✂️

Additional context: ALL models have a generate() function defined, as the mixin is added to all models. This function is a helper to detect when the model class is compatible with generate() or not.


Double-checking with code:

from transformers import Blip2ForConditionalGeneration, BertForQuestionAnswering, BarkFineModel, BarkModel, SpeechT5ForTextToSpeech

print(Blip2ForConditionalGeneration.can_generate())
print(BarkFineModel.can_generate())
print(BarkModel.can_generate())
print(SpeechT5ForTextToSpeech.can_generate())
print(BertForQuestionAnswering.can_generate())  # sanity check: this one can't generate

After this PR, this prints True in all cases except the last one, as expected.

@gante gante requested a review from amyeroberts August 29, 2023 17:27
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 29, 2023

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

@gante gante changed the title Generate: models with custom generate() return true in can_generate() Generate: models with custom generate() return True in can_generate() Aug 29, 2023
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for the update and tidying this up ❤️

@gante gante merged commit 07998ef into huggingface:main Aug 29, 2023
@gante gante deleted the can_generate_upgrade branch August 29, 2023 19:10
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.

3 participants