Fix DeepSeek4 crafted template - #25414
Conversation
aldehir
left a comment
There was a problem hiding this comment.
If we want to start testing templates, probably best to move those to a separate test suite as this one is already pretty large.
IMO Python tests are more appropriate for the Jinja templates.
|
Yeah, I'll probably move to refactor Personally, I'm against Python tests because the C++ tests double down as a check on the template rendering / message passing, which Python won't do - I prefer the tests to run inside the same engine as the actual template processing. |
|
As I had explained in the reddit thread, this is not the only issue and I had to opt out of the autoparser in order to properly run DSV4. In particular, parallel tool calling is not working with the autoparser and while running on pi I was getting random stops with tool calls within the reasoning block. Everything done to fix are contained in these two commits sent to fairydreaming's lightining indexer branch: fairydreaming#4 |
|
@tarruda yeah, working on the parser extension next :) |
|
@tarruda can you please include your response from Reddit for visibility purposes. Also because the link appears broken on my end. |
|
This is basically pretty similar to @tarruda 's branch :) a few style differences. @tarruda technically your approach to the template flag isn't in line with the reference: they require reasoning traces not if tools are declared, but if any tool calls are actually present (I know, practically it doesn't really matter too much, but just nitpicking :)) |
|
@ggml-org/maintainers need another approval, let's get this done so we can move on with the DS4 template fixes (I forgot this wasn't merged). |
|
@pwilkin Can you take a look at this one? https://github.com/ggml-org/llama.cpp/pull/25891/changes#diff-8dbbe2bce6d35f58f9ab0dc165bb2ae45c20923d4f144c35e77a0ae836d20e8d It adds two things that are still missing:
|
|
@pwilkin official encoding reference on these features I mentioned: |
|
@ggml-org/maintainers need 1 more approval please. |
| ctx.set_val("preserve_thinking", mk_val<value_bool>(enabled)); | ||
| ctx.set_val("clear_thinking", mk_val<value_bool>(!enabled)); | ||
| ctx.set_val("truncate_history_thinking", mk_val<value_bool>(!enabled)); | ||
| ctx.set_val("drop_reasoning", mk_val<value_bool>(!enabled)); |
There was a problem hiding this comment.
The variable in the template is named drop_thinking.
There was a problem hiding this comment.
Also: drop_thinking defaults to false, so this seems to disable the --reasoning-preserve mechanics. IOW: you can force thinking to drop by explicitly passing the template kwargs drop_thinking=true, but this doesn't seem to be doing anything.
There was a problem hiding this comment.
Ah crap :/
Yeah, the behavior is different than with other --reasoning-preserve models.
|
FWIW in pi.dev I have this, followed by the agent prematurely ending the turn, on current HEAD (0cea362): |
|
@kallewoof yeah, might be another instance of model calling tools within reasoning block. |
* chat: fix DS4 template to explicitly follow reference behavior * Support DeepSeekv4 flag (`drop_reasoning`). * fix: hook DS3.2 parser for DS4 as well * fix: add tool result reordering * fix: post-merge
|
@kallewoof try to reproduce this bug on my branch (which is #25891 rebased on master) . I believe it has fixed all instances where this happens. |
|
@tarruda Just gave it a shot. No <|DSML stuff, and the output passes review. Why is this not a pull request again? Edit: Or why is the PR closed, rather. |
|
@kallewoof it overlapped my fixes for the most part and with the tool calling in reasoning we were waiting for #25544 which just got merged. |
|
I can open a new PR if @pwilkin is fine with the changes in tarruda@4d561a3 |
|
or someone could reopen #25891, I'm unable to do so |
|
The test you posted is fixed, are there more? |
|
Okay I see your branch. @pwilkin can you confirm if test-chat from that branch passes on your PR? |
|
@am17an there might be more cases that I haven't reproduced, but from my local testing using my branch, it hasn't reproduced that bug in a while. |
Overview
It seems like I've been a bit lazy implementing the DS4 template. I used the standard behavior (retain last reasoning trace). However, the reference behavior is different. DS4 will retain all reasoning traces in one of two cases:
drop_reasoningis set to falseI've patched the template and added a test to verify this.
Additional information
Note that under the current behavior llama.cpp defaults to setting
drop_reasoningto true, so if you want it set to false you'll have to add--preserve-reasoning- not that it matters that much because for all agentic cases, DS4 will still force the retain of traces due to the presence of tool calls.Requirements
<think>and</think>:))