Allow `mlm_probability` to be set to None when `mlm`=False in `DataCollatorForLanguageModeling`
Author: KameniAlexNea
Pull request: no
Labels: name: bug

### System Info

Currently, in the `DataCollatorForLanguageModeling` class, the `mlm_probability` argument is required to be a float between 0 and 1, regardless of whether `mlm` is `True` or `False`.

However, since `mlm_probability` is only used when `mlm=True`, it would make sense to allow `mlm_probability=None` when `mlm=False`, in order to reduce confusion and unnecessary configuration.

Relevant code:
[https://github.com/huggingface/transformers/blob/51d732709e5ae424e8fb6c4e58b72057a3e413c2/src/transformers/data/data\_collator.py#L841](https://github.com/huggingface/transformers/blob/51d732709e5ae424e8fb6c4e58b72057a3e413c2/src/transformers/data/data_collator.py#L841)

```python
if self.mlm_probability < 0 or self.mlm_probability > 1:
    raise ValueError("mlm_probability should be between 0 and 1.")
```

This condition runs unconditionally and throws an error even if `mlm=False`.
This behavior might be unexpected for users who are not using masked language modeling and do not want to set `mlm_probability` at all.

**Suggested change:**

Wrap the validation and assignment of `mlm_probability` inside a conditional check for `mlm`, like this:

```python
if self.mlm:
    if self.tokenizer.mask_token is None:
        raise ValueError(...)
    if self.mlm_probability is None or self.mlm_probability < 0 or self.mlm_probability > 1:
        raise ValueError("mlm_probability should be between 0 and 1.")
    self.mlm_probability = float(self.mlm_probability)
```

This would allow users to omit `mlm_probability` (or set it to `None`) when using causal language modeling (`mlm=False`).


-----
I'm asking this because this configuration causes the training execution with the trl library (SFTTrainer, version 0.18.0) to fail.

### Who can help?

@ArthurZucker @zach-huggingface @SunMarc 

### 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

```
from trl import SFTTrainer

trainer = SFTTrainer(
      model=model,
      tokenizer=tokenizer,
      data_collator=None, # let this empty and it will create DataCollatorForLanguageModeling with mlm_prob None
      train_dataset=dataset,
      eval_dataset=eval_dataset,
      args=SFTConfig(**config),
  )

trainer.train()
```

### Expected behavior

```
if self.mlm:
    if self.tokenizer.mask_token is None:
        raise ValueError(...)
    if self.mlm_probability is None or self.mlm_probability < 0 or self.mlm_probability > 1:
        raise ValueError("mlm_probability should be between 0 and 1.")
    self.mlm_probability = float(self.mlm_probability)
```

Comments:
Sounds reasonable @KameniAlexNea, would you like to open a PR with your fix ? What I don't understand is that `mlm_probability` default is `0.15`, so you shouldn't get an error even if you don't set the value. 

Yes, I can do this (done).
Regarding your second question, It may be a change made between versions of `transformers` and some libraries are still setting this parameter to `None` to deactivate the `mlm`. 
Maybe they should just change their default value ? Or we should support both compatibility.

Related to this, trl 0.18.0 causes data_collator.py to throw an error saying tokenizer does not have an attribute called 'pad' when trying to initialize an SFTTrainer, although it does have 'pad'. The root cause for this is that the tokenizer passed into data_collator through trl 0.18.0 get switched into an 'int' object, even though you pass in exactly the 'tokenizer' object.

data_collator: DataCollatorForLanguageModeling(tokenizer=151643, mlm=False, mlm_probability=None, mask_replace_prob=0.8, random_replace_prob=0.1, pad_to_multiple_of=None, tf_experimental_compile=False, return_tensors='pt', seed=None)

This is actually a wrong DataCollatorForLanguageModeling object as the right one should be the one defined in 'trl' library, instead of the current one defined in 'transformers' library.

And because you use DataCollatorForLanguageModeling in 'transformers' library, you get the above issue with "mlm".

One quick fix should be specifically initialize SFTTrainer with DataCollatorForLanguageModeling in 'trl' library:
```
from trl.trainer.sft_trainer import DataCollatorForLanguageModeling

collator = DataCollatorForLanguageModeling(
    pad_token_id, completion_only_loss, pad_to_multiple_of
)

trainer = SFTTrainer(
    data_collator = collator,
)
```

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/main/CONTRIBUTING.md) are likely to be ignored.