Add Doc Test GPT-2
Author: ArEnSc
Pull request: yes

# What does this PR do?
Fixes the broken doc tests for GPT-2
Apart of the documentation sprint work.

Fixes [Github issue] (https://github.com/huggingface/transformers/issues/16292)

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a [Github issue](https://github.com/huggingface/transformers/issues/16292)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?
gpt2: @patrickvonplaten, @LysandreJik
Documentation: @sgugger


Comments:
_The documentation is not available anymore as the PR was closed or merged._

I think this is what is required something up with CI failing code quality check? 
```
#!/bin/bash -eo pipefail
black --check examples tests src utils
Skipping .ipynb files as Jupyter dependencies are not installed.
You can fix this by running ``pip install black[jupyter]``
would reformat src/transformers/models/gpt2/modeling_gpt2.py

Oh no! 💥 💔 💥
1 file would be reformatted, 1510 files would be left unchanged.

Exited with code exit status 1
CircleCI received exit code 1
```

Yes, you need to run `make style` on your branch to make that test pass :-)

Pinging @ydshieh on this PR since Patrick is on vacation this week.

Hi, @ArEnSc

Thank you for this PR!

In order to run `make style`, you will need to run

```
pip install transformers[quality]
```

If you haven't done this before.

```Run python -m pytest -n [2](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:2) --dist=loadfile -s --make-reports=tests_new_models tests/bert_new/test_modeling_bert_new.py
  python -m pytest -n 2 --dist=loadfile -s --make-reports=tests_new_models tests/bert_new/test_modeling_bert_new.py
  shell: /usr/bin/bash -e {0}
/usr/lib/python[3](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:3)/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.9) or chardet (3.0.[4](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:4)) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/runner/.local/lib/python3.8/site-packages/pytest/__main__.py", line [5](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:5), in <module>
    raise SystemExit(pytest.console_main())
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 145, in main
    config = _prepareconfig(args, plugins)
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/runner/.local/lib/python3.8/site-packages/pluggy/_hooks.py", line 2[6](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:6)5, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/runner/.local/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/runner/.local/lib/python3.8/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/home/runner/.local/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/runner/.local/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1016, in pytest_cmdline_parse
    self.parse(args)
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1304, in parse
    self._preparse(args, addopts=addopts)
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 118[7](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:7), in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/runner/.local/lib/python3.[8](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:8)/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line [9](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:9)91, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line [10](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:10)[14](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:14), in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line [16](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:16)8, in exec_module
    exec(co, module.__dict__)
  File "/home/runner/.local/lib/python3.8/site-packages/dash/__init__.py", line 5, in <module>
    from .dash import Dash, no_update  # noqa: F401,E402
  File "/home/runner/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
    exec(co, module.__dict__)
  File "/home/runner/.local/lib/python3.8/site-packages/dash/dash.py", line [18](https://github.com/huggingface/transformers/runs/5729180598?check_suite_focus=true#step:6:18), in <module>
    from werkzeug.debug.tbtools import get_current_traceback
ImportError: cannot import name 'get_current_traceback' from 'werkzeug.debug.tbtools' (/home/runner/.local/lib/python3.8/site-packages/werkzeug/debug/tbtools.py)
````

```
I did run 
make fixup 
make style
Then I also merged master what am I missing for this last piece.
lmk if I am missing something
```


Hi, @ArEnSc 

For this sprint, you don't need to test the model, but just to test the docstrings in model files.

You can see a guide here [For Python files](https://github.com/huggingface/transformers/tree/main/docs#for-python-files).

Before you run, you need to 

```python
pip install -e ".[dev]"
```

Let me know if this works for you.

> Hi, @ArEnSc
> 
> For this sprint, you don't need to test the model, but just to test the docstrings in model files.
> 
> You can see a guide here [For Python files](https://github.com/huggingface/transformers/tree/main/docs#for-python-files).
> 
> Before you run, you need to
> 
> ```python
> pip install -e ".[dev]"
> ```
> 
> Let me know if this works for you.

Yes I did run the required commands specifically:
```
python utils/prepare_for_doc_test.py src docs #line1 This command I didn't run because I was specifically working on modeling_gpt2
python utils/prepare_for_doc_test.py src/transformers/utils/doc.py src/transformers/models/gpt2/modeling_gpt2.py

pytest --doctest-modules src/transformers/models/gpt2/modeling_gpt2.py -sv --doctest-continue-on-failure # I ran this to run
 the test
 
 python utils/prepare_for_doc_test.py src docs --remove_new_line # ran this line to get everything back to normal
```

I am unsure about how to stop CI from running the add model like runner I suppose as that error came from CI
Thanks let me know!



@ArEnSc 

For now, You can ignore the errors on **build_pr_documentation** and **Add new model like template tests** from the CI.
We are currently working on these issues internally.

@ydshieh @sgugger I think this should address the comments =)

Hi, @ArEnSc Ping me for the merge once you finish the `# fmt: off` thing mentioned by Sylvain :-)

@ydshieh this one is good to go now! =)

@ArEnSc 

```
Hopefully ignores the formatting issue.
```
--> not just a hope, dream comes True now :-)

Thank you again for the contribution. Merged!