AttributeError: 'GPT2LMHeadModel' object has no attribute 'generate'
Author: jsh9
Pull request: no
Labels: name: wontfix

## 🐛 Bug

<!-- Important information -->

The example script `run_generation.py` is broken with the error message `AttributeError: 'GPT2LMHeadModel' object has no attribute 'generate'`


## To Reproduce

Steps to reproduce the behavior:

1. In a terminal, cd to `transformers/examples` and then `python run_generation.py --model_type=gpt2 --model_name_or_path=gpt2`
2. After the model binary is downloaded to cache, enter anything when prompted "`Model prompt >>>`"
3. And then you will see the error:

```
Traceback (most recent call last):
  File "run_generation.py", line 236, in <module>
    main()
  File "run_generation.py", line 216, in main
    output_sequences = model.generate(
  File "C:\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 585, in __getattr__
    type(self).__name__, name))
AttributeError: 'GPT2LMHeadModel' object has no attribute 'generate'
```

<!-- If you have a code sample, error messages, stack traces, please provide it here as well. -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

* OS: Windows 10
* Python version: 3.7.3
* PyTorch version: 1.3.1
* PyTorch Transformers version (or branch): 2.2.2
* Using GPU ? N/A
* Distributed of parallel setup ? N/A
* Any other relevant information:

I'm running the latest version of `run_generation.py`. Here is the permanent link: https://github.com/huggingface/transformers/blob/ce50305e5b8c8748b81b0c8f5539a337b6a995b9/examples/run_generation.py

## Additional context

<!-- Add any other context about the problem here. -->


Comments:
Same problem

I have found the reason.

So it turns out that the `generate()` method of the `PreTrainedModel` class is newly added, even newer than the latest release (2.3.0). Quite understandable since this library is iterating very fast.

So to make `run_generation.py` work, you can install this library like this:

- Clone the repo to your computer
- cd into the repo
- Run `pip install -e .` (don't forget the dot)
- Re-run `run_generation.py`

I'll leave this ticket open until the `generate()` method is incorporated into the latest release.

@jsh9's solution worked for me!

Also, if you want to avoid doing the manual steps, you can just `pip install` directly from the `master` branch by running:

```bash
pip install git+https://github.com/huggingface/transformers.git@master#egg=transformers
```


i was getting the same error then i used repository before 7days which is working fine for me 
`!wget https://github.com/huggingface/transformers/archive/f09d9996413f2b265f1c672d7a4b438e4c5099c4.zip`

then unzip with

`!unzip file_name.zip`

there is some bugs in recent update, hope they fix it soon

@Weenkus's way worked for me. In `requirements.txt` you can use;
```
-e git+https://github.com/huggingface/transformers.git@master#egg=transformers
```

(all on one line)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.