Tf model outputs
Author: sgugger
Pull request: yes

This PR continues the work on model outputs and treats all TF models (except T5) to use them. Since the new output type is opt-in only (default to `return_dict` is `False`) there is no breaking changes.

In the tests, I've enabled the new output types and this makes two changes necessary:
- we can no longer unpack outputs like tuple (since they are dict-likes)
- after using SavedModel and reloading, the outputs become a dictionary with no special properties (so we can't index by integers or access keys as attributes).

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

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

```diff
@@            Coverage Diff             @@
##           master    #6247      +/-   ##
==========================================
+ Coverage   78.30%   79.43%   +1.12%     
==========================================
  Files         146      147       +1     
  Lines       26597    27120     +523     
==========================================
+ Hits        20828    21543     +715     
+ Misses       5769     5577     -192     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/6247?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/\_\_init\_\_.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9fX2luaXRfXy5weQ==) | `99.24% <ø> (ø)` | |
| [src/transformers/configuration\_encoder\_decoder.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX2VuY29kZXJfZGVjb2Rlci5weQ==) | `100.00% <ø> (ø)` | |
| [src/transformers/configuration\_xlnet.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9jb25maWd1cmF0aW9uX3hsbmV0LnB5) | `94.33% <ø> (ø)` | |
| [src/transformers/modeling\_encoder\_decoder.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19lbmNvZGVyX2RlY29kZXIucHk=) | `92.20% <ø> (ø)` | |
| [src/transformers/modeling\_outputs.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19vdXRwdXRzLnB5) | `100.00% <ø> (ø)` | |
| [src/transformers/modeling\_t5.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190NS5weQ==) | `83.33% <0.00%> (-0.38%)` | :arrow_down: |
| [src/transformers/modeling\_tf\_auto.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9hdXRvLnB5) | `66.66% <ø> (ø)` | |
| [src/transformers/modeling\_tf\_camembert.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9jYW1lbWJlcnQucHk=) | `100.00% <ø> (ø)` | |
| [src/transformers/modeling\_tf\_xlm\_roberta.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl94bG1fcm9iZXJ0YS5weQ==) | `100.00% <ø> (ø)` | |
| [src/transformers/modeling\_xlnet.py](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ194bG5ldC5weQ==) | `81.75% <ø> (ø)` | |
| ... and [41 more](https://codecov.io/gh/huggingface/transformers/pull/6247/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/6247?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/6247?src=pr&el=footer). Last update [e4920c9...fe68f7d](https://codecov.io/gh/huggingface/transformers/pull/6247?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


> I would have just one question, in some tests you assume that the models return a dict and in some other you look at the instance of the output. Why not harmonizing and taking for all tests one or another?

I went for the quickest usually, because the PR is very big as it is. I think we should strive to harmonize the tests in a follow-up PR, if that's ok, and not only inside the TF tests but ideally the PT/TF tests.

> I went for the quickest usually, because the PR is very big as it is. I think we should strive to harmonize the tests in a follow-up PR, if that's ok, and not only inside the TF tests but ideally the PT/TF tests.

Ok fine, good for me!

Still two small comments. Also can you rerun the two slow tests I gave you yesterday but just on T5?

Fixed the wrong key for the slow tests, but there is a failure which was there before AFAICT: the model returns the past key values after the save but not before. It seems like when evaluating the model, config.use_cache is False, but it's True after.

> We should be careful about merge conflicts with #6260 and #6227

https://github.com/huggingface/transformers/pull/6260 has been updated to reflect these changes.