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

[Jinja] GPT4All-Chat 3.5.1 Chat template syntax for MaziyarPanahi_Qwen2-1.5B-Instruct-GGUF #3263

Open
ThiloteE opened this issue Dec 11, 2024 · 2 comments
Labels
bug-unconfirmed chat gpt4all-chat issues

Comments

@ThiloteE
Copy link
Collaborator

ThiloteE commented Dec 11, 2024

Bug Report

I experience Jinja syntax errors.

Steps to Reproduce

Use the model with new default jinja template, introduced in GPT4All-Chat 3.5.1

Default (reset) template:

{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
You are a helpful assistant.<|im_end|>
' }}{% endif %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}

Image

Better template:

{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
You are a helpful assistant.<|im_end|>
' }}{% endif %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}

Image
Image

Expected Behavior

No problems

Your Environment

@ThiloteE ThiloteE added bug-unconfirmed chat gpt4all-chat issues labels Dec 11, 2024
@ThiloteE ThiloteE changed the title [Jinja] GPT4All-Chat 3.5.1 Chat template syntax for Qwen2-1.5B-Instruct.Q6_K.gguf [Jinja] GPT4All-Chat 3.5.1 Chat template syntax for MaziyarPanahi_Qwen2-1.5B-Instruct-GGUF Dec 11, 2024
@ThiloteE
Copy link
Collaborator Author

ThiloteE commented Dec 13, 2024

So, I think many models have problems with space after '. In particular the ones that follow basic ChatML syntax (the ones that have im_start|> and <|im_end|>).

Example for another model with the same issues: https://huggingface.co/FPHam/Karen_TheEditor_V2_CREATIVE_Mistral_7B

Default jinja in GPT4All that causes error:

{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}

Better:

{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
' }}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}

Notice, I only added a space on the left side of the code block, right on the second character position of line 4.

@ThiloteE
Copy link
Collaborator Author

ThiloteE commented Dec 13, 2024

Even better Jinja chat template:

{%- for message in messages %}
    {%- if loop.first and messages[0]['role'] != 'system' %}
        {{  '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}
    {%- endif %}
        {{ '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n' }}
{%- endfor %}

{%- if add_generation_prompt %}
    {{ '<|im_start|>assistant\n' }}
{%- endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-unconfirmed chat gpt4all-chat issues
Projects
None yet
Development

No branches or pull requests

1 participant