AttributeError when using EncoderDecoderModel.forward() with encoder_outputs and return_dict=True
Author: aizawa-naoki
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.6.0
- Platform: macOS-10.15.7-x86_64-i386-64bit
- Python version: 3.9.4
- PyTorch version (GPU?): 1.8.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help
@patrickvonplaten, @patil-suraj


## Information

Model I am using (Bert, XLNet ...): encoder=decoder="gpt2"

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce
```python3:code.py
from transformers import EncoderDecoderModel, GPT2Tokenizer
import torch

tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = EncoderDecoderModel.from_encoder_decoder_pretrained("gpt2", "gpt2")

enc_input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True)).unsqueeze(0)
dec_input_ids = torch.tensor([[model.config.decoder.eos_token_id]])

outputs = model(input_ids=enc_input_ids, decoder_input_ids=dec_input_ids, encoder_outputs=None, return_dict=True)
_, _, enc_h = outputs.values() # (logits, past_key_values, encoder_last_hidden_states)
enc_h = (enc_h, ) # *1(link below) requests that I should make tuple for "encoder_outputs" argument ↓
outputs = model(input_ids=enc_input_ids, decoder_input_ids=dec_input_ids, encoder_outputs=enc_h, return_dict=True)# Error occured @ this line.
```
[*1:Doc](https://huggingface.co/transformers/model_doc/encoderdecoder.html#transformers.EncoderDecoderModel.forward) 

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## behavior
![image](https://user-images.githubusercontent.com/6253193/118772221-7455a900-b8be-11eb-8e36-125c7402ca4b.png)



## Expected behavior
No Error at modeling_encoder_decoder.py line 463.

# Cause of Error
In [modeling_encoder_decoder.py line435](https://github.com/huggingface/transformers/blob/680d181ce80070f89f0ebd49bf93ca29b24cd56b/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py#L435), "encoder_outputs" need to behave as Iterable (and the encoder-decoder-model documentation request Tuple as argument).

But, around [line 463](https://github.com/huggingface/transformers/blob/680d181ce80070f89f0ebd49bf93ca29b24cd56b/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py#L463), "encoder_outputs" need to behave something else.




Comments:
Hey @aizawa-naoki,

Thanks for your bug report here. 

The problem here is that the model expects the inputs and outputs to be of type `ModelOutput` by setting `return_dict=True`.
However, `encoder_outputs` is passed as a tuple and not as a `ModelOutput` which leads to an error. You could fix your code as follows:

```python
from transformers import EncoderDecoderModel, GPT2Tokenizer
from transformers.modeling_outputs import BaseModelOutput
import torch

tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = EncoderDecoderModel.from_encoder_decoder_pretrained("gpt2", "gpt2")

enc_input_ids = torch.tensor(tokenizer.encode("Hello, my dog is cute", add_special_tokens=True)).unsqueeze(0)
dec_input_ids = torch.tensor([[model.config.decoder.eos_token_id]])

outputs = model(input_ids=enc_input_ids, decoder_input_ids=dec_input_ids, encoder_outputs=None, return_dict=True)
_, _, enc_h = outputs.values() # (logits, past_key_values, encoder_last_hidden_states)

outputs = model(input_ids=enc_input_ids, decoder_input_ids=dec_input_ids, encoder_outputs=BaseModelOutput(last_hidden_state=enc_h), return_dict=True)# Error occured @ this line.
```

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.