# Chat\_template is not set & throwing error

**URL:** <https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095>\
**Category:** 🤗Tokenizers\
**Created:** [August 26, 2024, 8:02pm UTC](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095 "2024-08-26T20:02:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flxflx](https://avatars.discourse-cdn.com/v4/letter/f/5daacb/32.png) [@flxflx](https://discuss.huggingface.co/u/flxflx)\
**Post date:** [August 26, 2024, 8:02pm UTC](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095/1 "2024-08-26T20:02:26Z")

</div>

When I am running the sample code from [here](https://huggingface.co/docs/transformers/v4.44.2/en/chat_templating#is-there-an-automated-pipeline-for-chat):

```from
tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")

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.apply_chat_template(chat, tokenize=False)

```

I get the error message:

```auto
ValueError: Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating

```

I am using tokenizers-0.19.1 & transformers-4.44.2 on a ubuntu on windows system.

Any clue what the problem could be? I already uninstalled and re-installed these two packages.  
Thank you for your help!!

---

<div class="post-metadata">

**Author:** ![GIJoe](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@GIJoe](https://discuss.huggingface.co/u/GIJoe)\
**Post date:** [August 30, 2024, 11:56am UTC](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095/2 "2024-08-30T11:56:41Z")

</div>

I have the same issue. Can somebody help?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [August 31, 2024, 4:01pm UTC](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095/4 "2024-08-31T16:01:24Z")

</div>

Thanks for notifying, this is because initially we had default chat templates for models which didn’t have one set. As this led to various issues, one now needs to explicitly add a chat template (PR for that is [here](https://github.com/huggingface/transformers/pull/31733)).

I’ll open an issue on the Transformers library to replace the code snippet by a model which supports chat templates (like [Mistral-7B](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3), [LLaMa 3.1](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct), [Qwen2](https://huggingface.co/Qwen/Qwen2-1.5B), etc.). Check whether the chat\_template attribute is present in the `tokenizer_config.json` file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [September 5, 2024, 8:36pm UTC](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095/5 "2024-09-05T20:36:10Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
