DataCollatorForLanguageModeling call of tokenizer.pad causes crash
Author: condor-cp
Pull request: no

### System Info

- `transformers` version: 4.30.2
- Platform: Linux-5.19.0-45-generic-x86_64-with-glibc2.35
- Python version: 3.10.6
- Huggingface_hub version: 0.15.1
- Safetensors version: 0.3.1
- PyTorch version (GPU?): 2.0.1+cu117 (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>

### Who can help?

@ArthurZucker

### Information

- [ ] The official example scripts
- [X] 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

```python
from transformers import AutoTokenizer, DataCollatorForLanguageModeling

tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")

multiple_length_batch = [
    {
        "input_ids": [0, 51, 51, 2],
        "labels": [0, 51, 51, 2],
    },
    {
        "input_ids": [0, 10, 11, 12, 13, 2],
        "labels": [0, 10, 11, 12, 13, 2],
    },
]

data_collator = DataCollatorForLanguageModeling(
    tokenizer=tokenizer,
    mlm_probability=0.15,
)

data_collator.torch_call(multiple_length_batch)
```

Causes 
```sh
ValueError: Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' 'truncation=True' to have batched tensors with the same length. Perhaps your features (`labels` in this case) have excessive nesting (inputs type `list` where type `int` is expected).
```

### Expected behavior

I simplified the problem analysis, the minimal example of the bug reproduction was found by calling a trainer using this same datacollator, (the failing function gets called here : https://github.com/huggingface/transformers/blob/e84bf1f734f87aa2bedc41b9b9933d00fc6add98/src/transformers/data/data_collator.py#L45)

In the case input_ids and labels are not padded manually before, this causes DataCollatorForLanguageModeling to crash here : 
https://github.com/huggingface/transformers/blob/e84bf1f734f87aa2bedc41b9b9933d00fc6add98/src/transformers/data/data_collator.py#L732

, before "labels" are padded a few line after here : 
https://github.com/huggingface/transformers/blob/e84bf1f734f87aa2bedc41b9b9933d00fc6add98/src/transformers/data/data_collator.py#L748

I suspect the conversion to pytorch tensor should be done after labels are also padded by this line and not before.


Comments:
This data collator is not meant to be used with labels in your data. It builts the labels from the input IDs (either by masking random tokens or copying the inputs).

I understand thank you. Then this line in the documentation is misleading, since it prepares a 'labels' feature (which works in the example because all samples are the same size) : 
https://github.com/huggingface/transformers/blob/daccde143d646e4fec8d52cc870b8c7fd1d2581c/docs/source/en/tasks/masked_language_modeling.md?plain=1#L171

Maybe in the case a 'labels' feature is provided, the error could be caught earlier than trying to convert to pytorch tensor ?

Yes this line should probably be removed. I think it's a copy-paste from a case in our examples where we use the standard data collator after.

Ok thank you I will pull-request this line removal.

@sgugger what if I do want to use labels and this data collator? specifically in my case i create the labels myself and put -100 in all "user" messages of a conversation. is there some parameter I can use? or do I have to create my own data collator?