can't generate text of given length
Author: KeremZaman
Pull request: no

### System Info

Python 3.7.13
transformers 4.30.2
Ubuntu 18.04.6 LTS

### Who can help?

@ArthurZucker @younesbelkada @gante

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

In generation config, the `eos_token_id` is optional, so we expect it to generate a text of `max_length` length. 

Example code:
```
from transformers import AutoTokenizer, GenerationConfig, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained('t5-small')
model = AutoModelForSeq2SeqLM.from_pretrained('t5-small')

generation_config = GenerationConfig(
        bos_token_id=tokenizer.eos_token_id,
        eos_token_id=None,
        pad_token=model.config.pad_token_id,
        num_beams=1,
        do_sample=False
    )

inputs = tokenizer("It's what it is.", return_tensors="pt")
length = inputs['input_ids'].shape[0] + 20
print(length)
outputs = model.generate(**inputs, generation_config=generation_config, max_length=length)

print(outputs.shape)
```

Sample output:
```
21
torch.Size([1, 14])
```

This happens because the model produces EOS token way before it reaches to 21st token.

### Expected behavior

The expected output is as follows:

```
21
torch.Size([1, 21])

```

This probably occurs becuse of the following line in `greedy_search` function:

https://github.com/huggingface/transformers/blob/66fd3a8d626a32989f4569260db32785c6cbf42a/src/transformers/generation/utils.py#L2290

It uses `self.generation_config.eos_token_id` if given one is `None` and there is no place where given generation configuration is assigned to `self.generation_config`. Since the default value of `self.genertion_config.eos_token_id` is not None, it overrides the precedence of the given length when EOS token is encountered.


Comments:
Pinging @gante! 

Hey @KeremZaman 👋 

While we can't touch the line that sets `eos_token_id` to the default `self.generation_config.eos_token_id`, for backwards compatibility reasons, you can set `eos_token_id` to an impossible value to achieve the same goal :) 

e.g.:

```python
from transformers import AutoTokenizer, GenerationConfig, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained('t5-small')
model = AutoModelForSeq2SeqLM.from_pretrained('t5-small')

generation_config = GenerationConfig(
        bos_token_id=tokenizer.eos_token_id,
        eos_token_id=-1,
        pad_token=model.config.pad_token_id,
        num_beams=1,
        do_sample=False
    )

inputs = tokenizer("It's what it is.", return_tensors="pt")
length = inputs['input_ids'].shape[0] + 20
print(length)
outputs = model.generate(**inputs, generation_config=generation_config, max_length=length)

print(outputs.shape)
# torch.Size([1, 21])
```

@gante That's a very clever workaround! Thanks for the quick response!

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.