separate kwargs in processor (similar to #30193) (#30905)

* Fix similar bug in processor (related to #30193)

* Reformat processing_git.py to comply with ruff formatting
This commit is contained in:
Eric2i 2024-05-20 02:18:17 -07:00 committed by GitHub
parent 1834916481
commit 7b4b456438
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -76,15 +76,21 @@ class GitProcessor(ProcessorMixin):
`None`).
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
"""
tokenizer_kwargs, image_processor_kwargs = {}, {}
if kwargs:
tokenizer_kwargs = {k: v for k, v in kwargs.items() if k not in self.image_processor._valid_processor_keys}
image_processor_kwargs = {
k: v for k, v in kwargs.items() if k in self.image_processor._valid_processor_keys
}
if text is None and images is None:
raise ValueError("You have to specify either text or images. Both cannot be none.")
if text is not None:
encoding = self.tokenizer(text, return_tensors=return_tensors, **kwargs)
encoding = self.tokenizer(text, return_tensors=return_tensors, **tokenizer_kwargs)
if images is not None:
image_features = self.image_processor(images, return_tensors=return_tensors, **kwargs)
image_features = self.image_processor(images, return_tensors=return_tensors, **image_processor_kwargs)
if text is not None and images is not None:
encoding["pixel_values"] = image_features.pixel_values