Repository: huggingface/transformers
Pull request: 🚨 [v5] remove generate output retrocompatibility aliases

# What does this PR do?

See title :)

Changed files:
filename: src/transformers/generation/__init__.py
patch: @@ -100,16 +100,6 @@
     ]
     _import_structure["utils"] = [
         "GenerationMixin",
-        "GreedySearchEncoderDecoderOutput",
-        "GreedySearchDecoderOnlyOutput",
-        "SampleEncoderDecoderOutput",
-        "SampleDecoderOnlyOutput",
-        "BeamSearchEncoderDecoderOutput",
-        "BeamSearchDecoderOnlyOutput",
-        "BeamSampleEncoderDecoderOutput",
-        "BeamSampleDecoderOnlyOutput",
-        "ContrastiveSearchEncoderDecoderOutput",
-        "ContrastiveSearchDecoderOnlyOutput",
         "GenerateBeamDecoderOnlyOutput",
         "GenerateBeamEncoderDecoderOutput",
         "GenerateDecoderOnlyOutput",
@@ -194,21 +184,11 @@
             validate_stopping_criteria,
         )
         from .utils import (
-            BeamSampleDecoderOnlyOutput,
-            BeamSampleEncoderDecoderOutput,
-            BeamSearchDecoderOnlyOutput,
-            BeamSearchEncoderDecoderOutput,
-            ContrastiveSearchDecoderOnlyOutput,
-            ContrastiveSearchEncoderDecoderOutput,
             GenerateBeamDecoderOnlyOutput,
             GenerateBeamEncoderDecoderOutput,
             GenerateDecoderOnlyOutput,
             GenerateEncoderDecoderOutput,
             GenerationMixin,
-            GreedySearchDecoderOnlyOutput,
-            GreedySearchEncoderDecoderOutput,
-            SampleDecoderOnlyOutput,
-            SampleEncoderDecoderOutput,
         )
         from .watermarking import (
             BayesianDetectorConfig,

filename: src/transformers/generation/utils.py
patch: @@ -329,28 +329,6 @@ class GenerateBeamEncoderDecoderOutput(ModelOutput):
     past_key_values: Optional[Cache] = None
 
 
-# TODO (joao): remove the equivalent classes and typing shortcuts below in v5
-# Equivalent classes (kept for retrocompatibility purposes)
-GreedySearchDecoderOnlyOutput = GenerateDecoderOnlyOutput
-ContrastiveSearchDecoderOnlyOutput = GenerateDecoderOnlyOutput
-SampleDecoderOnlyOutput = GenerateDecoderOnlyOutput
-
-ContrastiveSearchEncoderDecoderOutput = GenerateEncoderDecoderOutput
-GreedySearchEncoderDecoderOutput = GenerateEncoderDecoderOutput
-SampleEncoderDecoderOutput = GenerateEncoderDecoderOutput
-
-BeamSearchDecoderOnlyOutput = GenerateBeamDecoderOnlyOutput
-BeamSampleDecoderOnlyOutput = GenerateBeamDecoderOnlyOutput
-
-BeamSearchEncoderDecoderOutput = GenerateBeamEncoderDecoderOutput
-BeamSampleEncoderDecoderOutput = GenerateBeamEncoderDecoderOutput
-
-GreedySearchOutput = Union[GreedySearchEncoderDecoderOutput, GreedySearchDecoderOnlyOutput]
-SampleOutput = Union[SampleEncoderDecoderOutput, SampleDecoderOnlyOutput]
-BeamSearchOutput = Union[BeamSearchEncoderDecoderOutput, BeamSearchDecoderOnlyOutput]
-BeamSampleOutput = Union[BeamSampleEncoderDecoderOutput, BeamSampleDecoderOnlyOutput]
-ContrastiveSearchOutput = Union[ContrastiveSearchEncoderDecoderOutput, ContrastiveSearchDecoderOnlyOutput]
-
 # Typing shortcuts
 GenerateNonBeamOutput = Union[GenerateDecoderOnlyOutput, GenerateEncoderDecoderOutput]
 GenerateBeamOutput = Union[GenerateBeamDecoderOnlyOutput, GenerateBeamEncoderDecoderOutput]

filename: tests/generation/test_utils.py
patch: @@ -84,25 +84,17 @@
         StaticCache,
     )
     from transformers.generation import (
-        BeamSampleDecoderOnlyOutput,
-        BeamSampleEncoderDecoderOutput,
-        BeamSearchDecoderOnlyOutput,
-        BeamSearchEncoderDecoderOutput,
         CompileConfig,
         GenerateBeamDecoderOnlyOutput,
         GenerateBeamEncoderDecoderOutput,
         GenerateDecoderOnlyOutput,
         GenerateEncoderDecoderOutput,
         GenerationConfig,
         GenerationMixin,
-        GreedySearchDecoderOnlyOutput,
-        GreedySearchEncoderDecoderOutput,
         LogitsProcessorList,
         MaxLengthCriteria,
         MinLengthLogitsProcessor,
         PromptLookupCandidateGenerator,
-        SampleDecoderOnlyOutput,
-        SampleEncoderDecoderOutput,
         StoppingCriteria,
         StoppingCriteriaList,
         SynthIDTextWatermarkingConfig,
@@ -364,15 +356,11 @@ def test_greedy_generate_dict_outputs(self):
             if model.config.is_encoder_decoder:
                 self.assertTrue(output_generate.sequences.shape[1] == self.max_new_tokens + 1)
                 self.assertIsInstance(output_generate, GenerateEncoderDecoderOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, GreedySearchEncoderDecoderOutput)
             else:
                 self.assertTrue(
                     output_generate.sequences.shape[1] == self.max_new_tokens + inputs_dict["input_ids"].shape[1]
                 )
                 self.assertIsInstance(output_generate, GenerateDecoderOnlyOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, GreedySearchDecoderOnlyOutput)
 
             self._check_generate_outputs(output_generate, model.config)
 
@@ -446,15 +434,11 @@ def test_sample_generate_dict_output(self):
             if model.config.is_encoder_decoder:
                 self.assertTrue(output_generate.sequences.shape[1] == self.max_new_tokens + 1)
                 self.assertIsInstance(output_generate, GenerateEncoderDecoderOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, SampleEncoderDecoderOutput)
             else:
                 self.assertTrue(
                     output_generate.sequences.shape[1] == self.max_new_tokens + inputs_dict["input_ids"].shape[1]
                 )
                 self.assertIsInstance(output_generate, GenerateDecoderOnlyOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, SampleDecoderOnlyOutput)
 
             self._check_generate_outputs(output_generate, model.config, num_return_sequences=2)
 
@@ -496,15 +480,11 @@ def test_beam_search_generate_dict_output(self):
             if model.config.is_encoder_decoder:
                 self.assertTrue(output_generate.sequences.shape[1] == self.max_new_tokens + 1)
                 self.assertIsInstance(output_generate, GenerateBeamEncoderDecoderOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, BeamSearchEncoderDecoderOutput)
             else:
                 self.assertTrue(
                     output_generate.sequences.shape[1] == self.max_new_tokens + inputs_dict["input_ids"].shape[1]
                 )
                 self.assertIsInstance(output_generate, GenerateBeamDecoderOnlyOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, BeamSearchDecoderOnlyOutput)
 
             self._check_generate_outputs(
                 output_generate,
@@ -625,15 +605,11 @@ def test_beam_sample_generate_dict_output(self):
             if model.config.is_encoder_decoder:
                 self.assertTrue(output_generate.sequences.shape[1] == self.max_new_tokens + 1)
                 self.assertIsInstance(output_generate, GenerateBeamEncoderDecoderOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, BeamSampleEncoderDecoderOutput)
             else:
                 self.assertTrue(
                     output_generate.sequences.shape[1] == self.max_new_tokens + inputs_dict["input_ids"].shape[1]
                 )
                 self.assertIsInstance(output_generate, GenerateBeamDecoderOnlyOutput)
-                # Retrocompatibility check
-                self.assertIsInstance(output_generate, BeamSampleDecoderOnlyOutput)
 
             self._check_generate_outputs(
                 output_generate,