Switch from return_tuple to return_dict
Author: sgugger
Pull request: yes

This is the first step in the change of model outputs as described on [the forum](https://discuss.huggingface.co/t/new-model-output-types/195/8).

This PR removes the argument `return_tuple` and introduces `return_dict` (that works the other way round) and all models now return tuple by default (100% full backward compatibility) unless you opt-in the new model output types with `return_dict=True`. The model output class is changed to the dict-like one that should work equally well for TensorFlow.

I have normally updated all examples in the docs to instantiate the model with `return_dict=True` but more docs will follow in other PRs. For the tests, I have set `return_dict=True` in one of the common tests just to make sure it actually works. Step 2 (in a follow-up PR) will be to use it in all tests.

Step 3 is then going to update the TensorFlow models to use this `ModelOutput`.

Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=h1) Report
> Merging [#6138](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/8a8ae27617e3c4dafb34bcbbaadf4ceee28583bd&el=desc) will **increase** coverage by `0.99%`.
> The diff coverage is `71.96%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/6138/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #6138      +/-   ##
==========================================
+ Coverage   78.49%   79.48%   +0.99%     
==========================================
  Files         146      146              
  Lines       26335    26441     +106     
==========================================
+ Hits        20671    21017     +346     
+ Misses       5664     5424     -240     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/\_\_init\_\_.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9fX2luaXRfXy5weQ==) | `99.24% <ø> (ø)` | |
| [src/transformers/modeling\_auto.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19hdXRvLnB5) | `78.48% <ø> (ø)` | |
| [src/transformers/modeling\_camembert.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19jYW1lbWJlcnQucHk=) | `100.00% <ø> (ø)` | |
| [src/transformers/modeling\_encoder\_decoder.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19lbmNvZGVyX2RlY29kZXIucHk=) | `92.20% <ø> (ø)` | |
| [src/transformers/modeling\_xlm\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ194bG1fcm9iZXJ0YS5weQ==) | `100.00% <ø> (ø)` | |
| [src/transformers/trainer.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyLnB5) | `40.96% <ø> (-0.04%)` | :arrow_down: |
| [src/transformers/training\_args\_tf.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmluZ19hcmdzX3RmLnB5) | `47.45% <0.00%> (ø)` | |
| [src/transformers/trainer\_tf.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyX3RmLnB5) | `16.54% <8.66%> (+0.06%)` | :arrow_up: |
| [src/transformers/modeling\_mmbt.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19tbWJ0LnB5) | `23.47% <11.11%> (-0.63%)` | :arrow_down: |
| [src/transformers/file\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9maWxlX3V0aWxzLnB5) | `80.56% <68.08%> (-1.65%)` | :arrow_down: |
| ... and [40 more](https://codecov.io/gh/huggingface/transformers/pull/6138/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=footer). Last update [8a8ae27...60928b0](https://codecov.io/gh/huggingface/transformers/pull/6138?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


@sgugger thanks very much for this PR!

`return_dict` seems to work with the `from_pretrained()` method for models, but what if I didn't want to use `from_pretrained()` and simply instantiated the model from scratch as follows:

```
config_class = GPT2Config
model_class = GPT2DoubleHeadsModel
config = config_class.from_pretrained("gpt2")
model = model_class(config)
```

I still want to be able to use `return_dict`. How would I go about doing that?

It looks like I could pass `return_dict` explicitly in the `forward()` for the from-scratch case. However, I want the `forward()` call in my code to be consistent across the from-scratch and the `from_pretrained()` settings, in order to decouple the model instantiation from the actual trainer loop.

How should this be handled?

Would the solution be something like this:

```
config_class = GPT2Config
model_class = GPT2DoubleHeadsModel
config = config_class.from_pretrained("gpt2", use_return_dict=True)
model = model_class(config)
```

I tried this solution but it didn't work, it gave me the following error:

```
>>> from transformers import GPT2Config
>>> config = GPT2Config.from_pretrained("gpt2", use_return_dict=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/transformers/configuration_utils.py", line 312, in from_pretrained
    return cls.from_dict(config_dict, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/configuration_utils.py", line 406, in from_dict
    setattr(config, key, value)
AttributeError: can't set attribute
```

The right line is:
```
config = config_class.from_pretrained("gpt2", return_dict=True)
```
`use_return_dict` is an inner attribute that combines `return_dict` and `torchscript` (since torchscript is incompatible with `return_dict=True`)