Image + text + audio uniform processors#30511
Open
molbap wants to merge 97 commits intohuggingface:mainfrom
Open
Image + text + audio uniform processors#30511molbap wants to merge 97 commits intohuggingface:mainfrom
molbap wants to merge 97 commits intohuggingface:mainfrom
Conversation
This parameter depends on tokenizers received.
gafrom
reviewed
Aug 7, 2024
| feature_extractor = None | ||
| if "feature_extractor" in kwargs: | ||
| def __init__(self, image_processor=None, tokenizer=None, feature_extractor=None): | ||
| if "feature_extractor": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR is a stab at uniformizing the processors across all transformers models. If we are happy with the design, I'll expand it to all existing models. It only touches on some text + audio and text + images models as experiment subjects. Linked with #28711 which has a larger scope, and several previous discussions with team members.
Usage
As before, kwargs that are passed to processors at
__call__time take priority. However, per-modality processors can be instantiated with their own kwargs, and if they are not overriden at call time, they will serve as defaults.Type hinting of kwargs is preserved if they are passed as structured dictionary entries

It also works with kwargs passed without nesting:

Merging of kwargs and handling priority order is done in
processing_utilsthrough a dedicated method.The order of operations is as follows:
What changes:
ProcessingKwargsTypedDict of kwargs that inherits fromImagesKwargs,TextKwargs, and so on.TypedDictthat does not need to be total. We can expand this typed dict (inprocessing_utils) as processors get uniformized.kwargsset by a user will always override default processing kwargs.call.What that allows:
Limitations:
Tests pass (I think). What's missing:
Who can review?
Models: