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 3.5.1 breaks GPT4All-Community/gemma-2-9b-it-GGUF #3282

Open
ThiloteE opened this issue Dec 13, 2024 · 4 comments
Open

[Jinja] GPT4All 3.5.1 breaks GPT4All-Community/gemma-2-9b-it-GGUF #3282

ThiloteE opened this issue Dec 13, 2024 · 4 comments
Labels

Comments

@ThiloteE
Copy link
Collaborator

ThiloteE commented Dec 13, 2024

Bug Report

  1. System message field triggers following error: "System message is not "plain text""
  2. Jinja default chat template triggers following error: "Syntax error: 4:2: error: Unexpected token '}'. Expected: '>' '}}{% endif %} -^-------"

Image

Default Jinja template in GPT4All (broken)

{{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '
' + message['content'] | trim + '<end_of_turn>
' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model
'}}{% endif %}

Jinja template that doesn't trigger errors (still broken!):

{{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '
' + message['content'] | trim + '<end_of_turn>
' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model
' }}{% endif %}

Steps to Reproduce

Download and use the model

Expected Behavior

  1. Model just works.
  2. gemma-2-9b-it was trained without system prompt, so having none should just work instead of triggering an error.
  3. Default Jinja template works out of the box.

Your Environment

@ThiloteE
Copy link
Collaborator Author

ThiloteE commented Dec 13, 2024

Oh, once the jinja template is "fixed" (still broken), the error message related to the system message also vanishes.
Image

@ThiloteE
Copy link
Collaborator Author

ThiloteE commented Dec 13, 2024

Working/fixed template:

{{ bos_token }}
{%- if messages[0]['role'] == 'system' %}
	 {{- raise_exception('System role not supported') }}
{%- endif %}

{%- for message in messages %}
	 {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}
		  {{- raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
	 {%- endif %}
	 {%- if (message['role'] == 'assistant') %}
		  {%- set role = 'model' %}
		  {%- else %}{% set role = message['role'] %}
	 {%- endif %}
	 {{- '<start_of_turn>' + role + '\n' + message['content'] | trim + '<end_of_turn>\n' }}
{%- endfor %}

{%- if add_generation_prompt %}
	 {{- '<start_of_turn>model\n' }}
{%- endif %}

@tcfurrer
Copy link

tcfurrer commented Dec 16, 2024

With that template on 3.5.3 I'm getting:

Error: Failed to parse chat template: 1:1: error: Unexpected exception occurred during template processing.
Exception: Jinja template error: Conversation roles must alternate user/assistant/user/assistant/...

That's happening when the System Message is just "You are a helpful assistant."

In case it matters, I'm using Mistral-Small-Instruct-2409-Q5_K_M.gguf

@ThiloteE
Copy link
Collaborator Author

ThiloteE commented Dec 17, 2024

This template is for the gemma model and based on its original template. The gemma model does not support a system prompt. If you wanted to add a system prompt, the template would have to be different. I get the same exception, as soon as I add a system message in the model settings. If you remove the system prompt, it also should work to a limited degree for the mistral model, but I recommend to come up with a proper template for Mistral based on its original template.

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

No branches or pull requests

2 participants