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

Make AutoProcessor a magic loading class for all modalities #18963

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Sep 9, 2022

What does this PR do?

This PR re-enables a feature initially part of #14465 : the fact that AutoProcessor is a class loading the right processing class for any model (so processor, tokenizer or feature extractor). You can thus do:

processor = AutoProcessor.from_pretrained("bert-base-cased")
# Returns a fast BERT tokenizer

or

processor = AutoProcessor.from_pretrained("facebook/convnext-tiny-224")
# Returns a fConvNext feature extractor

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 9, 2022

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

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Thank you for your PR! Simple and elegant. I can't think of a repository that would have a feature extractor and a tokenizer, but no processor.

Looks good to me! @patrickvonplaten, could you give it a look?

# At this stage, there doesn't seem to be a `Processor` class available for this model, so let's try a
# tokenizer.
try:
return AutoTokenizer.from_pretrained(
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the order doesn't matter too much here since if both tokenizer and feature extractor would be present then the model also should have a processor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I don't see when we could have both without a processor.

Copy link
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.

Thanks for re-enabling this!

@sgugger sgugger merged commit 6f8f2f6 into main Sep 14, 2022
@sgugger sgugger deleted the auto_processor_magic branch September 14, 2022 11:36
oneraghavan pushed a commit to oneraghavan/transformers that referenced this pull request Sep 26, 2022
…ace#18963)

* Make AutoProcessor a magic loading class for all modalities

* Quality
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.

None yet

4 participants