[GH-ISSUE #12329] Modelfile for qwen3:4b is not working #8191

Closed
opened 2026-04-12 20:38:29 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @redaachouhad on GitHub (Sep 18, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12329

What is the issue?

i have this modelfile to create a finetunned model (in .gguf format) based on the qwen3:4 model, but the problem is that the tool calling is not work ? does anyone know what should be the correct template to deploy my model in ollama locally?

this my actual model file:
FROM qwen3:4b

SYSTEM """You are an assistant that discuss with customers in a frinedly way"""
TEMPLATE """
{{ if .System }}
<|im_start|>system
{{ .System }}

{{ if .Tools }}

Tools

You may call one or more functions to assist with the user query.
You are provided with function signatures within XML tags:

{{ range .Tools }} {"type": "function", "function": {"name":"{{ .Function.Name }}","description":"{{ .Function.Description }}","parameters":{{ .Function.Parameters }}}} {{ end }} {{ end }} <|im_end|> {{ end }}

{{ range $i, $msg := .Messages }}

{{ if eq $msg.Role "user" }}
<|im_start|>user
{{ $msg.Content }}
<|im_end|>

{{ else if eq $msg.Role "assistant" }}
<|im_start|>assistant
{{ if $msg.Content }}{{ $msg.Content }}{{ end }}
{{ if $msg.ToolCalls }}
{{ range $msg.ToolCalls }}
{{/* This signals Ollama to create a tool call, not just text */}}
<tool_call>
{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
</tool_call>
{{ end }}
{{ end }}
<|im_end|>

{{ else if eq $msg.Role "tool" }}
<|im_start|>user
<tool_response>
{{ $msg.Content }}
</tool_response>
<|im_end|>
{{ end }}

{{ end }}
"""

PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"

Relevant log output


OS

No response

GPU

Nvidia

CPU

No response

Ollama version

No response

Originally created by @redaachouhad on GitHub (Sep 18, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12329 ### What is the issue? i have this modelfile to create a finetunned model (in .gguf format) based on the qwen3:4 model, but the problem is that the tool calling is not work ? does anyone know what should be the correct template to deploy my model in ollama locally? this my actual model file: FROM qwen3:4b SYSTEM """You are an assistant that discuss with customers in a frinedly way""" TEMPLATE """ {{ if .System }} <|im_start|>system {{ .System }} {{ if .Tools }} # Tools You may call one or more functions to assist with the user query. You are provided with function signatures within <tools></tools> XML tags: <tools> {{ range .Tools }} {"type": "function", "function": {"name":"{{ .Function.Name }}","description":"{{ .Function.Description }}","parameters":{{ .Function.Parameters }}}} {{ end }} </tools> {{ end }} <|im_end|> {{ end }} {{ range $i, $msg := .Messages }} {{ if eq $msg.Role "user" }} <|im_start|>user {{ $msg.Content }} <|im_end|> {{ else if eq $msg.Role "assistant" }} <|im_start|>assistant {{ if $msg.Content }}<think>{{ $msg.Content }}</think>{{ end }} {{ if $msg.ToolCalls }} {{ range $msg.ToolCalls }} {{/* This signals Ollama to create a tool call, not just text */}} <tool_call> {"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}} </tool_call> {{ end }} {{ end }} <|im_end|> {{ else if eq $msg.Role "tool" }} <|im_start|>user <tool_response> {{ $msg.Content }} </tool_response> <|im_end|> {{ end }} {{ end }} """ PARAMETER stop "<|im_start|>" PARAMETER stop "<|im_end|>" ### Relevant log output ```shell ``` ### OS _No response_ ### GPU Nvidia ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the bug label 2026-04-12 20:38:29 -05:00
Author
Owner

@rick-github commented on GitHub (Sep 18, 2025):

If it's a finetune of qwen3:4b, just use the qwen3:4b modelfile.

echo FROM path/to/my/model.gguf > Modelfile
echo SYSTEM '"""You are an assistant that discusses with customers in a friendly way"""' >> Modelfile
ollama show --modelfile qwen3:4b | grep -v "^FROM" >> Modelfile
ollama create my-new-model
<!-- gh-comment-id:3306711926 --> @rick-github commented on GitHub (Sep 18, 2025): If it's a finetune of qwen3:4b, just use the qwen3:4b modelfile. ``` echo FROM path/to/my/model.gguf > Modelfile echo SYSTEM '"""You are an assistant that discusses with customers in a friendly way"""' >> Modelfile ollama show --modelfile qwen3:4b | grep -v "^FROM" >> Modelfile ollama create my-new-model ```
Author
Owner

@redaachouhad commented on GitHub (Sep 18, 2025):

I initially thought I would have to develop the Modelfile by translating the chat template provided on Hugging Face for qwen3, but I’ve now discovered that each model already has its Modelfile implemented. I really appreciate your help—it was very helpful!

<!-- gh-comment-id:3306955640 --> @redaachouhad commented on GitHub (Sep 18, 2025): I initially thought I would have to develop the Modelfile by translating the chat template provided on Hugging Face for qwen3, but I’ve now discovered that each model already has its Modelfile implemented. I really appreciate your help—it was very helpful!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#8191