Repository: huggingface/transformers
Pull request: [Tests] add `min_new_tokens` to prevent flaky length checks

# What does this PR do?

Sets `min_new_tokens` to the same value as `max_new_tokens` in a few checks to prevent failures in length-related checks. These checks expect that we generate exactly `max_new_tokens` tokens, and we might stop earlier due to stopping criteria that's often on by defaulta (e.g. due to eos token)

E.g. 
<img width="1377" alt="Screenshot 2025-04-01 at 16 11 47" src="https://github.com/user-attachments/assets/7c1877b5-668f-41f6-bcb3-93101c58094d" />

this one is no longer flaky :) (`py.test tests/models/pix2struct/test_modeling_pix2struct.py::Pix2StructModelTest::test_greedy_generate_dict_outputs_use_cache --flake-finder --flake-runs 1000`, previously had a ~3% failure rate)

Changed files:
filename: tests/generation/test_utils.py
patch: @@ -281,6 +281,7 @@ def _greedy_generate(
             do_sample=False,
             num_beams=1,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_attentions=output_attentions,
             output_hidden_states=output_hidden_states,
             output_scores=output_scores,
@@ -311,6 +312,7 @@ def _sample_generate(
             do_sample=True,
             num_beams=1,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             num_return_sequences=num_return_sequences,
             output_scores=output_scores,
             output_logits=output_logits,
@@ -340,6 +342,7 @@ def _beam_search_generate(
         output_generate = model.generate(
             do_sample=False,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_scores=output_scores,
             output_logits=output_logits,
             output_attentions=output_attentions,
@@ -370,6 +373,7 @@ def _beam_sample_generate(
         output_generate = model.generate(
             do_sample=True,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_scores=output_scores,
             output_logits=output_logits,
             output_attentions=output_attentions,
@@ -399,6 +403,7 @@ def _group_beam_search_generate(
         output_generate = model.generate(
             do_sample=False,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_scores=output_scores,
             output_logits=output_logits,
             output_attentions=output_attentions,
@@ -429,6 +434,7 @@ def _constrained_beam_search_generate(
         output_generate = model.generate(
             do_sample=False,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_scores=output_scores,
             output_logits=output_logits,
             output_attentions=output_attentions,
@@ -464,6 +470,7 @@ def _contrastive_generate(
             do_sample=False,
             num_beams=1,
             max_new_tokens=self.max_new_tokens,
+            min_new_tokens=self.max_new_tokens,
             output_attentions=output_attentions,
             output_hidden_states=output_hidden_states,
             output_scores=output_scores,