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
It is a Llama model; it should be fixed easily using the Llama chat template.
RuntimeError: Unsloth: The tokenizer `Raj-Maharajwala/Open-Insurance-LLM-Llama3-8B`
does not have a {% if add_generation_prompt %} for generation purposes.
Please file a bug report immediately - thanks!
For the open insurance model yes="<|begin_of_text|>System: This is a chat between a user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. The assistant should also indicate when the answer cannot be found in the context.\n\nUser: Who are you?\n\nAssistant:", while for the tokenizer of a typical llama model yes='<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nWho are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n'
new_chat_template="{{ bos_token }}{%- if messages[0]['role'] == 'system' -%}{% set loop_messages = messages[1:] %}{%- else -%}{% set loop_messages = messages %}{% endif %}System: This is a chat between a user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. The assistant should also indicate when the answer cannot be found in the context.\n\n{% for message in loop_messages %}{%- if message['role'] == 'user' -%}User: {{ message['content'].strip() + '\n\n' }}{%- else -%}Assistant: {{ message['content'].strip() + '\n\n' }}{%- endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}"
It works for a patch like this, but the problem is I use FastLanguageModel.from_pretrained to init the model and tokenizer, and it fails to load since this call model, tokenizer = dispatch_model.from_pretrained use load_correct_tokenizer and seems to do some verification over the chat template. Thus, I do not have time to change it.
I don't know what should be the 'right' way to do this, but for now you could try this:
frominspectimportgetsourcefromunslothimportload_correct_tokenizertemplate=r"{{ bos_token }}{%- if messages[0]['role'] == 'system' -%}{% set loop_messages = messages[1:] %}{%- else -%}{% set loop_messages = messages %}{% endif %}System: This is a chat between a user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. The assistant should also indicate when the answer cannot be found in the context.\n\n{% for message in loop_messages %}{%- if message['role'] == 'user' -%}User: {{ message['content'].strip() + '\n\n' }}{%- else -%}Assistant: {{ message['content'].strip() + '\n\n' }}{%- endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}"src=getsource(load_correct_tokenizer)
i=src.index('old_chat_template')
new_src=src[:i] +f'tokenizer.chat_template = "{template}"\n '+src[i:]
exec(new_src, globals())
# Load the modelexec(src, globals())
Activity
KareemMusleh commentedon Mar 15, 2025
It seems that there is a problem with the chat template of the model.
For the open insurance model
yes="<|begin_of_text|>System: This is a chat between a user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions based on the context. The assistant should also indicate when the answer cannot be found in the context.\n\nUser: Who are you?\n\nAssistant:", while for the tokenizer of a typical llama modelyes='<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nWho are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n'davebulaval commentedon Mar 16, 2025
I tried changing the template later on using the Llama template, but it failed during the
unslothloading.KareemMusleh commentedon Mar 16, 2025
is it throwing the same error?
I've tested this and it works
both
Raj-Maharajwala/Open-Insurance-LLM-Llama3-8Band the model it's based onnvidia/Llama3-ChatQA-1.5-8Bseem to have the same chat_template.KareemMusleh commentedon Mar 16, 2025
try this:
davebulaval commentedon Mar 16, 2025
It works for a patch like this, but the problem is I use
FastLanguageModel.from_pretrainedto init the model and tokenizer, and it fails to load since this callmodel, tokenizer = dispatch_model.from_pretraineduseload_correct_tokenizerand seems to do some verification over the chat template. Thus, I do not have time to change it.KareemMusleh commentedon Mar 17, 2025
I don't know what should be the 'right' way to do this, but for now you could try this:
davebulaval commentedon Mar 17, 2025
Good idea.
I've used this instead, which I found to be easier.