So I have been successfully running llama-cpp together with a quantized version of Devstral-Small-2 and things are going quite alright. Though I did have to make some adjustments to get here:
- The default chat template from mistral seems to enforce a user -> assistant -> user -> assistant pattern, this is sub optimal because my main interest in this setup is using
opencode. But that fails fast, so I have adjusted the jinja template to remove that limitation. With that in place opencode happily accepts my api endpoint and starts buzzing along.
- I am also running OpenWebUI pointed to my llama-server and things work okay, but I started noticing that thinking output seems not work as expected.
The second part is what led me down a rabbit hole of trying to get thinking output to work …
I am going to stick to my example with Devstral 2 but I think some of the issues I am describing will be applicable to other models and combinations there of.
So according to the the chat template [THINK] and [/THINK] should be the tags with which to wrap the thinking output
But in my testing I did not get this to work, It only started working after I manually changed the tags to use <think> and </think> (patching the code in llama-cpp to use different prefixes) … I suspect this is related to me using a quantized version of the model that was further fine tuned and may with the training set containing different thinking tags than the original tags the model should be using. Another thing I noticed is that when trying to use [THINK] the model would often generate [TOOL_CALL] instead. So the issue might also be that the tags are quite similar and [TOOL_CALL] is has a higher probability of being selected.
But here is the thing: I can't solve this without patching llama-cpp and I think this is the biggest issue. Open Weights models are distrubuted and repackaged by different organizations with different needs and it is simply impossible for llama-cpp to provide a chat template parser for every combination under the sun. The current implementation of chat template handling simply involves way to much hard coding.
Note: There is also a lot of code in the chat templates part that has no explanation what so ever and chat templates are widely different in their formatting making it hard to reason about if it would even be feasible to get them to behave similarly enough in order to add more control to the user. For example common_chat_templates_support_enable_thinking seems to be used to check if a chat template supports thinking mode, but there is simply not enough information in order for me to understand how to get a chat template and corresponding parser to correctly work with this!
So with my current setup I am stuck accepting either that thinking is not going to work, or that I will have run a forked version, because upstreaming yet another special case to the current state of affairs will not improve the overall situation any bit … But given that this is a complex issue with many moving parts I don't know any easy answer.
At the very least I hope this report helps other people facing similar issues …
Operating systems
Linux
Which llama.cpp modules do you know to be affected?
llama-server
Command line
Problem description & steps to reproduce
See description
First Bad Commit
No response
Relevant log output
No response
So I have been successfully running
llama-cpptogether with a quantized version ofDevstral-Small-2and things are going quite alright. Though I did have to make some adjustments to get here:opencode. But that fails fast, so I have adjusted the jinja template to remove that limitation. With that in placeopencodehappily accepts my api endpoint and starts buzzing along.The second part is what led me down a rabbit hole of trying to get thinking output to work …
I am going to stick to my example with
Devstral 2but I think some of the issues I am describing will be applicable to other models and combinations there of.So according to the the chat template [THINK] and [/THINK] should be the tags with which to wrap the thinking output
But in my testing I did not get this to work, It only started working after I manually changed the tags to use
<think>and</think>(patching the code in llama-cpp to use different prefixes) … I suspect this is related to me using a quantized version of the model that was further fine tuned and may with the training set containing different thinking tags than the original tags the model should be using. Another thing I noticed is that when trying to use [THINK] the model would often generate [TOOL_CALL] instead. So the issue might also be that the tags are quite similar and [TOOL_CALL] is has a higher probability of being selected.But here is the thing: I can't solve this without patching llama-cpp and I think this is the biggest issue. Open Weights models are distrubuted and repackaged by different organizations with different needs and it is simply impossible for llama-cpp to provide a chat template parser for every combination under the sun. The current implementation of chat template handling simply involves way to much hard coding.
Note: There is also a lot of code in the chat templates part that has no explanation what so ever and chat templates are widely different in their formatting making it hard to reason about if it would even be feasible to get them to behave similarly enough in order to add more control to the user. For example
common_chat_templates_support_enable_thinkingseems to be used to check if a chat template supports thinking mode, but there is simply not enough information in order for me to understand how to get a chat template and corresponding parser to correctly work with this!So with my current setup I am stuck accepting either that thinking is not going to work, or that I will have run a forked version, because upstreaming yet another special case to the current state of affairs will not improve the overall situation any bit … But given that this is a complex issue with many moving parts I don't know any easy answer.
At the very least I hope this report helps other people facing similar issues …
Operating systems
Linux
Which llama.cpp modules do you know to be affected?
llama-server
Command line
Problem description & steps to reproduce
See description
First Bad Commit
No response
Relevant log output
No response