You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What happens is that if self.model_name does not have a chat_template attribute in tokenizer_config.json (e.g. granite 34 b code instruct ) it will raise an exception...
This code shows the problem:
fromtransformersimportAutoTokenizertokenizer=AutoTokenizer.from_pretrained("ibm-granite/granite-20b-code-base")
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!"},
]
print(tokenizer.apply_chat_template(chat, tokenize=False))
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
Is it possible to improve the error handling in this case?
I don't know if its possible to have a default chat template or be more explicit in the error so the user could take action...
@allyssonf I opened #1983 for this. HFSystemFormat now raises a clear error when it's created if the model's tokenizer has no chat template. The message suggests using a model with a chat template, passing one explicitly with chat_kwargs_dict={'chat_template': ...} (which already works), or using SystemFormat. cc @elronbandel@yoavkatz
Activity
github-actions commentedon Apr 26, 2025
This issue is stale because it has been open for 30 days with no activity.
github-actions commentedon May 10, 2025
This issue was closed because it has been inactive for 14 days since being marked as stale.
wak327 commentedon Oct 3, 2026
@allyssonf I opened #1983 for this.
HFSystemFormatnow raises a clear error when it's created if the model's tokenizer has no chat template. The message suggests using a model with a chat template, passing one explicitly withchat_kwargs_dict={'chat_template': ...}(which already works), or usingSystemFormat. cc @elronbandel @yoavkatz