[GH-ISSUE #1103] Custom model repeats context in the response #551

Closed
opened 2026-04-12 10:14:45 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @sethmbhele on GitHub (Nov 12, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1103

Hello Friends

Firstly thank you so much for this amazing project. I have been playing around with it and having quite the blast learning the ins and outs of Ollama. If anyone can kindly assist with a challenge I am currently facing:
I created a Modelfile and passed temperature and system message; created and ran custom model. Everything works great and the new model is responding according to the new system message shared in the Modelfile. The challenge that I am facing is that on the second or third multi-turn chat, I am getting response + entire system message appended at the end. Any ideas on what I can try to fix this behaviour?
PS: Passing an instruction in the system message to NOT repeat system message in response did not work :(

Originally created by @sethmbhele on GitHub (Nov 12, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1103 Hello Friends Firstly thank you so much for this amazing project. I have been playing around with it and having quite the blast learning the ins and outs of Ollama. If anyone can kindly assist with a challenge I am currently facing: I created a Modelfile and passed temperature and system message; created and ran custom model. Everything works great and the new model is responding according to the new system message shared in the Modelfile. The challenge that I am facing is that on the second or third multi-turn chat, I am getting response + entire system message appended at the end. Any ideas on what I can try to fix this behaviour? PS: Passing an instruction in the system message to NOT repeat system message in response did not work :(
Author
Owner

@igorschlum commented on GitHub (Nov 12, 2023):

@sethmbhele

Hello, you are a step ahead of me. I would like to understand how to create and use a Modelfile. Could you share your experience with us?

<!-- gh-comment-id:1807258952 --> @igorschlum commented on GitHub (Nov 12, 2023): @sethmbhele Hello, you are a step ahead of me. I would like to understand how to create and use a Modelfile. Could you share your experience with us?
Author
Owner

@BruceMacD commented on GitHub (Nov 13, 2023):

This sounds like a job for stop tokens. They tell the LLM runner to stop generating when they're seen. Are you seeing <<SYS>> tags or anything like that in the output when it generates the system message again?

Here is an example of a modelfile with stop tokens:

FROM llama2
TEMPLATE """[INST] <<SYS>>{{ .System }}<</SYS>>

{{ .Prompt }} [/INST]
"""]
PARAMETER stop "[INST]"
PARAMETER stop "<<SYS>>"
<!-- gh-comment-id:1809165890 --> @BruceMacD commented on GitHub (Nov 13, 2023): This sounds like a job for stop tokens. They tell the LLM runner to stop generating when they're seen. Are you seeing `<<SYS>>` tags or anything like that in the output when it generates the system message again? Here is an example of a modelfile with stop tokens: ``` FROM llama2 TEMPLATE """[INST] <<SYS>>{{ .System }}<</SYS>> {{ .Prompt }} [/INST] """] PARAMETER stop "[INST]" PARAMETER stop "<<SYS>>" ```
Author
Owner

@sethmbhele commented on GitHub (Nov 19, 2023):

This sounds like a job for stop tokens. They tell the LLM runner to stop generating when they're seen. Are you seeing <<SYS>> tags or anything like that in the output when it generates the system message again?

Here is an example of a modelfile with stop tokens:

FROM llama2
TEMPLATE """[INST] <<SYS>>{{ .System }}<</SYS>>

{{ .Prompt }} [/INST]
"""]
PARAMETER stop "[INST]"
PARAMETER stop "<<SYS>>"

Thanks Bruce - this solved my issue

<!-- gh-comment-id:1817912457 --> @sethmbhele commented on GitHub (Nov 19, 2023): > This sounds like a job for stop tokens. They tell the LLM runner to stop generating when they're seen. Are you seeing `<<SYS>>` tags or anything like that in the output when it generates the system message again? > > Here is an example of a modelfile with stop tokens: > > ``` > FROM llama2 > TEMPLATE """[INST] <<SYS>>{{ .System }}<</SYS>> > > {{ .Prompt }} [/INST] > """] > PARAMETER stop "[INST]" > PARAMETER stop "<<SYS>>" > ``` Thanks Bruce - this solved my issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#551