Using LLaMA2 fast tokenizer gives zero loss
Author: cnut1648
Pull request: no

### System Info

- `transformers` version: 4.36.2
- Platform: Linux-6.2.0-37-generic-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.20.1
- Safetensors version: 0.4.1
- Accelerate version: 0.25.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.1 (True)
- Tensorflow version (GPU?): 2.13.1 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: yes

### Who can help?

@pacman100, @ArthurZucker , @younesbelkada

### 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

Using fast tokenizer would give me a zero loss on my own data no matter what hyperparameters I use (even with extremely high learning rate like 0.1 and 10). However I notice that if I switch to standard tokenizer (`use_fast=False`) then I can have a normal behavior.
The command I have is 
```shell
deepspeed --master_port 12345 --num_gpus=4 train.py --bf16 --deepspeed ./deepspeed_config/zero3-offload.json
    --model_name_or_path NousResearch/Llama-2-7b-hf --do_train
    --data_path dataset/chat_data --output_dir output_path
    --per_device_train_batch_size=4 --per_device_eval_batch_size=1 --num_train_epochs=3 --lr_scheduler_type=cosine --gradient_accumulation_steps=4 --gradient_checkpointing=True
    --overwrite_output_dir --seed 42 --report_to=none --learning_rate 2e-5 --weight_decay=0.01 --logging_steps=1
```
The `train.py` is modified from [`run_clm.py`](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_clm.py) but I change the train_data  with [fastchat](https://github.com/lm-sys/FastChat) formatted dataset. Specifically, the train_data is:
```python

    class SupervisedDataset(torch.utils.data.Dataset):
        """Dataset for supervised fine-tuning."""

        def __init__(self, raw_data, tokenizer: transformers.PreTrainedTokenizer):
            super(SupervisedDataset, self).__init__()

            sources = [example["conversations"] for example in raw_data]
            data_dict = preprocess(sources, tokenizer)

            self.input_ids = data_dict["input_ids"]
            self.labels = data_dict["labels"]
            self.attention_mask = data_dict["attention_mask"]

        def __len__(self):
            return len(self.input_ids)

        def __getitem__(self, i) -> Dict[str, torch.Tensor]:
            return dict(
                input_ids=self.input_ids[i],
                labels=self.labels[i],
                attention_mask=self.attention_mask[i],
            )
   train_dataset = SupervisedDataset(raw_datasets["train"], tokenizer)
``` 
where `preprocess` is [imported](https://github.com/lm-sys/FastChat/blob/main/fastchat/train/train.py#L92-L177) from fastchat, and the `raw_datasets['train']` is a filtered version of https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k which I unfortunately cannot share. But I mainly would like to ask if there are some issues with LLaMA's fast tokenizer.
The tokenizer is built with `AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-hf", use_fast=True)`

Thanks. 

### Expected behavior

Fasttokenizer should not affect training dynamics.

Comments:
BTW similar issue seems to happen on mistral as well. Training on the same data, non-fast tokenizer gives ~1 loss while fast tokenizer gives > 10 loss.

There are know issues with LlamaFast tokenizer, could you try with this: #26678 

```python
from tokenizers import pre_tokenizers, normalizers
from transformers import AutoTokenizer
old_tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
old_tokenizer._tokenizer.normalizer = normalizers.Sequence([])
old_tokenizer._tokenizer.pre_tokenizer = pre_tokenizers.Metaspace("▁", True, prepend_scheme = "first")
```

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.