diff --git a/src/transformers/pipelines/__init__.py b/src/transformers/pipelines/__init__.py index 87db1981cbc0..5b8e3f6b221c 100755 --- a/src/transformers/pipelines/__init__.py +++ b/src/transformers/pipelines/__init__.py @@ -59,6 +59,7 @@ get_default_model_and_revision, load_model, ) +from .deprecated import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline from .depth_estimation import DepthEstimationPipeline from .document_question_answering import DocumentQuestionAnsweringPipeline from .feature_extraction import FeatureExtractionPipeline @@ -74,7 +75,6 @@ from .object_detection import ObjectDetectionPipeline from .question_answering import QuestionAnsweringArgumentHandler, QuestionAnsweringPipeline from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline -from .text2text_generation import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline from .text_classification import TextClassificationPipeline from .text_generation import TextGenerationPipeline from .text_to_audio import TextToAudioPipeline diff --git a/src/transformers/pipelines/deprecated/__init__.py b/src/transformers/pipelines/deprecated/__init__.py new file mode 100644 index 000000000000..c0e31392f272 --- /dev/null +++ b/src/transformers/pipelines/deprecated/__init__.py @@ -0,0 +1,16 @@ +# coding=utf-8 +# Copyright 2025 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .text2text_generation import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline diff --git a/src/transformers/pipelines/text2text_generation.py b/src/transformers/pipelines/deprecated/text2text_generation.py similarity index 92% rename from src/transformers/pipelines/text2text_generation.py rename to src/transformers/pipelines/deprecated/text2text_generation.py index 2e9e61691442..54e1b2873041 100644 --- a/src/transformers/pipelines/text2text_generation.py +++ b/src/transformers/pipelines/deprecated/text2text_generation.py @@ -2,14 +2,14 @@ import warnings from typing import Any -from ..generation import GenerationConfig -from ..tokenization_utils import TruncationStrategy -from ..utils import add_end_docstrings, is_torch_available, logging -from .base import Pipeline, build_pipeline_init_args +from ...generation import GenerationConfig +from ...tokenization_utils import TruncationStrategy +from ...utils import add_end_docstrings, is_torch_available, logging +from ..base import Pipeline, build_pipeline_init_args if is_torch_available(): - from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES + from ...models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES logger = logging.get_logger(__name__) @@ -77,6 +77,12 @@ class Text2TextGenerationPipeline(Pipeline): return_name = "generated" def __init__(self, *args, **kwargs): + if self.return_name == "generated": # Check this isn't summarization/translation instead + logger.warning_once( + "The `Text2TextGenerationPipeline` is deprecated and no longer maintained. For most " + "purposes, we recommend using newer models with causal pipelines like " + "`TextGenerationPipeline` or `ImageTextToTextPipeline`." + ) super().__init__(*args, **kwargs) self.check_model_type(MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES) @@ -254,6 +260,14 @@ class SummarizationPipeline(Text2TextGenerationPipeline): # Used in the return key of the pipeline. return_name = "summary" + def __init__(self, *args, **kwargs): + logger.warning_once( + "The `SummarizationPipeline` is deprecated and no longer maintained. For most " + "summarization tasks, we recommend appropriately prompting modern general-purpose LLMs " + "via pipelines like `TextGenerationPipeline` or `ImageTextToTextPipeline`." + ) + super().__init__(*args, **kwargs) + def __call__(self, *args, **kwargs): r""" Summarize the text(s) given as inputs. @@ -323,6 +337,14 @@ class TranslationPipeline(Text2TextGenerationPipeline): # Used in the return key of the pipeline. return_name = "translation" + def __init__(self, *args, **kwargs): + logger.warning_once( + "The `TranslationPipeline` is deprecated and no longer maintained. For most " + "translation tasks, we recommend appropriately prompting modern general-purpose LLMs " + "via pipelines like `TextGenerationPipeline` or `ImageTextToTextPipeline`." + ) + super().__init__(*args, **kwargs) + def check_inputs(self, input_length: int, min_length: int, max_new_tokens: int): """ Removed input length check - unnecessary with max_new_tokens (previously relevant for max_length)