Unable to use Trainer with T5ForQuestionAnswering
Author: sjrl
Pull request: no

### System Info

- `transformers` version: 4.31.0.dev0
- Platform: macOS-10.16-x86_64-i386-64bit
- Python version: 3.9.17
- Huggingface_hub version: 0.16.2
- Safetensors version: 0.3.1
- PyTorch version (GPU?): 2.0.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

Tagging @sgugger since this is related to the Trainer and @ArthurZucker and @younesbelkada since it is also related to the text model T5ForQuestionAnswering.

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

I first ran into this error when running the `examples/pytorch/question-answering/run_qa.py` script, but I am able to reproduce with the following minimal example:

```python
from transformers import AutoModelForQuestionAnswering, Trainer
model = AutoModelForQuestionAnswering.from_pretrained("sjrhuschlee/flan-t5-base-squad2")
trainer = Trainer(model=model)
```

This produces the error
```python
Traceback (most recent call last):
  File "/Users/sebastianlee/miniconda3/envs/sjrl_transformers/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-84527b5cd844>", line 3, in <module>
    trainer = Trainer(model=model)
  File "/Users/sebastianlee/Documents/code/sjrl_transformers/src/transformers/trainer.py", line 373, in __init__
    if hasattr(model, "is_parallelizable") and model.is_parallelizable and model.model_parallel:
  File "/Users/sebastianlee/miniconda3/envs/sjrl_transformers/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'T5ForQuestionAnswering' object has no attribute 'model_parallel'
```

I believe this could be fixed by adding 
```python
self.model_parallel = False
```
to the init method of T5ForQuestionAnswering. However, this model does not support parallelization so I wonder if it would be better to somehow update the Trainer or possibly remove the `is_parallelizable` attribute from T5ForQuestionAnswering.

### Expected behavior

For the Trainer to work with T5ForQuestionAnswering.

Comments:
Hi @sjrl 

Could you add `model.model_parallel = False` before the line `trainer = Trainer(model=model)`?

`T5ForQuestionAnswering` is recently added, and it doesn't have `parallelize` or `deparallelize` as other T5 model classes.

Or you can follow the suggestion below to use `device_map`.

```
            "`T5ForConditionalGeneration.parallelize` is deprecated and will be removed in v5 of Transformers, you"
            " should load your model with `device_map='balanced'` in the call to `from_pretrained`. You can also"
            " provide your own `device_map` but it needs to be a dictionary module_name to device, so for instance"
            " {'encoder.block.0': 0, 'encoder.block.1': 1, ...}",
```

Hey @ydshieh, thanks for the feedback!

> T5ForQuestionAnswering is recently added, and it doesn't have parallelize or deparallelize as other T5 model classes.

Haha yes, maybe I should have specified that I was the one to recently add it. I opted to not add the `parallelize` or `deparallelize` classes since they would eventually be deprecated.

And my apologies, I should have been more clear with my error. I'm not trying to use the `parallelzie` functionality at all, but since `T5ForQuestionAnswering` inherits from `T5PreTrainedModel` it automatically inherits the `is_parallelizable = True` class variable which is causing the error to be thrown. 

> Could you add model.model_parallel = False before the line trainer = Trainer(model=model)?

Definitely! I'll try this and get back to you. 

Yep, we should probably add `is_parallelizable = False` in the class

> Yep, we should probably add is_parallelizable = False in the class

I can go ahead and open a PR for this.