Pipeline feature request for min_new_tokens
Author: mediocreatmybest
Pull request: no
Labels: name: WIP

### Feature request

Pipeline already supports the option max_new_tokens.

I’m requesting for the existing “min_new_tokens” to be able to be used with pipeline the same way as “max_new_tokens”.

Currently this will throw an error when trying to specify “min_new_tokens” as unrecognised.  

### Motivation

Maintaining consistency, as the previous way to specify tokens is deprecated.

### Your contribution

I can test, but I’m not a developer. So no, I couldn’t do a PR.


Comments:
cc @gante 

Hey @mediocreatmybest -- the flag is already available and operational :) Be mindful that you may need to adjust `max_new_tokens` to an admissible range. An impossible combination of constraints should raise a warning -- we are working on them :)

```py
from transformers import pipeline
pipe = pipeline(task="text-generation", model="gpt2")

# Base example
pipe_out = pipe("This is a sequence of numbers: 1 2 3 4", do_sample=False)
print(pipe_out)

# Add min_new_tokens -> no change because the default maximum number of tokens is smaller
# This will likely be an exception in the future.
pipe_out = pipe("This is a sequence of numbers: 1 2 3 4", do_sample=False, min_new_tokens=100)
print(pipe_out)

# If we add max_new_tokens -> it works as expected
pipe_out = pipe("This is a sequence of numbers: 1 2 3 4", do_sample=False, min_new_tokens=100, max_new_tokens=100)
print(pipe_out)
```

(I'm closing since the feature already exists -- feel free to continue commenting)

Awesome thanks! 

> (I'm closing since the feature already exists -- feel free to continue commenting)

Thanks @gante, just to confirm which version of transformers has this been included in?
Currently transformers 4.31.0 with pipeline task text-to-image produces this error when running with min_new_tokens 

Simple Caption Pipeline:
```

from transformers import pipeline

pipe = pipeline("image-to-text",model="Salesforce/blip-image-captioning-base",min_new_tokens=5, max_new_tokens=20)
caption = pipe("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")
print(caption)
```


```
      pipe = pipeline("image-to-text",model="Salesforce/blip-image-captioning-base",min_new_tokens=5, max_new_tokens=20)
  File "C:\Python310\lib\site-packages\transformers\pipelines\__init__.py", line 988, in pipeline
    return pipeline_class(model=model, framework=framework, task=task, **kwargs)
  File "C:\Python310\lib\site-packages\transformers\pipelines\image_to_text.py", line 55, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Python310\lib\site-packages\transformers\pipelines\base.py", line 816, in __init__
    self._preprocess_params, self._forward_params, self._postprocess_params = self._sanitize_parameters(**kwargs)
TypeError: ImageToTextPipeline._sanitize_parameters() got an unexpected keyword argument 'min_new_tokens'

```

Just ran through your example and that ran without an issue, I'm guessing my issue might be the ImagetoTextPipeline doesn't have that feature? 

@mediocreatmybest quite possibly `ImagetoTextPipeline` is not correctly accepting text generation arguments -- will check it!

@mediocreatmybest #24989 fixes it :) (feel free to pip install from that PR)

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Commenting so this doesn’t close automatically.

As mentioned in the other thread, is this still possible? or what would be the recommended way to pass this to pipeline for the mentioned tasks?

Thanks. :)

Yes, it is still possible, but the fix may take a few weeks (it is a systemic change across pipelines, see [this comment](https://github.com/huggingface/transformers/pull/24989#issuecomment-1647767932)) :)

> Yes, it is still possible, but the fix may take a few weeks (it is a systemic change across pipelines, see [this comment](https://github.com/huggingface/transformers/pull/24989#issuecomment-1647767932)) :)

Awesome I'll keep an eye out and update my HF space after then. Thanks!

I'm happy to close this request if it looks to be in the "pipeline". :) 

(Let's keep it open, so we have a reminder to complete it!)

Bump! 

(assigned to me and added WIP so this doesn't get closed)