Multi predictions trainer
Author: sgugger
Pull request: yes

This allows the `Trainer` to properly return predictions when the model has several outputs (for instance, all models `XxxForMultipleChoice`). This should unlock progress in #7032 where the start and end logits are both required.


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

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

```diff
@@            Coverage Diff             @@
##           master    #7126      +/-   ##
==========================================
+ Coverage   79.12%   80.84%   +1.71%     
==========================================
  Files         168      168              
  Lines       32303    32305       +2     
==========================================
+ Hits        25560    26117     +557     
+ Misses       6743     6188     -555     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/7126?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/trainer.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyLnB5) | `55.04% <70.00%> (+0.13%)` | :arrow_up: |
| [src/transformers/trainer\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmVyX3V0aWxzLnB5) | `60.29% <100.00%> (ø)` | |
| [src/transformers/modeling\_tf\_funnel.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9mdW5uZWwucHk=) | `18.53% <0.00%> (-75.51%)` | :arrow_down: |
| [src/transformers/modeling\_marian.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19tYXJpYW4ucHk=) | `60.00% <0.00%> (-30.00%)` | :arrow_down: |
| [src/transformers/activations.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9hY3RpdmF0aW9ucy5weQ==) | `85.00% <0.00%> (-5.00%)` | :arrow_down: |
| [src/transformers/generation\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9nZW5lcmF0aW9uX3RmX3V0aWxzLnB5) | `84.21% <0.00%> (-1.76%)` | :arrow_down: |
| [src/transformers/modeling\_bart.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ19iYXJ0LnB5) | `93.77% <0.00%> (-0.51%)` | :arrow_down: |
| [src/transformers/modeling\_tf\_bert.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl9iZXJ0LnB5) | `98.38% <0.00%> (-0.36%)` | :arrow_down: |
| [src/transformers/tokenization\_utils\_base.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90b2tlbml6YXRpb25fdXRpbHNfYmFzZS5weQ==) | `93.77% <0.00%> (-0.28%)` | :arrow_down: |
| [src/transformers/file\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9maWxlX3V0aWxzLnB5) | `82.84% <0.00%> (-0.25%)` | :arrow_down: |
| ... and [17 more](https://codecov.io/gh/huggingface/transformers/pull/7126/diff?src=pr&el=tree-more) | |

------

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


Yes this doesn't work if the model has `output_attentions` or `output_hiddens` in the config set to True: it needs the outputs to be a tuple of tensor with optional loss at the beginning. Documenting this is next when I make a template/protocol for models that `Trainer` supports. I can add a clean error message if one output is detected to be a tuple of tensors and add asserts that `output_attention` and `output_all_hiddens` are False in the config (if those arguments can be found).

@sgugger are you saying that the eval in Trainer-backed https://github.com/huggingface/transformers/blob/master/examples/multiple-choice/run_multiple_choice.py is not currently working? 

I'm pretty sure he meant `XxxForQuestionAnswering`, not multiple choice

> I'm pretty sure he meant `XxxForQuestionAnswering`, not multiple choice

Oh yes, makes sense now. Thanks @LysandreJik ;)

Yes @LysandreJik reads my thoughts right, sorry about the typo ;-)