When using transformers.DataCollatorWithPadding normally, always get annoying warning
Author: JulesGM
Pull request: no
Labels: name: Good Second Issue

### Explanation

So systematically, people who use `transformers.DataCollatorWithPadding` get 

```python
You're using a T5TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.
```

when the collator is called, because it's called on pre-tokenized samples. Now, I feel like it's still faster to pre-tokenize once & then dynamically pad batches (because samples can be shuffled), than only live tokenize, & tokenizing to fixed `max_length` is just very sub-optimal from a compute and memory standpoint. 

So, I feel like that warning should be disabled at least when using the collator, & using it as intented.

@ArthurZucker  @sgugger


Comments:
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.

Sorry this slipped through the cracks. If you have a way to disable the warning for the data collator, I'm happy to look at a PR!

The simplest would be to add an argument to `tokenizer.pad` that defaults to `False` that is something like `supress_warning_slow: bool = False`, & when it's passed as `True`, the warning is not emitted.  

This warning is genreated from [here](https://github.com/huggingface/transformers/blob/003a0cf8cc4d78e47ef9debfb1e93a5c1197ca9a/src/transformers/tokenization_utils_base.py#L2949), an easy way to turn off is
```python
tokenizer = AutoTokenizer.from_pretrained(...)
tokenizer.deprecation_warnings["Asking-to-pad-a-fast-tokenizer"] = True
```

Oh I didn't know that! Do you want to make a PR to add this in `DataCollatorWithPadding`?

What is the recommendation? Should we pre-pad together with tokenization or leave that to the collator, when using a fast tokenizer? Has anyone done any performance comparison?

https://github.com/huggingface/transformers/pull/23742

> 

If you need to tokenize the data before training, just turn off this warning, if you can do tokenization during training(for small datasets or only train once), you can use the fast tokenizer in a custom data collector function without calling ```tokenizer.pad```.

It's weird to me that when using the official Transformers data collators, the warnings are be emitted. I feel like they shouldn't. That is the point of this issue.

I feel like the fact that one decides to use the collators means that the warnings should indeed be disabled. 

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.

Hello, what is the status of this fix ? Was it merged ? I look for it but I still get the warning message

I just didn't have the time to do it, had to finish my thesis & do
interviews.
You're welcome to try to figure this out.

On Tue, Dec 19, 2023, 4:50 PM Daniel Bustamante Ospina <
***@***.***> wrote:

> Hello, what is the status of this fix ? Was it merged ? I look for it but
> I still get the warning message
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/transformers/issues/22638#issuecomment-1863521135>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAYU34OTHDOTBIECC6S4HVLYKID2RAVCNFSM6AAAAAAWVZYVB2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRTGUZDCMJTGU>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


Thanks for the reply @JulesGM , I think that I could take your advances (indeed you already solved the issue) and give it a try :)

This warning is genreated from [here](https://github.com/huggingface/transformers/blob/003a0cf8cc4d78e47ef9debfb1e93a5c1197ca9a/src/transformers/tokenization_utils_base.py#L2949), an easy way to turn off is:

```python
import os
os.environ['TRANSFORMERS_NO_ADVISORY_WARNINGS'] = 'true'
```

Closing because of https://github.com/huggingface/transformers/pull/28213