Using Trainer with custom model caused dimension error
### System Info

```
- `transformers` version: 4.31.0
- Platform: Windows-10-10.0.19045-SP0
- Python version: 3.11.4
- Huggingface_hub version: 0.16.4
- Safetensors version: 0.3.1
- Accelerate version: 0.21.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.1+cu118 (True)
- 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?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
```

Not sure if it's the intended way of using the Trainer clas, but what I did was:
- Created a custom image+text classifier where the image encoder and text encoders are huggingface models (i.e., Bert, ViT) and I extracted the last hidden state from each embedding, concatenated them, and added a linear layer for binary classification.
- I modified the `compute_loss` function by subclassing the Trainer class but didn't do anything else.

The issue was, since the model class only outputs logits but nothing else (not dict, not tuple), this part of the code: https://github.com/huggingface/transformers/blob/main/src/transformers/trainer.py#L3344-L3347 where since the output from model forward isn't a dict, it assumed it's a tuple, and trimmed the first sample's logits in the batch causing dimension error when computing the loss since labels and logits dimensions don't match (off by # of batches).

This is probably solvable by modifying the model class to return what the trainer is expecting, but it's not communicated clearly either, maybe it's because the Trainer isn't fully suitable for custom model training?

I have created a commit in my branch to fix this on my side so that the training can continue: https://github.com/huggingface/transformers/compare/main...zhangyilun:transformers:allow-logits-only-outputs. Not sure if it's worth merging into the repo. I think the change shouldn't break anything else.

If you think I'm doing things wrong or I missed anything, please correct me!

### Who can help?

_No response_

### Information

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

### Tasks

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

### Reproduction

Create a custom binary classification model where the forward method only returns the logits.
Use the Trainer class for training.

### Expected behavior

Dimension mismatch in compute_loss method.
cc our trainer master @sgugger , but I think the best is to follow the standard output format (i.e. either tuple or dict)<|||||>This is communicated clearly on the [Trainer doc page](https://huggingface.co/docs/transformers/main_classes/trainer), scroll a bit to the big warning.<|||||>Thank you for pointing me to the doc!