Repository: huggingface/transformers
Pull request: 🚨Deprecate legacy argument for image-text-to-text models and adopt new behavior by default

# What does this PR do?

The legacy kwarg, behavior and the corresponding warnings have been out in the library for a while. The original deprecation version was 5.0.0, but as it is causing issues with remote_code models such as https://github.com/huggingface/transformers/issues/36106 amongst others, it might be time to remove it now?
Other issue, the kwarg was removed from the image-text-to-text pipeline (inadvertently by me 😐) where it should be set to False by default, so right now the behavior in the pipeline for model that do use the legacy argument is not as it should be.
The models using the legacy kwarg are the following: Donut, Git, Pix2Struct.
They are quite old models, and hopefully users have had the time to see the deprecation warnings, but putting 🚨 as it will still change some default behaviors.


Changed files:
filename: src/transformers/models/donut/processing_donut.py
patch: @@ -88,17 +88,6 @@ def __call__(
         [`~DonutProcessor.as_target_processor`] this method forwards all its arguments to DonutTokenizer's
         [`~DonutTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information.
         """
-        # For backward compatibility
-        legacy = kwargs.pop("legacy", True)
-        if legacy:
-            # With `add_special_tokens=True`, the performance of donut are degraded when working with both images and text.
-            logger.warning_once(
-                "Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
-                "In the new behavior, if both images and text are provided, the default value of `add_special_tokens` "
-                "will be changed to `False` when calling the tokenizer if `add_special_tokens` is unset. "
-                "To test the new behavior, set `legacy=False`as a processor call argument."
-            )
-
         if self._in_target_context_manager:
             return self.current_processor(images, text, **kwargs)
 
@@ -114,7 +103,7 @@ def __call__(
         if images is not None:
             inputs = self.image_processor(images, **output_kwargs["images_kwargs"])
         if text is not None:
-            if not legacy and images is not None:
+            if images is not None:
                 output_kwargs["text_kwargs"].setdefault("add_special_tokens", False)
             encodings = self.tokenizer(text, **output_kwargs["text_kwargs"])
 

filename: src/transformers/models/git/processing_git.py
patch: @@ -95,15 +95,6 @@ def __call__(
               `None`).
             - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
         """
-        legacy = kwargs.pop("legacy", True)
-        if legacy:
-            logger.warning_once(
-                "Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
-                "In the new behavior, if both images and text are provided, the last token (EOS token) "
-                "of the input_ids and attention_mask tensors will be removed. "
-                "To test the new behavior, set `legacy=False`as a processor call argument."
-            )
-
         if text is None and images is None:
             raise ValueError("You have to specify either text or images. Both cannot be none.")
 
@@ -123,9 +114,6 @@ def __call__(
         if images is not None:
             image_features = self.image_processor(images, **output_kwargs["images_kwargs"])
             data.update(image_features)
-            if not legacy:
-                data["input_ids"] = data["input_ids"][:, :-1]
-                data["attention_mask"] = data["attention_mask"][:, :-1]
 
         return BatchFeature(data=data, tensor_type=output_kwargs["common_kwargs"].get("return_tensors"))
 

filename: src/transformers/models/pix2struct/processing_pix2struct.py
patch: @@ -89,15 +89,6 @@ def __call__(
 
         Please refer to the docstring of the above two methods for more information.
         """
-        legacy = kwargs.pop("legacy", True)
-        if legacy:
-            logger.warning_once(
-                "Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
-                "In the new behavior, If both images and text are provided, image_processor is not a VQA processor, and `add_special_tokens` is unset, "
-                "the default value of `add_special_tokens` will be changed to `False` when calling the tokenizer. "
-                "To test the new behavior, set `legacy=False`as a processor call argument."
-            )
-
         if images is None and text is None:
             raise ValueError("You have to specify either images or text.")
 
@@ -126,7 +117,7 @@ def __call__(
 
         if text is not None and not self.image_processor.is_vqa:
             output_kwargs["text_kwargs"]["add_special_tokens"] = (
-                add_special_tokens if add_special_tokens is not None else legacy
+                add_special_tokens if add_special_tokens is not None else False
             )
             text_encoding = self.tokenizer(text=text, **output_kwargs["text_kwargs"])