Can we add an augment `min_new_tokens` to the `generate` function?
Author: silverriver
Pull request: no

### Feature request

Can we add a new parameter `min_new_tokens` to the `generate` function to limit the length of newly generated tokens? The current parameter `min_length` limits the length of `prompt + newly generated tokens`, not the length of `newly generated tokens`.

### Motivation

We already have `max_new_tokens` to limit the max length of the generated tokens, i.e., `max_length = max_new_tokens + prompt`.

Why not add the `min_new_token` to limit the min length of the generated tokens? (i.e., `min_length = min_new_tokens + prompt`)

I know this is kind like an other syntax sugar, but it will be much convenient if we have this parameter.

### Your contribution

I can sumbit a PR.

Comments:
the `min_length` already does what you want the `min_new_tokens` does under the hood, so personally I don't understand why you like to add a new `min_new_tokens` and change what `min_length` original mean. But add `min_new_tokens` as an alias of `min_length` may be a good idea (but not necessary).

For my understanding, in the current implementation, `min_length` set the length limit of `len(promt) + len(generated tokens)`

See the implementation of [`MinLengthLogitsProcessor`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/logits_process.py#L119):
```python
    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
        cur_len = input_ids.shape[-1]
        if cur_len < self.min_length:
            scores[:, self.eos_token_id] = -float("inf")
        return scores
```

`input_ids` in the previous code block refers to `prompt + generated tokens`. For example, see the implemented of some decoding method for how logits processors are called. (See [`beam_search()`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/utils.py#L2818) or [`greedy_decoding()`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/utils.py#L2298))

It will be more convenient if we set an argument `min_new_tokens` to **only** limit the length of `generated tokens`, not `prompt + generated tokens`.

---
Please correct me if I have missed something


cc @gante 

> For my understanding, in the current implementation, `min_length` set the length limit of `len(promt) + len(generated tokens)`
> 
> See the implementation of [`MinLengthLogitsProcessor`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/logits_process.py#L119):
> 
> ```python
>     def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
>         cur_len = input_ids.shape[-1]
>         if cur_len < self.min_length:
>             scores[:, self.eos_token_id] = -float("inf")
>         return scores
> ```
> 
> `input_ids` in the previous code block refers to `prompt + generated tokens`. For example, see the implemented of some decoding method for how logits processors are called. (See [`beam_search()`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/utils.py#L2818) or [`greedy_decoding()`](https://github.com/huggingface/transformers/blob/28f3d431d4b8b74a458a5583297d5101483edb74/src/transformers/generation/utils.py#L2298))
> 
> It will be more convenient if we set an argument `min_new_tokens` to **only** limit the length of `generated tokens`, not `prompt + generated tokens`.
> 
> Please correct me if I have missed something

@silverriver yes you are right, its my mistake 😂

But I still think `min_new_tokens` and `min_length` should mean the same thing and also to `max_new_tokens` and `max_length` (though they are actually different now), because most people who use `model.generate` would think `min_length` means to 'at least generate min_length tokens' and `max_length` means to 'generate tokens no more than max_length'

@PanQiWei I agree, but I think it is impossible to change the current implementation of `max_length` and `min_length` for the conern of back compatibility.

Hey @silverriver @PanQiWei 👋 

Having `min_new_tokens` would certainly be a welcome change, for the same reason as `max_new_tokens`. It is clear what it does, regardless of the type of model, where `min_tokens`/`max_tokens` are not. In the long run, we'd like to deprecate `min_tokens`/`max_tokens` in favor of `min_new_tokens`/`max_new_tokens`.

I'll have a look at your PRs :)

I have closed my original PR and made a new one (#21044 ) to avoid messing with other commits when I tried to rebase my change.