'LlamaTokenizerFast' object has no attribute 'apply_chat_template'
Author: Manaschauhan28
Pull request: no

### System Info

I have tried the same code available on the huggingface hub but for me it is showing the error [Check here](https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat/blob/main/app.py)

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Please look into this

### Expected behavior

It should work well as it has inherited from the transformers

Comments:
Hey, can you make sure you are using the latest release of `transformers`? And if upgrading to the latest version does not work share the output of `transformers-cli env`

![Screenshot 2023-10-26 at 5 57 50 PM](https://github.com/huggingface/transformers/assets/107470066/4bb78f07-8ecb-4f01-a2ce-81cc7a93d1d9)


I can't reproduce this. The following snippets works outof the box for me: 
```python 
>>> from transformers import AutoTokenizer
>>> tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
>>> chat = [
{"role": "user", "content": "Hello, how are you?"},
{"role": "assistant", "content": "I'm doing great. How can I help you today?"},
{"role": "user", "content": "I'd like to show off how chat templating works!"},
 ]
>>> tokenizer.use_default_system_prompt = False
>>> tokenizer.apply_chat_template(chat, tokenize=False)
"

 Hello, how are you? 
 I'm doing great. How can I help you today? 


 I'd like to show off how chat templating works! 
"
```

![Screenshot 2023-10-26 at 7 12 04 PM](https://github.com/huggingface/transformers/assets/107470066/a805624c-08fd-4f0e-b235-713b2f113dce)

I tried the same and getting the same error 


can you print `print(transformers.__version__)`

Thanks for your help man. It solved with the latest version of transformers==4.34.1


Glad I helped 🤗 

Note: If you install `transformers` through conda, it'll install an older version. For me, it installed v4.32.1 instead of the current pip version 4.36.2.

> Note: If you install `transformers` through conda, it'll install an older version. For me, it installed v4.32.1 instead of the current pip version 4.36.2.

This helped a lot, thanks - had to "pip install" within the conda environment to get transformers updated.

thia my `transformers` version: 4.39.3, but it still failed. pls help, thanks.

**The error:**
Traceback (most recent call last):
  File "e:\AI\deepsppekCoder7B\deepspeek.py", line 7, in <module>
    inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device) 
AttributeError: '**LlamaTokenizerFast' object has no attribute 'apply_chat_template'**


**code:**
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True).cuda()
messages=[
    { 'role': 'user', 'content': "write a quick sort algorithm in python."}
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)

outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))


You are using `trust_remote_code=True` 

Also, I found that if you are trying to pass tokenizer as a variable to another function, it will be the same ERROR:LlamaForCausalLM' object has no attribute 'apply_chat_temple'. Very weird in LLAMA3-70B but never encountering this problem in other LLM models

> thia my `transformers` version: 4.39.3, but it still failed. pls help, thanks.
> 
> **The error:** Traceback (most recent call last): File "e:\AI\deepsppekCoder7B\deepspeek.py", line 7, in inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device) AttributeError: '**LlamaTokenizerFast' object has no attribute 'apply_chat_template'**
> 
> **code:** from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True).cuda() messages=[ { 'role': 'user', 'content': "write a quick sort algorithm in python."} ] inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
> 
> outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id) print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))

you should update the latest version. pip install --upgrade transformers   (4.44.2 is ok)

> > thia my `transformers` version: 4.39.3, but it still failed. pls help, thanks.
> > **The error:** Traceback (most recent call last): File "e:\AI\deepsppekCoder7B\deepspeek.py", line 7, in inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device) AttributeError: '**LlamaTokenizerFast' object has no attribute 'apply_chat_template'**
> > **code:** from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("E:\AI\deepsppekCoder7B", trust_remote_code=True).cuda() messages=[ { 'role': 'user', 'content': "write a quick sort algorithm in python."} ] inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
> > outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id) print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
> 
> you should update the latest version. pip install --upgrade transformers (4.44.2 is ok)

solved it. Many thanks. Was using Python 3.7 and Transformers 4.30.2, got same object has no attribute 'apply_chat_template' problem.
Change to Python 3.8.10 and install Transformer 4.46.1, the problem is solved, model is able to run