"Both `max_new_tokens` and `max_length` have been set but they serve the same purpose" when only setting max_new_tokens.
Author: gael-vanderlee
Pull request: no

### System Info

- `transformers` version: 4.27.0.dev0
- Platform: Windows-10-10.0.19044-SP0
- Python version: 3.10.4
- Huggingface_hub version: 0.12.0
- PyTorch version (GPU?): 1.13.1+cpu (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No


### Who can help?

@gante I believe.

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

1. Install transformers
2. Run the following script 
```
from transformers import pipeline

summarizer = pipeline("summarization", max_new_tokens=50)

prompt = "text to summarize"
summary = summarizer(prompt)
```
3. It crashes with the following error:

> ValueError: Both `max_new_tokens` and `max_length` have been set but they serve the same purpose -- setting a limit to the generated output length. Remove one of those arguments. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)


### Expected behavior

Expected behavior is that the script should run. I only set `max_new_tokens` and not `max_length`.
This might seem like a duplicate of https://github.com/huggingface/transformers/issues/20894 but the issue persists even after installing the latest version of transformers with the fix for that issue.


Comments:
Hey @Gvanderl 👋 
We are aware of this issue (some downstream uses of `.generate()`, like the `pipeline`, fail when `max_new_tokens` is set). #21347 will fix it 🎉 

After it gets merged, install from main and it should work! (i.e. `pip install --upgrade git+https://github.com/huggingface/transformers.git`)

Amazing, thanks for being so responsive.
I'm closing the issue. 

Hello,

Trying the new main, I encounter a new issue. It seems that `max_new_tokens` behaves like `max_length`.
However, according to the documentation their behavior should be the following:

> max_length (int, optional, defaults to 20) — The maximum length the generated tokens can have. Corresponds to the length of the input prompt + max_new_tokens. In general, prefer the use of max_new_tokens, which ignores the number of tokens in the prompt.
max_new_tokens (int, optional) — The maximum numbers of tokens to generate, ignoring the number of tokens in the prompt.

Using the code from above, I get the following stack trace:

```
--- Logging error ---
Traceback (most recent call last):
  File "AppData\Local\Programs\Python\Python310\lib\logging\__init__.py", line 1100, in emit
    msg = self.format(record)
  File "AppData\Local\Programs\Python\Python310\lib\logging\__init__.py", line 943, in format
    return fmt.format(record)
  File "AppData\Local\Programs\Python\Python310\lib\logging\__init__.py", line 678, in format
    record.message = record.getMessage()
  File "AppData\Local\Programs\Python\Python310\lib\logging\__init__.py", line 368, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "AppData\Roaming\JetBrains\PyCharm2022.3\scratches\scratch.py", line 6, in <module>
    summary = summarizer(prompt)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 265, in __call__
    return super().__call__(*args, **kwargs)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 165, in __call__
    result = super().__call__(*args, **kwargs)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 1089, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 1096, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 995, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 187, in _forward
    output_ids = self.model.generate(**model_inputs, **generate_kwargs)
  File "venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "venv\lib\site-packages\transformers\generation\utils.py", line 1285, in generate
    logger.warn(
Message: 'Both `max_new_tokens` (=50) and `max_length`(=51) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)'
Arguments: (<class 'UserWarning'>,)
Traceback (most recent call last):
  File "AppData\Roaming\JetBrains\PyCharm2022.3\scratches\scratch.py", line 6, in <module>
    summary = summarizer(prompt)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 265, in __call__
    return super().__call__(*args, **kwargs)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 165, in __call__
    result = super().__call__(*args, **kwargs)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 1089, in __call__
    return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 1096, in run_single
    model_outputs = self.forward(model_inputs, **forward_params)
  File "venv\lib\site-packages\transformers\pipelines\base.py", line 995, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
  File "venv\lib\site-packages\transformers\pipelines\text2text_generation.py", line 187, in _forward
    output_ids = self.model.generate(**model_inputs, **generate_kwargs)
  File "venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "venv\lib\site-packages\transformers\generation\utils.py", line 1294, in generate
    raise ValueError(
ValueError: Unfeasible length constraints: the minimum length (56) is larger than the maximum length (51)

Process finished with exit code 1
```




Hey @Gvanderl -- That's because `min_length` is set for that pipeline (in that case, `min_length=56`), and `min_length` has to be smaller than the maximum length you define :) 

You can either decrease `min_length`, by setting it, or increase `max_new_tokens`

Oh I see.
This fixed the issue, though now every time it runs it gives me the following warning: 
```
Message: 'Both `max_new_tokens` (=50) and `max_length`(=51) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)'
```

Any way to get rid of it ? Setting `max_length=None` resulted in a crash. 

You can raise the level of the logger to ignore warnings :) I will be working on the pipelines in the coming week or two, that warning should disappear by then.

Can anyone please tell me how to pass the max_token_size. I am passing max_length in the generate method, still it is taking the default value
    inputs = processor(batch["audio"]["array"], return_tensors="pt",sampling_rate=16_000)
    generated_ids = model.generate(inputs=inputs.input_features,max_length=1000)
    print(len(generated_ids))
    batch["pred_str"] = processor.batch_decode(generated_ids,skip_special_tokens=True,group_tokens=True,max_length=500)
 The length is not getting set , I am getting output till length 448. Please help me on this.

@enankobh that happens because, [if I'm seeing correctly](https://huggingface.co/openai/whisper-large-v2/blob/main/config.json#L44), Whisper's maximum output length is 448 tokens. @ArthurZucker can you confirm?