Repository: huggingface/transformers
Pull request: fix check inputs for text2text pipeline

The pipeline should check generation_config before checking inputs.
```python
import torch
from transformers import pipeline, AutoTokenizer

model_id = "sshleifer/distilbart-cnn-12-6"
tokenizer = AutoTokenizer.from_pretrained(model_id)
generator = pipeline(
    "summarization",
    model=model_id,
    tokenizer=tokenizer,
    dtype=torch.float16,
)
generation_config = generator.model.generation_config
generation_config.max_new_tokens = 4
generation_config.min_new_tokens = 4
input_sentence = "This is an example inputs for summarization"
output = generator(
    input_sentence, generation_config=generation_config
)
```

output:
```
Traceback (most recent call last):
  File "/home/jiqing/HuggingFace/tests/workloads/test_summa.py", line 16, in <module>
    output = generator(
             ^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/text2text_generation.py", line 285, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/text2text_generation.py", line 182, in __call__
    result = super().__call__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/base.py", line 1289, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/base.py", line 1296, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/base.py", line 1200, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jiqing/transformers/src/transformers/pipelines/text2text_generation.py", line 198, in _forward
    self.check_inputs(
  File "/home/jiqing/transformers/src/transformers/pipelines/text2text_generation.py", line 291, in check_inputs
    if max_new_tokens < min_length:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'int'
```

This PR can fix it by getting the correct max_new_tokens in generation config.

Changed files:
filename: src/transformers/pipelines/text2text_generation.py
patch: @@ -194,17 +194,13 @@ def preprocess(self, inputs, truncation=TruncationStrategy.DO_NOT_TRUNCATE, **kw
 
     def _forward(self, model_inputs, **generate_kwargs):
         in_b, input_length = model_inputs["input_ids"].shape
-
-        self.check_inputs(
-            input_length,
-            generate_kwargs.get("min_length", self.generation_config.min_length),
-            generate_kwargs.get("max_new_tokens", self.generation_config.max_new_tokens),
-        )
-
         # User-defined `generation_config` passed to the pipeline call take precedence
         if "generation_config" not in generate_kwargs:
             generate_kwargs["generation_config"] = self.generation_config
 
+        min_length = generate_kwargs.get("min_length", generate_kwargs["generation_config"].min_length)
+        max_new_tokens = generate_kwargs.get("max_new_tokens", generate_kwargs["generation_config"].max_new_tokens)
+        self.check_inputs(input_length, min_length, max_new_tokens)
         output_ids = self.model.generate(**model_inputs, **generate_kwargs)
         out_b = output_ids.shape[0]
         output_ids = output_ids.reshape(in_b, out_b // in_b, *output_ids.shape[1:])