From 61cc5767a6e54cfd43911dc8d7d170debb17a6e7 Mon Sep 17 00:00:00 2001 From: yonigozlan Date: Thu, 31 Oct 2024 19:23:03 +0000 Subject: [PATCH] Change legacy deprecation warning to only show when True --- src/transformers/models/donut/processing_donut.py | 11 +++++------ src/transformers/models/git/processing_git.py | 13 ++++++------- .../models/pix2struct/processing_pix2struct.py | 13 ++++++------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/transformers/models/donut/processing_donut.py b/src/transformers/models/donut/processing_donut.py index 3f81d0d61a2b9a..b46ff4bcfab902 100644 --- a/src/transformers/models/donut/processing_donut.py +++ b/src/transformers/models/donut/processing_donut.py @@ -16,7 +16,6 @@ Processor class for Donut. """ -import logging import re import warnings from contextlib import contextmanager @@ -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): @@ -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, @@ -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: diff --git a/src/transformers/models/git/processing_git.py b/src/transformers/models/git/processing_git.py index ecce9ff9df2d82..e9e96fa765d841 100644 --- a/src/transformers/models/git/processing_git.py +++ b/src/transformers/models/git/processing_git.py @@ -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): @@ -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, @@ -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: diff --git a/src/transformers/models/pix2struct/processing_pix2struct.py b/src/transformers/models/pix2struct/processing_pix2struct.py index 90acbd2c247c43..bf02531ffb864f 100644 --- a/src/transformers/models/pix2struct/processing_pix2struct.py +++ b/src/transformers/models/pix2struct/processing_pix2struct.py @@ -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): @@ -50,7 +49,7 @@ class Pix2StructProcessorKwargs(ProcessingKwargs, total=False): } -logger = logging.getLogger(__name__) +logger = logging.get_logger(__name__) class Pix2StructProcessor(ProcessorMixin): @@ -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, @@ -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: