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

Ignore unsupported kwarg in ProcessorMixin call #34285

Merged

Conversation

yonigozlan
Copy link
Member

@yonigozlan yonigozlan commented Oct 21, 2024

What does this PR do?

When a processor kwarg that is not supported by any modality is passed to a ProcessorMixin call, it is added to CommonKwargs whether or not it is supported by the ProcessorMixin's CommonKwargs object.
This means that any kwargs passed to a processor call will that is not supported by any modality will still be added to all modality kwargs, which can lead to errors. Example:

from transformers import LlavaProcessor, LlavaForConditionalGeneration
processor = LlavaProcessor.from_pretrained("llava-hf/llava-interleave-qwen-0.5b-hf")
outputs = processor(text="Hello, my dog is cute", return_tensors="pt", test=True)

gives

output_kwargs: {'text_kwargs': {'padding': False, 'return_tensors': 'pt', 'test': True}, 'images_kwargs': {'return_tensors': 'pt', 'test': True}, 'audio_kwargs': {'return_tensors': 'pt', 'test': True}, 'videos_kwargs': {'return_tensors': 'pt', 'test': True}, 'common_kwargs': {'return_tensors': 'pt', 'test': True}}

And a TypeError

After this fix:

Keyword argument test is not a valid argument for this processor and will be ignored.
output_kwargs {'text_kwargs': {'padding': False, 'return_tensors': 'pt'}, 'images_kwargs': {'return_tensors': 'pt'}, 'audio_kwargs': {'return_tensors': 'pt'}, 'videos_kwargs': {'return_tensors': 'pt'}, 'common_kwargs': {'return_tensors': 'pt'}}

Who can review?

@molbap

@yonigozlan yonigozlan requested a review from molbap October 21, 2024 15:00
Copy link
Contributor

@molbap molbap left a comment

Choose a reason for hiding this comment

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

Just curious, did you try with text/audio processors with overlapping names? No conflict in the handling logic? other than that LGTM! thanks for the fix :)

src/transformers/processing_utils.py Show resolved Hide resolved
@yonigozlan
Copy link
Member Author

@molbap Just tested with Wav2Vec2Processor, No handling conflict to report when using padding or other overlapping names as far as I see ;)

@yonigozlan yonigozlan merged commit fe35073 into huggingface:main Oct 24, 2024
21 of 23 checks passed
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
BernardZach pushed a commit to innovationcore/transformers that referenced this pull request Dec 6, 2024
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