UnboundLocalError when generating sequences
Author: miguelvictor
Pull request: no

## Environment info

- `transformers` version: 4.2.0dev0
- Platform: macOS-11.1-x86_64-i386-64bit
- Python version: 3.8.7
- PyTorch version (GPU?): 1.7.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

### Who can help

@patrickvonplaten 

## Information

Model I am using GPT2LMHeadModel:

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

Generate sequences using with the following snippet:
```python
model.generate(
        input_ids,
        do_sample=False,
        num_beams=beam_width,
        num_return_sequences=beam_width,
        early_stopping=False,
        output_scores=True,
        return_dict_in_generate=True,
)
```

Generate 

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:

1. Try to generate sequences as mentioned above.

### Traceback

```
Traceback (most recent call last):
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/middleware/cors.py", line 86, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/middleware/cors.py", line 142, in simple_response
    await self.app(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
    await route.handle(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
    await self.app(scope, receive, send)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
    raw_response = await run_endpoint_function(
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/fastapi/routing.py", line 150, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/starlette/concurrency.py", line 34, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "./server.py", line 47, in doSampleGPT2
    results = sampleGPT2v2(model=model, tokenizer=tokenizer, sequence=src)
  File "./ccompletion/samplers/gpt2sampler.py", line 151, in sampleGPT2v2
    outputs = model.generate(
  File "/Users/miguelvictor/.virtualenvs/transformers/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
    return func(*args, **kwargs)
  File "/Users/miguelvictor/Projects/transformers/src/transformers/generation_utils.py", line 943, in generate
    return self.beam_search(
  File "/Users/miguelvictor/Projects/transformers/src/transformers/generation_utils.py", line 1655, in beam_search
    input_ids, beam_scores, next_tokens, next_indices, pad_token_id=pad_token_id, eos_token_id=eos_token_id
UnboundLocalError: local variable 'next_tokens' referenced before assignment
```

## Expected behavior

No errors raised.


Comments:
Hey @miguelvictor, the problem is that `max_length` is set to a value that is too small. You need to increase either,

```model.config.max_length``` or pass a `max_length` parameter to `generate()` that is longer than your input_ids.

Ohh... my bad. Thank you!