Skip to content

Commit

Permalink
Change legacy deprecation warning to only show when True
Browse files Browse the repository at this point in the history
  • Loading branch information
yonigozlan committed Oct 31, 2024
1 parent 5772312 commit 61cc576
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/transformers/models/donut/processing_donut.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Processor class for Donut.
"""

import logging
import re
import warnings
from contextlib import contextmanager
Expand All @@ -25,14 +24,14 @@
from ...image_utils import ImageInput
from ...processing_utils import ProcessingKwargs, ProcessorMixin, Unpack
from ...tokenization_utils_base import PreTokenizedInput, TextInput
from ...utils.deprecation import deprecate_kwarg
from ...utils import logging


class DonutProcessorKwargs(ProcessingKwargs, total=False):
_defaults = {}


logger = logging.getLogger(__name__)
logger = logging.get_logger(__name__)


class DonutProcessor(ProcessorMixin):
Expand Down Expand Up @@ -75,7 +74,6 @@ def __init__(self, image_processor=None, tokenizer=None, **kwargs):
self.current_processor = self.image_processor
self._in_target_context_manager = False

@deprecate_kwarg(old_name="legacy", version="5.0.0")
def __call__(
self,
images: ImageInput = None,
Expand All @@ -95,9 +93,10 @@ def __call__(
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 new behavior with legacy=False will be enabled in the future."
"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."
"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:
Expand Down
13 changes: 6 additions & 7 deletions src/transformers/models/git/processing_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
Image/Text processor class for GIT
"""

import logging
from typing import List, Optional, Union

from ...feature_extraction_utils import BatchFeature
from ...image_utils import ImageInput
from ...processing_utils import ProcessingKwargs, ProcessorMixin, Unpack, _validate_images_text_input_order
from ...tokenization_utils_base import PreTokenizedInput, TextInput
from ...utils.deprecation import deprecate_kwarg
from ...utils import logging


class GitProcessorKwargs(ProcessingKwargs, total=False):
_defaults = {}


logger = logging.getLogger(__name__)
logger = logging.get_logger(__name__)


class GitProcessor(ProcessorMixin):
Expand All @@ -55,7 +54,6 @@ def __init__(self, image_processor, tokenizer):
super().__init__(image_processor, tokenizer)
self.current_processor = self.image_processor

@deprecate_kwarg(old_name="legacy", version="5.0.0")
def __call__(
self,
images: Optional[ImageInput] = None,
Expand Down Expand Up @@ -99,10 +97,11 @@ def __call__(
"""
legacy = kwargs.pop("legacy", True)
if legacy:
logger.warning(
"Legacy behavior is being used. The new behavior with legacy=False will be enabled in the future."
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."
"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:
Expand Down
13 changes: 6 additions & 7 deletions src/transformers/models/pix2struct/processing_pix2struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
Processor class for Pix2Struct.
"""

import logging
from typing import List, Optional, Union

from ...feature_extraction_utils import BatchFeature
from ...processing_utils import ImagesKwargs, ProcessingKwargs, ProcessorMixin, Unpack
from ...tokenization_utils_base import BatchEncoding, PreTokenizedInput, TextInput
from ...utils.deprecation import deprecate_kwarg
from ...utils import logging


class Pix2StructImagesKwargs(ImagesKwargs, total=False):
Expand Down Expand Up @@ -50,7 +49,7 @@ class Pix2StructProcessorKwargs(ProcessingKwargs, total=False):
}


logger = logging.getLogger(__name__)
logger = logging.get_logger(__name__)


class Pix2StructProcessor(ProcessorMixin):
Expand All @@ -76,7 +75,6 @@ def __init__(self, image_processor, tokenizer):
tokenizer.return_token_type_ids = False
super().__init__(image_processor, tokenizer)

@deprecate_kwarg(old_name="legacy", version="5.0.0")
def __call__(
self,
images=None,
Expand All @@ -93,10 +91,11 @@ def __call__(
"""
legacy = kwargs.pop("legacy", True)
if legacy:
logger.warning(
"Legacy behavior is being used. The new behavior with legacy=False will be enabled in the future."
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."
"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:
Expand Down

0 comments on commit 61cc576

Please sign in to comment.