[GH-ISSUE #5666] Curious, What's the correct TEMPLATE parameter for google gemma model, in the context of modelfile? I am converting GGUF to ollama by myself by using the command "ollama crea xxx -f xxx" #29293

Closed
opened 2026-04-22 08:01:51 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Astroherodvaipayan on GitHub (Jul 13, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/5666

          Curious, What's the correct TEMPLATE parameter for google gemma model, in the context of modelfile? I am converting GGUF to ollama by myself by using the command "ollama crea xxx -f xxx"

the original hugingface repo chat_template is as follows

{% 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 %}

Originally posted by @nps798 in https://github.com/ollama/ollama/issues/2636#issuecomment-1957025970

Originally created by @Astroherodvaipayan on GitHub (Jul 13, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/5666 Curious, What's the correct TEMPLATE parameter for google gemma model, in the context of modelfile? I am converting GGUF to ollama by myself by using the command "ollama crea xxx -f xxx" the original hugingface repo chat_template is as follows ``` {% 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 %} ``` _Originally posted by @nps798 in https://github.com/ollama/ollama/issues/2636#issuecomment-1957025970_
GiteaMirror added the question label 2026-04-22 08:01:51 -05:00
Author
Owner

@Astroherodvaipayan commented on GitHub (Jul 13, 2024):

does this modelfile prompt template work for gemma models? it doesnt seem to work for me.

<!-- gh-comment-id:2226801922 --> @Astroherodvaipayan commented on GitHub (Jul 13, 2024): does this modelfile prompt template work for gemma models? it doesnt seem to work for me.
Author
Owner

@rick-github commented on GitHub (Jul 14, 2024):

 $ ollama show --template gemma:latest
<start_of_turn>user
{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn>
<start_of_turn>model
{{ .Response }}<end_of_turn>
<!-- gh-comment-id:2227302765 --> @rick-github commented on GitHub (Jul 14, 2024): ``` $ ollama show --template gemma:latest <start_of_turn>user {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn> <start_of_turn>model {{ .Response }}<end_of_turn> ```
Author
Owner

@rick-github commented on GitHub (Nov 6, 2024):

The chat_template is a jinja template, which looks similar to the golang template langue used in ollama but is not compatible.

<!-- gh-comment-id:2459642128 --> @rick-github commented on GitHub (Nov 6, 2024): The chat_template is a [jinja template](https://jinja.palletsprojects.com/en/stable/), which looks similar to the [golang template](https://pkg.go.dev/text/template) langue used in ollama but is not compatible.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#29293