Skip to content

Commit 371ef0f

Browse files
[v5] Deprecate Text2Text and related pipelines (#41996)
* Deprecate Text2Text and related pipelines * Try a restructure * make fixup * logging -> logger
1 parent 6efc179 commit 371ef0f

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/transformers/pipelines/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
get_default_model_and_revision,
6060
load_model,
6161
)
62+
from .deprecated import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline
6263
from .depth_estimation import DepthEstimationPipeline
6364
from .document_question_answering import DocumentQuestionAnsweringPipeline
6465
from .feature_extraction import FeatureExtractionPipeline
@@ -74,7 +75,6 @@
7475
from .object_detection import ObjectDetectionPipeline
7576
from .question_answering import QuestionAnsweringArgumentHandler, QuestionAnsweringPipeline
7677
from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline
77-
from .text2text_generation import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline
7878
from .text_classification import TextClassificationPipeline
7979
from .text_generation import TextGenerationPipeline
8080
from .text_to_audio import TextToAudioPipeline
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding=utf-8
2+
# Copyright 2025 The HuggingFace Inc. team.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from .text2text_generation import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline

src/transformers/pipelines/text2text_generation.py renamed to src/transformers/pipelines/deprecated/text2text_generation.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import warnings
33
from typing import Any
44

5-
from ..generation import GenerationConfig
6-
from ..tokenization_utils import TruncationStrategy
7-
from ..utils import add_end_docstrings, is_torch_available, logging
8-
from .base import Pipeline, build_pipeline_init_args
5+
from ...generation import GenerationConfig
6+
from ...tokenization_utils import TruncationStrategy
7+
from ...utils import add_end_docstrings, is_torch_available, logging
8+
from ..base import Pipeline, build_pipeline_init_args
99

1010

1111
if is_torch_available():
12-
from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
12+
from ...models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
1313

1414
logger = logging.get_logger(__name__)
1515

@@ -77,6 +77,12 @@ class Text2TextGenerationPipeline(Pipeline):
7777
return_name = "generated"
7878

7979
def __init__(self, *args, **kwargs):
80+
if self.return_name == "generated": # Check this isn't summarization/translation instead
81+
logger.warning_once(
82+
"The `Text2TextGenerationPipeline` is deprecated and no longer maintained. For most "
83+
"purposes, we recommend using newer models with causal pipelines like "
84+
"`TextGenerationPipeline` or `ImageTextToTextPipeline`."
85+
)
8086
super().__init__(*args, **kwargs)
8187

8288
self.check_model_type(MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES)
@@ -254,6 +260,14 @@ class SummarizationPipeline(Text2TextGenerationPipeline):
254260
# Used in the return key of the pipeline.
255261
return_name = "summary"
256262

263+
def __init__(self, *args, **kwargs):
264+
logger.warning_once(
265+
"The `SummarizationPipeline` is deprecated and no longer maintained. For most "
266+
"summarization tasks, we recommend appropriately prompting modern general-purpose LLMs "
267+
"via pipelines like `TextGenerationPipeline` or `ImageTextToTextPipeline`."
268+
)
269+
super().__init__(*args, **kwargs)
270+
257271
def __call__(self, *args, **kwargs):
258272
r"""
259273
Summarize the text(s) given as inputs.
@@ -323,6 +337,14 @@ class TranslationPipeline(Text2TextGenerationPipeline):
323337
# Used in the return key of the pipeline.
324338
return_name = "translation"
325339

340+
def __init__(self, *args, **kwargs):
341+
logger.warning_once(
342+
"The `TranslationPipeline` is deprecated and no longer maintained. For most "
343+
"translation tasks, we recommend appropriately prompting modern general-purpose LLMs "
344+
"via pipelines like `TextGenerationPipeline` or `ImageTextToTextPipeline`."
345+
)
346+
super().__init__(*args, **kwargs)
347+
326348
def check_inputs(self, input_length: int, min_length: int, max_new_tokens: int):
327349
"""
328350
Removed input length check - unnecessary with max_new_tokens (previously relevant for max_length)

0 commit comments

Comments
 (0)