[RFC] autoparser unable to accommodate non-ASCII reasoning markers, e.g. ◁think▷#25369
Open
ulidtko wants to merge 1 commit into
Open
[RFC] autoparser unable to accommodate non-ASCII reasoning markers, e.g. ◁think▷#25369ulidtko wants to merge 1 commit into
◁think▷#25369ulidtko wants to merge 1 commit into
Conversation
Models such as Kimi-VL-A3B-Thinking-2506 emit CoT reasoning wrapped in ◁think▷...◁/think▷ (U+25C1 WHITE LEFT-POINTING TRIANGLE + "think" + U+25B7 WHITE RIGHT-POINTING TRIANGLE). These are multi-byte UTF-8 sequences, not ASCII angle-brackets, so both segmentize_markers() and p.marker() silently classified them as plain TEXT, causing the autoparser to infer reasoning_mode=NONE even when the chat template correctly uses reasoning_content around those delimiters. Fix: - segmentize_markers(): add two new else-if branches that detect ◁ as a multi-byte opener and ▷ as the corresponding closer, producing MARKER segments identical in role to <...> and [...] ones. The for-loop step is preserved unchanged; the branches adjust cur_pos with ±(size-1) to account for the 3-byte sequences inside the single-increment loop. - p.marker(): add a third choice branch that matches ◁...▷ spans, keeping it symmetric with the existing sharp- and square-bracket branches. After this change, llama-debug-template-parser should report reasoning_mode: TAG_BASED with the correct start/end tags for Kimi-VL-Thinking templates. Co-Authored-By: Claude Code <claude-code@anthropic.com>
|
Hi @ulidtko, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi @pwilkin and team!
In follow-up to #18675, let me open an issue after repeatedly failing to find prior discussion.
The attached patch is mostly to demonstrate an issue — it's short enough to tell exactly what is being "fixed". Below I'll describe textually anyway. I'm not convinced it's the best possible approach; sure enough, you'll find a better idea. I'm perfectly fine if the PR gets closed, if anyone more familiar finds a better way.
So, the issue reproduces when running this model: ggml-org/Kimi-VL-A3B-Thinking-2506-GGUF,
The surface-level symptom is, llama.cpp not parsing the reasoning stream properly:
Do notice the uncommon
◁think▷marker; the closing one◁/think▷follows below in response. The characters are:WHITE LEFT-POINTING TRIANGLEWHITE RIGHT-POINTING TRIANGLEThese are a property of how the Thinking fine-tune was conducted, I believe. The multi-token sequences
◁think▷,◁/think▷are documented in the models readme's, too.... With this patch, and a correction in chat template jinja, I'm getting
reasoning_mode: TAG_BASEDand proper parses in both llama-cli and llama-server:However again, I'm clear that this is only a rough first cut, a PoC draft that worked; the added logic is too specific and not a good proper fix.
It is necessary, because
segmentize_markers()cannot handle anything besides<foo>and[bar]:llama.cpp/common/chat-auto-parser-helpers.cpp
Lines 274 to 275 in f36e5c3
(Plus a related change in PEG builder. This patch is made and tested against version
b9747, but the same code lives in today's master ☝️)The real question is:
tokenizer.chat_templatealone?Hence the RFC tag — Request For Comment.
Fixed & original chat templates
Original, distributed with model
Fixed, works as expected together with the PR's patch
AI usage disclosure: Anthropic Sonnet 4.6 wrote this garbage of patch, with iterated
verbal abusedirection provided by the operator (me). But hey, at least it was able to read the docs & follow the source — well done, good codebase. This PR description is 100% pure human writing; best regards.