diff --git a/src/transformers/models/blip/processing_blip.py b/src/transformers/models/blip/processing_blip.py index 7fc154f3483e..f600e8ce27d8 100644 --- a/src/transformers/models/blip/processing_blip.py +++ b/src/transformers/models/blip/processing_blip.py @@ -60,7 +60,6 @@ class BlipProcessor(ProcessorMixin): def __init__(self, image_processor, tokenizer, **kwargs): tokenizer.return_token_type_ids = False super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor def __call__( self, diff --git a/src/transformers/models/blip_2/processing_blip_2.py b/src/transformers/models/blip_2/processing_blip_2.py index abbbeb6ae0a4..40729f4f4501 100644 --- a/src/transformers/models/blip_2/processing_blip_2.py +++ b/src/transformers/models/blip_2/processing_blip_2.py @@ -66,7 +66,6 @@ class Blip2Processor(ProcessorMixin): def __init__(self, image_processor, tokenizer, num_query_tokens=None, **kwargs): tokenizer.return_token_type_ids = False - self.current_processor = image_processor if not hasattr(tokenizer, "image_token"): self.image_token = AddedToken("", normalized=False, special=True) tokenizer.add_tokens([self.image_token], special_tokens=True) diff --git a/src/transformers/models/chinese_clip/processing_chinese_clip.py b/src/transformers/models/chinese_clip/processing_chinese_clip.py index c6fb9f9df247..0510b9b0f3c9 100644 --- a/src/transformers/models/chinese_clip/processing_chinese_clip.py +++ b/src/transformers/models/chinese_clip/processing_chinese_clip.py @@ -16,8 +16,6 @@ Image/Text processor class for Chinese-CLIP """ -import warnings - from ...processing_utils import ProcessorMixin @@ -41,27 +39,7 @@ class ChineseCLIPProcessor(ProcessorMixin): tokenizer_class = ("BertTokenizer", "BertTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class __all__ = ["ChineseCLIPProcessor"] diff --git a/src/transformers/models/clip/processing_clip.py b/src/transformers/models/clip/processing_clip.py index 893346e798bb..7b856f9981ee 100644 --- a/src/transformers/models/clip/processing_clip.py +++ b/src/transformers/models/clip/processing_clip.py @@ -16,8 +16,6 @@ Image/Text processor class for CLIP """ -import warnings - from ...processing_utils import ProcessorMixin @@ -40,34 +38,7 @@ class CLIPProcessor(ProcessorMixin): tokenizer_class = "AutoTokenizer" def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["CLIPProcessor"] diff --git a/src/transformers/models/clipseg/processing_clipseg.py b/src/transformers/models/clipseg/processing_clipseg.py index e8cd47b0aa54..39e091106c71 100644 --- a/src/transformers/models/clipseg/processing_clipseg.py +++ b/src/transformers/models/clipseg/processing_clipseg.py @@ -16,8 +16,6 @@ Image/Text processor class for CLIPSeg """ -import warnings - from ...processing_utils import ProcessorMixin from ...tokenization_utils_base import BatchEncoding @@ -41,17 +39,6 @@ class CLIPSegProcessor(ProcessorMixin): tokenizer_class = ("CLIPTokenizer", "CLIPTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) def __call__(self, text=None, images=None, visual_prompt=None, return_tensors=None, **kwargs): @@ -124,21 +111,5 @@ def __call__(self, text=None, images=None, visual_prompt=None, return_tensors=No else: return BatchEncoding(data=dict(**image_features), tensor_type=return_tensors) - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["CLIPSegProcessor"] diff --git a/src/transformers/models/donut/processing_donut.py b/src/transformers/models/donut/processing_donut.py index a545c90539b9..65ca58bcf781 100644 --- a/src/transformers/models/donut/processing_donut.py +++ b/src/transformers/models/donut/processing_donut.py @@ -17,8 +17,6 @@ """ import re -import warnings -from contextlib import contextmanager from typing import Optional, Union from ...image_utils import ImageInput @@ -55,20 +53,7 @@ class DonutProcessor(ProcessorMixin): tokenizer_class = "AutoTokenizer" def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - self._in_target_context_manager = False def __call__( self, @@ -82,9 +67,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. """ - if self._in_target_context_manager: - return self.current_processor(images, text, **kwargs) - if images is None and text is None: raise ValueError("You need to specify either an `images` or `text` input to process.") @@ -116,22 +98,6 @@ def model_input_names(self): return list(image_processor_input_names + ["input_ids", "labels"]) - @contextmanager - def as_target_processor(self): - """ - Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning TrOCR. - """ - warnings.warn( - "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your " - "labels by using the argument `text` of the regular `__call__` method (either in the same call as " - "your images inputs, or in a separate call." - ) - self._in_target_context_manager = True - self.current_processor = self.tokenizer - yield - self.current_processor = self.image_processor - self._in_target_context_manager = False - def token2json(self, tokens, is_inner_value=False, added_vocab=None): """ Convert a (generated) token sequence into an ordered JSON format. @@ -190,21 +156,5 @@ def token2json(self, tokens, is_inner_value=False, added_vocab=None): else: return [] if is_inner_value else {"text_sequence": tokens} - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["DonutProcessor"] diff --git a/src/transformers/models/flava/processing_flava.py b/src/transformers/models/flava/processing_flava.py index 8e8a806e8615..272fb01d7b7a 100644 --- a/src/transformers/models/flava/processing_flava.py +++ b/src/transformers/models/flava/processing_flava.py @@ -16,8 +16,6 @@ Image/Text processor class for FLAVA """ -import warnings - from ...processing_utils import ProcessorMixin @@ -38,34 +36,7 @@ class FlavaProcessor(ProcessorMixin): tokenizer_class = ("BertTokenizer", "BertTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor __all__ = ["FlavaProcessor"] diff --git a/src/transformers/models/fuyu/processing_fuyu.py b/src/transformers/models/fuyu/processing_fuyu.py index 75b2bbad926e..a715ce412313 100644 --- a/src/transformers/models/fuyu/processing_fuyu.py +++ b/src/transformers/models/fuyu/processing_fuyu.py @@ -531,7 +531,6 @@ def __call__( if text is not None and images is None: logger.warning("You are processing a text with no associated image. Make sure it is intended.") - self.current_processor = self.tokenizer text_encoding = self.tokenizer(text, **output_kwargs["text_kwargs"]) return text_encoding diff --git a/src/transformers/models/git/processing_git.py b/src/transformers/models/git/processing_git.py index 20fae1a9f36b..2eba7c68f584 100644 --- a/src/transformers/models/git/processing_git.py +++ b/src/transformers/models/git/processing_git.py @@ -39,7 +39,6 @@ class GitProcessor(ProcessorMixin): def __init__(self, image_processor, tokenizer): super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor __all__ = ["GitProcessor"] diff --git a/src/transformers/models/idefics/processing_idefics.py b/src/transformers/models/idefics/processing_idefics.py index 4b5ccaffe5c8..b0ad20df386b 100644 --- a/src/transformers/models/idefics/processing_idefics.py +++ b/src/transformers/models/idefics/processing_idefics.py @@ -159,7 +159,6 @@ class IdeficsProcessor(ProcessorMixin): def __init__(self, image_processor, tokenizer=None, image_size=224, add_end_of_utterance_token=None, **kwargs): super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor self.image_token_id = ( tokenizer.image_token_id if hasattr(tokenizer, "image_token") diff --git a/src/transformers/models/layoutlmv2/processing_layoutlmv2.py b/src/transformers/models/layoutlmv2/processing_layoutlmv2.py index 603cdf4df4e9..0a6ea0d20030 100644 --- a/src/transformers/models/layoutlmv2/processing_layoutlmv2.py +++ b/src/transformers/models/layoutlmv2/processing_layoutlmv2.py @@ -16,7 +16,6 @@ Processor class for LayoutLMv2. """ -import warnings from typing import Optional, Union from ...processing_utils import ProcessorMixin @@ -49,17 +48,6 @@ class LayoutLMv2Processor(ProcessorMixin): tokenizer_class = ("LayoutLMv2Tokenizer", "LayoutLMv2TokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) def __call__( @@ -166,21 +154,5 @@ def get_overflowing_images(self, images, overflow_to_sample_mapping): def model_input_names(self): return ["input_ids", "bbox", "token_type_ids", "attention_mask", "image"] - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["LayoutLMv2Processor"] diff --git a/src/transformers/models/layoutlmv3/processing_layoutlmv3.py b/src/transformers/models/layoutlmv3/processing_layoutlmv3.py index 1f1b6cead607..f4a2906b5985 100644 --- a/src/transformers/models/layoutlmv3/processing_layoutlmv3.py +++ b/src/transformers/models/layoutlmv3/processing_layoutlmv3.py @@ -16,7 +16,6 @@ Processor class for LayoutLMv3. """ -import warnings from typing import Optional, Union from ...processing_utils import ProcessorMixin @@ -49,17 +48,6 @@ class LayoutLMv3Processor(ProcessorMixin): tokenizer_class = ("LayoutLMv3Tokenizer", "LayoutLMv3TokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) def __call__( @@ -164,21 +152,5 @@ def get_overflowing_images(self, images, overflow_to_sample_mapping): def model_input_names(self): return ["input_ids", "bbox", "attention_mask", "pixel_values"] - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["LayoutLMv3Processor"] diff --git a/src/transformers/models/layoutxlm/processing_layoutxlm.py b/src/transformers/models/layoutxlm/processing_layoutxlm.py index e3ece89f434b..8e6ef52f6c0f 100644 --- a/src/transformers/models/layoutxlm/processing_layoutxlm.py +++ b/src/transformers/models/layoutxlm/processing_layoutxlm.py @@ -16,7 +16,6 @@ Processor class for LayoutXLM. """ -import warnings from typing import Optional, Union from ...processing_utils import ProcessorMixin @@ -49,16 +48,6 @@ class LayoutXLMProcessor(ProcessorMixin): tokenizer_class = ("LayoutXLMTokenizer", "LayoutXLMTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) def __call__( @@ -165,21 +154,5 @@ def get_overflowing_images(self, images, overflow_to_sample_mapping): def model_input_names(self): return ["input_ids", "bbox", "attention_mask", "image"] - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["LayoutXLMProcessor"] diff --git a/src/transformers/models/mgp_str/processing_mgp_str.py b/src/transformers/models/mgp_str/processing_mgp_str.py index 8f7d32388748..349e075c7996 100644 --- a/src/transformers/models/mgp_str/processing_mgp_str.py +++ b/src/transformers/models/mgp_str/processing_mgp_str.py @@ -14,8 +14,6 @@ # limitations under the License. """Processor class for MGP-STR.""" -import warnings - from transformers import AutoTokenizer from transformers.utils import is_torch_available from transformers.utils.generic import ExplicitEnum @@ -57,17 +55,6 @@ class MgpstrProcessor(ProcessorMixin): char_tokenizer_class = "MgpstrTokenizer" def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - self.char_tokenizer = tokenizer self.bpe_tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2") self.wp_tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased") diff --git a/src/transformers/models/musicgen/processing_musicgen.py b/src/transformers/models/musicgen/processing_musicgen.py index e2bcbf373d48..030013d34f98 100644 --- a/src/transformers/models/musicgen/processing_musicgen.py +++ b/src/transformers/models/musicgen/processing_musicgen.py @@ -44,8 +44,6 @@ class MusicgenProcessor(ProcessorMixin): def __init__(self, feature_extractor, tokenizer): super().__init__(feature_extractor, tokenizer) - self.current_processor = self.feature_extractor - self._in_target_context_manager = False def get_decoder_prompt_ids(self, task=None, language=None, no_timestamps=True): return self.tokenizer.get_decoder_prompt_ids(task=task, language=language, no_timestamps=no_timestamps) @@ -56,10 +54,6 @@ def __call__(self, *args, **kwargs): argument to [`~T5Tokenizer.__call__`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor(*args, **kwargs) - if len(args) > 0: kwargs["audio"] = args[0] return super().__call__(*args, **kwargs) diff --git a/src/transformers/models/nougat/processing_nougat.py b/src/transformers/models/nougat/processing_nougat.py index 2815dcfa7b7a..b0b6d665bd22 100644 --- a/src/transformers/models/nougat/processing_nougat.py +++ b/src/transformers/models/nougat/processing_nougat.py @@ -44,7 +44,6 @@ class NougatProcessor(ProcessorMixin): def __init__(self, image_processor, tokenizer): super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor def __call__( self, diff --git a/src/transformers/models/owlvit/processing_owlvit.py b/src/transformers/models/owlvit/processing_owlvit.py index e7fb401d9a76..e6715e9688b9 100644 --- a/src/transformers/models/owlvit/processing_owlvit.py +++ b/src/transformers/models/owlvit/processing_owlvit.py @@ -71,17 +71,6 @@ class OwlViTProcessor(ProcessorMixin): tokenizer_class = ("CLIPTokenizer", "CLIPTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) def __call__( @@ -283,21 +272,5 @@ def post_process_image_guided_detection( outputs=outputs, threshold=threshold, nms_threshold=nms_threshold, target_sizes=target_sizes ) - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["OwlViTProcessor"] diff --git a/src/transformers/models/pix2struct/processing_pix2struct.py b/src/transformers/models/pix2struct/processing_pix2struct.py index fba2fe93ef19..25667f09ad81 100644 --- a/src/transformers/models/pix2struct/processing_pix2struct.py +++ b/src/transformers/models/pix2struct/processing_pix2struct.py @@ -95,7 +95,6 @@ def __call__( output_kwargs["text_kwargs"]["add_special_tokens"] = ( add_special_tokens if add_special_tokens is not None else True ) - self.current_processor = self.tokenizer text_encoding = self.tokenizer(text=text, **output_kwargs["text_kwargs"]) return text_encoding diff --git a/src/transformers/models/speech_to_text/processing_speech_to_text.py b/src/transformers/models/speech_to_text/processing_speech_to_text.py index 2df5808b9f66..3cfe31c6547a 100644 --- a/src/transformers/models/speech_to_text/processing_speech_to_text.py +++ b/src/transformers/models/speech_to_text/processing_speech_to_text.py @@ -17,7 +17,6 @@ """ import warnings -from contextlib import contextmanager from ...processing_utils import ProcessorMixin @@ -43,8 +42,6 @@ class Speech2TextProcessor(ProcessorMixin): def __init__(self, feature_extractor, tokenizer): super().__init__(feature_extractor, tokenizer) - self.current_processor = self.feature_extractor - self._in_target_context_manager = False def __call__(self, *args, **kwargs): """ @@ -54,10 +51,6 @@ def __call__(self, *args, **kwargs): [`~Speech2TextTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor(*args, **kwargs) - if "raw_speech" in kwargs: warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.") audio = kwargs.pop("raw_speech") @@ -85,22 +78,5 @@ def __call__(self, *args, **kwargs): inputs["labels"] = encodings["input_ids"] return inputs - @contextmanager - def as_target_processor(self): - """ - Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning - Speech2Text. - """ - warnings.warn( - "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your " - "labels by using the argument `text` of the regular `__call__` method (either in the same call as " - "your audio inputs, or in a separate call." - ) - self._in_target_context_manager = True - self.current_processor = self.tokenizer - yield - self.current_processor = self.feature_extractor - self._in_target_context_manager = False - __all__ = ["Speech2TextProcessor"] diff --git a/src/transformers/models/trocr/processing_trocr.py b/src/transformers/models/trocr/processing_trocr.py index 81c7db2850b3..037f708e4ee4 100644 --- a/src/transformers/models/trocr/processing_trocr.py +++ b/src/transformers/models/trocr/processing_trocr.py @@ -16,8 +16,6 @@ Processor class for TrOCR. """ -import warnings -from contextlib import contextmanager from typing import Optional, Union from ...image_processing_utils import BatchFeature @@ -50,20 +48,7 @@ class TrOCRProcessor(ProcessorMixin): tokenizer_class = "AutoTokenizer" def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor - super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - self._in_target_context_manager = False def __call__( self, @@ -77,10 +62,6 @@ def __call__( [`~TrOCRProcessor.as_target_processor`] this method forwards all its arguments to TrOCRTokenizer's [`~TrOCRTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor(images, **kwargs) - if images is None and text is None: raise ValueError("You need to specify either an `images` or `text` input to process.") @@ -108,37 +89,5 @@ def model_input_names(self): image_processor_input_names = self.image_processor.model_input_names return image_processor_input_names + ["labels"] - @contextmanager - def as_target_processor(self): - """ - Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning TrOCR. - """ - warnings.warn( - "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your " - "labels by using the argument `text` of the regular `__call__` method (either in the same call as " - "your images inputs, or in a separate call." - ) - self._in_target_context_manager = True - self.current_processor = self.tokenizer - yield - self.current_processor = self.image_processor - self._in_target_context_manager = False - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor - __all__ = ["TrOCRProcessor"] diff --git a/src/transformers/models/vilt/processing_vilt.py b/src/transformers/models/vilt/processing_vilt.py index 5b5126ad4a85..ceda264a5345 100644 --- a/src/transformers/models/vilt/processing_vilt.py +++ b/src/transformers/models/vilt/processing_vilt.py @@ -16,8 +16,6 @@ Processor class for ViLT. """ -import warnings - from ...processing_utils import ProcessingKwargs, ProcessorMixin @@ -56,34 +54,7 @@ class ViltProcessor(ProcessorMixin): valid_processor_kwargs = ViltProcessorKwargs def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor __all__ = ["ViltProcessor"] diff --git a/src/transformers/models/vision_text_dual_encoder/processing_vision_text_dual_encoder.py b/src/transformers/models/vision_text_dual_encoder/processing_vision_text_dual_encoder.py index 7bfe3e980ef0..b98f2ac3f373 100644 --- a/src/transformers/models/vision_text_dual_encoder/processing_vision_text_dual_encoder.py +++ b/src/transformers/models/vision_text_dual_encoder/processing_vision_text_dual_encoder.py @@ -16,8 +16,6 @@ Processor class for VisionTextDualEncoder """ -import warnings - from ...processing_utils import ProcessingKwargs, ProcessorMixin @@ -46,34 +44,7 @@ class VisionTextDualEncoderProcessor(ProcessorMixin): tokenizer_class = "AutoTokenizer" def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor super().__init__(image_processor, tokenizer) - self.current_processor = self.image_processor - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor __all__ = ["VisionTextDualEncoderProcessor"] diff --git a/src/transformers/models/wav2vec2/processing_wav2vec2.py b/src/transformers/models/wav2vec2/processing_wav2vec2.py index ee8e3abd195d..642151e24fed 100644 --- a/src/transformers/models/wav2vec2/processing_wav2vec2.py +++ b/src/transformers/models/wav2vec2/processing_wav2vec2.py @@ -17,7 +17,6 @@ """ import warnings -from contextlib import contextmanager from typing import Optional, Union from ...processing_utils import ProcessingKwargs, ProcessorMixin, Unpack @@ -50,8 +49,6 @@ class Wav2Vec2Processor(ProcessorMixin): def __init__(self, feature_extractor, tokenizer): super().__init__(feature_extractor, tokenizer) - self.current_processor = self.feature_extractor - self._in_target_context_manager = False @classmethod def from_pretrained(cls, pretrained_model_name_or_path, **kwargs): @@ -104,13 +101,6 @@ def __call__( tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs, ) - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor( - audio, - **output_kwargs["audio_kwargs"], - **output_kwargs["text_kwargs"], - ) if audio is not None: inputs = self.feature_extractor(audio, **output_kwargs["audio_kwargs"]) @@ -139,10 +129,6 @@ def pad(self, *args, **kwargs): Returns: This method returns the results of each `pad` method. If both are used, the output is a dictionary containing the results of both. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor.pad(*args, **kwargs) - input_features = kwargs.pop("input_features", None) labels = kwargs.pop("labels", None) if len(args) > 0: @@ -168,22 +154,5 @@ def model_input_names(self): feature_extractor_input_names = self.feature_extractor.model_input_names return feature_extractor_input_names + ["labels"] - @contextmanager - def as_target_processor(self): - """ - Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning - Wav2Vec2. - """ - warnings.warn( - "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your " - "labels by using the argument `text` of the regular `__call__` method (either in the same call as " - "your audio inputs, or in a separate call." - ) - self._in_target_context_manager = True - self.current_processor = self.tokenizer - yield - self.current_processor = self.feature_extractor - self._in_target_context_manager = False - __all__ = ["Wav2Vec2Processor"] diff --git a/src/transformers/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.py b/src/transformers/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.py index beb22ca86749..f5605ea6c5b5 100644 --- a/src/transformers/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.py +++ b/src/transformers/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.py @@ -19,7 +19,7 @@ import os import warnings from collections.abc import Iterable -from contextlib import contextmanager, nullcontext +from contextlib import nullcontext from dataclasses import dataclass from multiprocessing import Pool, get_context, get_start_method from typing import TYPE_CHECKING, Optional, Union @@ -110,8 +110,6 @@ def __init__( ) self.decoder = decoder - self.current_processor = self.feature_extractor - self._in_target_context_manager = False def save_pretrained(self, save_directory): super().save_pretrained(save_directory) @@ -227,10 +225,6 @@ def __call__(self, *args, **kwargs): Wav2Vec2CTCTokenizer's [`~Wav2Vec2CTCTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor(*args, **kwargs) - if "raw_speech" in kwargs: warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.") audio = kwargs.pop("raw_speech") @@ -266,10 +260,6 @@ def pad(self, *args, **kwargs): Wav2Vec2CTCTokenizer's [`~Wav2Vec2CTCTokenizer.pad`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor.pad(*args, **kwargs) - input_features = kwargs.pop("input_features", None) labels = kwargs.pop("labels", None) if len(args) > 0: @@ -638,22 +628,5 @@ def decode( word_offsets=word_offsets[:n_best] if word_offsets is not None else None, ) - @contextmanager - def as_target_processor(self): - """ - Temporarily sets the processor for processing the target. Useful for encoding the labels when fine-tuning - Wav2Vec2. - """ - warnings.warn( - "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your " - "labels by using the argument `text` of the regular `__call__` method (either in the same call as " - "your audio inputs, or in a separate call." - ) - self._in_target_context_manager = True - self.current_processor = self.tokenizer - yield - self.current_processor = self.feature_extractor - self._in_target_context_manager = False - __all__ = ["Wav2Vec2ProcessorWithLM"] diff --git a/src/transformers/models/whisper/processing_whisper.py b/src/transformers/models/whisper/processing_whisper.py index 26dd02d3c40a..ece78b2f10b1 100644 --- a/src/transformers/models/whisper/processing_whisper.py +++ b/src/transformers/models/whisper/processing_whisper.py @@ -39,8 +39,6 @@ class WhisperProcessor(ProcessorMixin): def __init__(self, feature_extractor, tokenizer): super().__init__(feature_extractor, tokenizer) - self.current_processor = self.feature_extractor - self._in_target_context_manager = False def get_decoder_prompt_ids(self, task=None, language=None, no_timestamps=True): return self.tokenizer.get_decoder_prompt_ids(task=task, language=language, no_timestamps=no_timestamps) @@ -51,10 +49,6 @@ def __call__(self, *args, **kwargs): argument to [`~WhisperTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information. """ - # For backward compatibility - if self._in_target_context_manager: - return self.current_processor(*args, **kwargs) - audio = kwargs.pop("audio", None) sampling_rate = kwargs.pop("sampling_rate", None) text = kwargs.pop("text", None) diff --git a/src/transformers/models/x_clip/processing_x_clip.py b/src/transformers/models/x_clip/processing_x_clip.py index 581dabc6d8b5..2110a783bb37 100644 --- a/src/transformers/models/x_clip/processing_x_clip.py +++ b/src/transformers/models/x_clip/processing_x_clip.py @@ -16,8 +16,6 @@ Image/Text processor class for XCLIP """ -import warnings - from ...processing_utils import ProcessorMixin @@ -40,35 +38,8 @@ class XCLIPProcessor(ProcessorMixin): tokenizer_class = ("CLIPTokenizer", "CLIPTokenizerFast") def __init__(self, image_processor=None, tokenizer=None, **kwargs): - feature_extractor = None - if "feature_extractor" in kwargs: - warnings.warn( - "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`" - " instead.", - FutureWarning, - ) - feature_extractor = kwargs.pop("feature_extractor") - - image_processor = image_processor if image_processor is not None else feature_extractor super().__init__(image_processor, tokenizer) self.video_processor = self.image_processor - self.current_processor = self.image_processor - - @property - def feature_extractor_class(self): - warnings.warn( - "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.", - FutureWarning, - ) - return self.image_processor_class - - @property - def feature_extractor(self): - warnings.warn( - "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.", - FutureWarning, - ) - return self.image_processor __all__ = ["XCLIPProcessor"]