Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HFSystemFormat Exception #1144

Open
allyssonf opened this issue Aug 13, 2024 · 0 comments
Open

HFSystemFormat Exception #1144

allyssonf opened this issue Aug 13, 2024 · 0 comments

Comments

@allyssonf
Copy link
Contributor

When using HFSystemFormat to define the format when loading a dataset an error is shown:

An error occurred while generating the dataset

HFSystemFormat function at the end applies a chat template to the message:

        ....

        tokenizer = AutoTokenizer.from_pretrained(self.model_name)

       ....

        tokenized_chat = tokenizer.apply_chat_template(
            messages, tokenize=False, add_generation_prompt=True
        )

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:

from transformers import AutoTokenizer

tokenizer = 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...

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant