Skip to content

Commit ef73811

Browse files
yonigozlanzucchini-nlp
authored andcommitted
🚨Deprecate legacy argument for image-text-to-text models and adopt new behavior by default (huggingface#36307)
* deprecate legacy argument and adopt new behavior by default * revert back modification git
1 parent 636e9c2 commit ef73811

File tree

3 files changed

+2
-34
lines changed

3 files changed

+2
-34
lines changed

‎src/transformers/models/donut/processing_donut.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ def __call__(
8888
[`~DonutProcessor.as_target_processor`] this method forwards all its arguments to DonutTokenizer's
8989
[`~DonutTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information.
9090
"""
91-
# For backward compatibility
92-
legacy = kwargs.pop("legacy", True)
93-
if legacy:
94-
# With `add_special_tokens=True`, the performance of donut are degraded when working with both images and text.
95-
logger.warning_once(
96-
"Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
97-
"In the new behavior, if both images and text are provided, the default value of `add_special_tokens` "
98-
"will be changed to `False` when calling the tokenizer if `add_special_tokens` is unset. "
99-
"To test the new behavior, set `legacy=False`as a processor call argument."
100-
)
101-
10291
if self._in_target_context_manager:
10392
return self.current_processor(images, text, **kwargs)
10493

@@ -114,7 +103,7 @@ def __call__(
114103
if images is not None:
115104
inputs = self.image_processor(images, **output_kwargs["images_kwargs"])
116105
if text is not None:
117-
if not legacy and images is not None:
106+
if images is not None:
118107
output_kwargs["text_kwargs"].setdefault("add_special_tokens", False)
119108
encodings = self.tokenizer(text, **output_kwargs["text_kwargs"])
120109

‎src/transformers/models/git/processing_git.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@ def __call__(
9595
`None`).
9696
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
9797
"""
98-
legacy = kwargs.pop("legacy", True)
99-
if legacy:
100-
logger.warning_once(
101-
"Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
102-
"In the new behavior, if both images and text are provided, the last token (EOS token) "
103-
"of the input_ids and attention_mask tensors will be removed. "
104-
"To test the new behavior, set `legacy=False`as a processor call argument."
105-
)
106-
10798
if text is None and images is None:
10899
raise ValueError("You have to specify either text or images. Both cannot be none.")
109100

@@ -123,9 +114,6 @@ def __call__(
123114
if images is not None:
124115
image_features = self.image_processor(images, **output_kwargs["images_kwargs"])
125116
data.update(image_features)
126-
if not legacy:
127-
data["input_ids"] = data["input_ids"][:, :-1]
128-
data["attention_mask"] = data["attention_mask"][:, :-1]
129117

130118
return BatchFeature(data=data, tensor_type=output_kwargs["common_kwargs"].get("return_tensors"))
131119

‎src/transformers/models/pix2struct/processing_pix2struct.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ def __call__(
8989
9090
Please refer to the docstring of the above two methods for more information.
9191
"""
92-
legacy = kwargs.pop("legacy", True)
93-
if legacy:
94-
logger.warning_once(
95-
"Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. "
96-
"In the new behavior, If both images and text are provided, image_processor is not a VQA processor, and `add_special_tokens` is unset, "
97-
"the default value of `add_special_tokens` will be changed to `False` when calling the tokenizer. "
98-
"To test the new behavior, set `legacy=False`as a processor call argument."
99-
)
100-
10192
if images is None and text is None:
10293
raise ValueError("You have to specify either images or text.")
10394

@@ -126,7 +117,7 @@ def __call__(
126117

127118
if text is not None and not self.image_processor.is_vqa:
128119
output_kwargs["text_kwargs"]["add_special_tokens"] = (
129-
add_special_tokens if add_special_tokens is not None else legacy
120+
add_special_tokens if add_special_tokens is not None else False
130121
)
131122
text_encoding = self.tokenizer(text=text, **output_kwargs["text_kwargs"])
132123

0 commit comments

Comments
 (0)