GPT-2 generate degenerates into producing garbage after a while
Author: demongolem-biz
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.9.2
- Platform: Windows 10
- Python version: 3.8.7
- PyTorch version (GPU?): 1.8.1+cu102
- Tensorflow version (GPU?): 2.6.0
- Using GPU in script?: ?
- Using distributed or parallel set-up in script?: No

### Who can help

@patrickvonplaten, @LysandreJik

## Information

Model I am using is GPT2.  When I do generate with max_length of 100, the output starts to look correct, but then it goes into a bunch of nonsense which isn't simply non-grammatical, but rather barely English at all (it looks badly garbled).  As an example:

> In soccer news, Bob Jackson scored 3 goals for Chlesea on October 12, 2021.  "It's been a long time coming, but I'm happy to be here," he said. "I'm excited to get back on the field and be a part of this team. I've been working with the staff to put to minute farereens Ahead optimistic429 Congressionaloute moldedtxt variants ralliedinous afflicted unwilling Prediction isn 315 WWElike flown fingertipsazelstripLLOWPayregor utilized confidently028 GamerGate

The workaround I have now which largely looks like it works is to do an `rfind` on the rightmost period and then cut off everything to the right of that.  Of course this would not be 100% successful.

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [X ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ X] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:
This is my code:

```
    tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
    # add the EOS token as PAD token to avoid warnings
    model = GPT2LMHeadModel.from_pretrained("gpt2", pad_token_id=tokenizer.eos_token_id)

    input_ids = tokenizer(msg, return_tensors="pt")
    beam_output = model.generate(
        **input_ids, 
        do_sample=True,
        max_length=100,
        num_beams=5,
        temperature=0.7,
        early_stopping=True,
        no_repeat_ngram_size=2
    )
    #generated_text = tokenizer.decode(beam_output[0], skip_special_tokens=True)[:280].replace('\n', ' ')
    generated_text = tokenizer.decode(beam_output[0], skip_special_tokens=True).replace('\n', ' ')
```

## Expected behavior
I expect generated output of length 100 of grammatical text, even if it is repeated or off-topic.

Comments:
Hey @demongolem-biz,

Could you try to turn of "beam sample" mode and just use "sample" mode instead? Beam sample mode isn't really common for models auch as GPT2.

```py
    tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
    # add the EOS token as PAD token to avoid warnings
    model = GPT2LMHeadModel.from_pretrained("gpt2", pad_token_id=tokenizer.eos_token_id)

    input_ids = tokenizer(msg, return_tensors="pt")
    beam_output = model.generate(
        **input_ids, 
        do_sample=True,
        max_length=100,
        num_beams=1,
        temperature=0.7,
        early_stopping=True,
        no_repeat_ngram_size=2
    )
    #generated_text = tokenizer.decode(beam_output[0], skip_special_tokens=True)[:280].replace('\n', ' ')
    generated_text = tokenizer.decode(beam_output[0], skip_special_tokens=True).replace('\n', ' ')
```

Note how `num_beams` is set to 1 above

Thanks for the clarification @patrickvonplaten .  I see that the I get proper English words now and the random blobs of text have disappeared.