`max_length` and `max_new_tokens` in `.generate()`
Author: bofenghuang
Pull request: no

Hi @gante,

I got some error related to the change of `max_length` and `max_new_tokens` in this PR https://github.com/huggingface/transformers/pull/20388.

For model like Whisper, the `max_length`  has already been defined by the max `PositionalEmbedding` length which is 448 (https://huggingface.co/openai/whisper-base/blob/main/config.json#L42).

Sometimes I want to run faster inference by setting a smaller `max_new_tokens`. But I can no more do it with the current change.

### Who can help?

@gante @sanchit-gandhi @ArthurZucker 

### 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

Below is a code snippet to reproduce the behavior.

```python
import torch
from datasets import load_dataset

from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq

model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-base")
processor = AutoProcessor.from_pretrained("openai/whisper-base")

dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
audio = dataset[0]["audio"]["array"]

inputs = processor(audio, return_tensors="pt")
input_features = inputs["input_features"]

generated_ids = model.generate(inputs=input_features, max_new_tokens=225)
```

### Expected behavior

When running this we see the following stack trace:

```
Using the latest cached version of the module from /home/bhuang/.cache/huggingface/modules/datasets_modules/datasets/hf-internal-testing--librispeech_asr_dummy/d3bc4c2bc2078fcde3ad0f0f635862e4c0fef78ba94c4a34c4c250a097af240b (last modified on Sun Dec 25 15:33:28 2022) since it couldn't be found locally at hf-internal-testing/librispeech_asr_dummy., or remotely on the Hugging Face Hub.
Found cached dataset librispeech_asr_dummy (/home/bhuang/.cache/huggingface/datasets/hf-internal-testing___librispeech_asr_dummy/clean/2.1.0/d3bc4c2bc2078fcde3ad0f0f635862e4c0fef78ba94c4a34c4c250a097af240b)
It is strongly recommended to pass the `sampling_rate` argument to this function. Failing to do so can result in silent errors that might be hard to debug.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 15
     12 inputs = processor(audio, return_tensors="pt")
     13 input_features = inputs["input_features"]
---> 15 generated_ids = model.generate(inputs=input_features, max_new_tokens=225)

File ~/anaconda3/envs/asr/lib/python3.8/site-packages/torch/autograd/grad_mode.py:27, in _DecoratorContextManager.__call__.<locals>.decorate_context(*args, **kwargs)
     24 @functools.wraps(func)
     25 def decorate_context(*args, **kwargs):
     26     with self.clone():
---> 27         return func(*args, **kwargs)

File ~/transformers/src/transformers/generation/utils.py:1230, in GenerationMixin.generate(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, **kwargs)
   1228     generation_config.max_length = generation_config.max_new_tokens + input_ids_seq_length
   1229 elif not has_default_max_length and generation_config.max_new_tokens is not None:
-> 1230     raise ValueError(
   1231         "Both `max_new_tokens` and `max_length` have been set but they serve the same purpose -- setting a"
   1232         " limit to the generated output length. Remove one of those arguments. Please refer to the"
   1233         " documentation for more information. "
   1234         "(https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)"
   1235     )
   1237 if generation_config.min_length is not None and generation_config.min_length > generation_config.max_length:
   1238     raise ValueError(
   1239         f"Unfeasible length constraints: the minimum length ({generation_config.min_length}) is larger than"
   1240         f" the maximum length ({generation_config.max_length})"
   1241     )

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)
```


I can set `model.config.max_length = 226` after loading the model to generate with the `max_length` I want. But I think it might be a better choice to enable this option in the `.generate()` function.

Comments:
I kind of agree with you, but I think the goal is to get rid of `max_length` and rather use the `max_new_token` in the configuration of the model, which is why we should rather deprecate (as we did with previous version) the usage of both of the arguments

In this instance, only one was passed though, so this is clearly a bug :-)

Hey @bofenghuang 👋 

Definitely an unwanted bug that arose from the ongoing transition to generation config files. Having a look!