Llama 3.1 Instruct: `add_generation_prompt=False` still appends assistant prompt
Author: hav4ik
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.44.0.dev0
- Platform: Linux-6.1.85+-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.23.5
- Safetensors version: 0.4.3
- Accelerate version: 0.32.1
- Accelerate config: 	not found
- PyTorch version (GPU?): 2.3.1+cu121 (False)
- Tensorflow version (GPU?): 2.15.0 (False)
- Flax version (CPU?/GPU?/TPU?): 0.8.4 (cpu)
- Jax version: 0.4.26
- JaxLib version: 0.4.26
- Using distributed or parallel set-up in script?: it is reproducible in any setup, even CPU one

### Who can help?

@ArthurZucker - this is a tokenizer issue of Llama 3.1 instruct

### 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

Just execute this simple code:
```python
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
messages = [
    {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
    {"role": "user", "content": "Who are you?"},
    {"role": "assistant", "content": "I am you"},
]
print(tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=False))
```
The output will be:
```


system


You are a pirate chatbot who always responds in pirate speak!

user


Who are you?

assistant


I am you

assistant


```
The final `
assistant
` shouldn't be there!

This bug, in theory, does not affect the training process though. During inference, everything after the last `
` or `
` will be ignored anyways.

### Expected behavior

The output is expected to be without the final assistant prompt, just like in Llama-3-8B-Instruct:
```


system


You are a pirate chatbot who always responds in pirate speak!

user


Who are you?

assistant


I am you

```

Comments:
As far as I can tell, this is an issue of the chat_template in the huggingface hub repo, not from transformers (which is only correctly applying what is in the tokenizer_config.json)

https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct/discussions/44
https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct/discussions/53

cc @Rocketknight1 it would be very nice to take a look at this and clarify what's happening. Thanks!

Yes, this issue is caused by the chat template, and so the bug isn't part of Transformers itself. We have PRs open on all of the 3.1-Instruct repos to fix this and add proper tool use support! 

Chat template PRs should now be merged.

@Rocketknight1  
Now we have the following output, the following string is added to the prompt, is it expected? 
```
Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024
```

```
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
messages = [
    {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
    {"role": "user", "content": "Who are you?"},
    {"role": "assistant", "content": "I am you"},
]
print(tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=False))
```

outputs 

```


system


Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024

You are a pirate chatbot who always responds in pirate speak!

user


Who are you?

assistant


I am you

```

@kzhang-dm, yes, that is expected!