-
Notifications
You must be signed in to change notification settings - Fork 366
Fix tool call for Qwen3.5 #1300
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to test it more but I have not had much success in no think mode by appending
<think>\n</think>. This might also be the fact that I'm using a small quant (IQ2_XS), but I did get repetition issues occasionally.
It's hard to replicate but I think I got better output by using <think>\n\n</think>\n\n as the original Jinja suggests.
https://huggingface.co/Qwen/Qwen3.5-397B-A17B/blob/main/chat_template.jinja
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I haven't looked at the backend too much, but isn't this logic supposed to be delt with by the Jinja?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am actually not too sure what's the purpose of the if-block here. I know the else-block is needed to set
thinking_forced_opento true, so that thinking goes underreasoning_content. Let me double check.Also I just pushed a commit that fixes the grammar to handle tool calls with multiple parameters correctly. It slipped through my testing..
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Jinja is being used and the context ends with "<think>\n" then it means that thinking should be on, so the code under if (!params.enable_thinking) should never run anyway.
If you're not using Jinja but rather formatting at front end level with text completion, the formatting should be handled by the front end, not llama.cpp.
That code might add a sneaky extra unwanted token to text completion front end programmers, depending on how params.enable_thinking is set. I don't see the point of it, but I'm not deep into backend so idk.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. So if I understand correctly, the if-block here should be for chat templates like https://huggingface.co/stepfun-ai/Step-3.5-Flash/blob/main/chat_template.jinja, which don't support the
enable_thinkingflag by itself. The if-block will then add a "</think>", as a best effort to disable reasoning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was Stepfun-3.5-Q4_K_L so not that small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I downloaded the IQ4_XS quant from https://huggingface.co/ubergarm/Step-3.5-Flash-GGUF/, which has the same chat template as https://huggingface.co/stepfun-ai/Step-3.5-Flash/blob/main/chat_template.jinja
Thinking seems to be working fine. And with the change in this PR, I can now set the
"enable_thinking": falsechat template kwargs, either as a llama-server cli flag or in the request body, to disable thinking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have downloaded ubergarm's quant, heh. Maybe I will just steal the template out of his metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Stepfun-3.5-Q4_K_L quant is from Bartowski right? Looking at https://huggingface.co/bartowski/stepfun-ai_Step-3.5-Flash-GGUF/edit/main/stepfun-ai_Step-3.5-Flash-Q4_K_L/stepfun-ai_Step-3.5-Flash-Q4_K_L-00001-of-00004.gguf, the chat template is also identical with the official one from stepfun-ai, so it should be working fine with this PR branch.
This is how it looks like with a simple Q&A without tool:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this is how it looks like with thinking disabled in the request body:
The prompt tokens went from 16 to 17, as this particular line adds the
</think>token to the prompt.