Repository navigation
Conversation
|
Models doing tool calls inside reasoning is generally a model bug. We don't want to adjust the parser behavior to support model bugs because fundamentally it usually results in reduced quality anyway. The only exceptions are when the behavior is so common (and present in high quantization versions) that it can be justifiably explained as actual trained model behavior, but we certainly don't want this to become the standard. |
A tool call emitted before Master's hand-written parsers already terminate reasoning at non-think boundaries: The close tag in this change is preferred. A The UTF-8 tolerance commit changes no parsing rules. Invalid bytes are skipped and rendered as U+FFFD. Everything around them parses by the unchanged rules. This can be split into its own PR if needed. |
So do many models, and they properly emit a closing think tag. Yes, there is prior work, but this is a weak argument.
This needs to be removed entirely. It will invalidate the prompt cache on subsequent requests and I'm not convinced it won't in-context learn as a result. It requires a better solution, and definitely not one that touches all models. I'm not opposed to a dedicated Ling parser to address the tool call issue. But I'll leave it to @pwilkin's discretion. |
|
Yeah, I was about to say - I'm fine with doing a dedicated Ling parser, I'm even fine with doing a superclass for "tool-call-in-reasoning" type parser that encompasses them all. But I'm wary of assuming all models that do reasoning will also do tool calls in-reasoning. |
31ba154 to
02578ad
Compare
|
Per review from @pwilkin and @aldehir, this PR has been reworked to add a dedicated Ling parser (modeled on the hand-written Qwen3-Coder/Kimi parsers) instead of changing the generated-parser rules. The parse-layer UTF-8 change has been removed. The UTF-8 issue is a separate server-side fix, and has been opened as #28724. Please note that Ling 3.0 Flash and Ling 3.0 Tiny need both of these changes, especially for any sort of agentic use. This builds upon the initial work that added BailingMoE 3 support #26608. |
|
/bot review |
|
❌ Code review failed. |
| common_chat_params common_chat_params_init_ling3(const common_chat_template & tmpl, const autoparser::generation_params & inputs); | ||
|
|
||
| common_chat_params common_chat_params_init_ling3(const common_chat_template & tmpl, const autoparser::generation_params & inputs); |
|
/bot review |
Automated code reviewReview of the reworked diff (dedicated Ling 3.0 parser) The rework looks good overall: the UTF-8 tolerance change was removed as requested, and a dedicated parser modeled on the existing hand-written parsers (kimi-k3, qwen3-coder) is the approach the maintainers explicitly approved. The detection strings ( Correctness issues that should be fixed before merge: (point 1) Thinking-off path misclassifies content as reasoning - (point 2) Missing continuation handling - Will slow the review: (point 3) Duplicate declaration - (point 4) Required arguments forced into schema order - (point 5) Whitespace strictness regression vs. the autoparser path - Nits: (point 6) (point 7) (point 8) (point 9) Everything else in the parser matches the established patterns (preserved tokens, message delimiters, grammar trigger on the call-start word, whitespace-only reasoning discarded). The tests cover the important paths well, including the streaming monotonicity case. This review was generated automatically by pi coding agent using |
02578ad to
9d800ba
Compare
|
9d800ba8d addresses issues surfaced from @aldehir's review:
Duplicate declaration removed
Ling tests now use the peg_tester conventions in tests/test-chat.cpp. Added coverage for the thinking-off path, continuations, tool calls with whitespace variations, and required arguments. |
9d800ba to
72ddff5
Compare
|
72ddff5c0 adds handling for Ling's end-of-turn token.
This registers |
| auto schema_info = common_schema_info(); | ||
| schema_info.resolve_refs(parameters); |
There was a problem hiding this comment.
This has changed, needs to adopt the newer schema types. See the qwen3-coder source as an example.
| @@ -99,6 +99,7 @@ static void test_normalize_quotes_with_embedded_quotes(testing & t); | |||
| static void test_tagged_args_with_embedded_quotes(testing & t); | |||
| static void test_bailing_v3_tool_format(testing & t); | |||
|
|
|||
|
|
|||
| // ============================================================================ | ||
| // Ling 3.0 Flash tests | ||
| // | ||
| // The template pre-opens the think block in the generation prompt | ||
| // ('<role>ASSISTANT</role>\n<think>'), so the model never emits an opening | ||
| // <think>. Reasoning must terminate at </think> OR at a tool-call start, | ||
| // otherwise a tool call emitted before the think block closes is swallowed | ||
| // into reasoning_content and the client sees a reasoning-only turn. | ||
| // ============================================================================ | ||
|
|
| @@ -2092,9 +2092,171 @@ static void test_lfm2_parser(const std::string & template_path, bool detailed_de | |||
|
|
|||
| } | |||
|
|
|||
|
|
|||
| // Ling 3.0 Flash / Bailing V3 dedicated parser | |||
| static void test_ling_3_0_flash(bool detailed_debug) { | |||
There was a problem hiding this comment.
Conform to the existing format used by all other models.
72ddff5 to
965c048
Compare
|
Thanks for addressing my comments. The tests still don't match the existing patterns in this file, though. We try to avoid adding style variations without a clear reason, so could you remove the extra tool definitions, reuse the existing ones, and nest the test case under the function like the other tests? I'll approve once that's done. |
965c048 to
5fb83b9
Compare
Ling 3.0 Flash templates pre-open the think block in the generation prompt, so the model never emits an opening <think>, and a tool call can arrive before any </think>. The generated autoparser terminated reasoning only at the close tag, which classified such tool calls entirely as reasoning_content: clients received content="" with no tool_calls and agent loops died as reasoning-only turns. Adds a specialized parser that terminates reasoning at the think close tag or at a <tool_call> start, mirroring the hand-written Qwen3-Coder and Kimi K3 parsers and the reference vLLM/SGLang Ling3 parser (which treats <tool_call> as an implicit reasoning terminator). Detection is gated on the <role>...</role> section markers, unique to this family among the tagged-argument templates. Adds the Ling 3.0 Flash chat template and tests covering the unclosed-think tool call (full parse and streaming), healthy closed-think paths, trailing prose, parallel calls, marker-like strings in argument values, string-union and non-string argument types, and reasoning_format=none. Assisted-by: Kimi Code
5fb83b9 to
1fc5c42
Compare
Addressed in 5fb83b9. |
|
Congrats on the merge, excited for Ling 3.0 Flash VL, but happy to see Ling 3.0 Tiny working right now. |
* chat: add dedicated Ling 3.0 (Bailing V3) parser Ling 3.0 Flash templates pre-open the think block in the generation prompt, so the model never emits an opening <think>, and a tool call can arrive before any </think>. The generated autoparser terminated reasoning only at the close tag, which classified such tool calls entirely as reasoning_content: clients received content="" with no tool_calls and agent loops died as reasoning-only turns. Adds a specialized parser that terminates reasoning at the think close tag or at a <tool_call> start, mirroring the hand-written Qwen3-Coder and Kimi K3 parsers and the reference vLLM/SGLang Ling3 parser (which treats <tool_call> as an implicit reasoning terminator). Detection is gated on the <role>...</role> section markers, unique to this family among the tagged-argument templates. Adds the Ling 3.0 Flash chat template and tests covering the unclosed-think tool call (full parse and streaming), healthy closed-think paths, trailing prose, parallel calls, marker-like strings in argument values, string-union and non-string argument types, and reasoning_format=none. Assisted-by: Kimi Code * tests : move Ling 3.0 test --------- Co-authored-by: aetherbird <[email protected]> Co-authored-by: Alde Rojas <[email protected]>
Overview
Ling 3.0 templates pre-open in the generation prompt, so the model never emits an opening tag and tool calls can appear before
</think>. The generated parser classified that output entirely asreasoning_contentand clients receivedcontent=""with notool_calls.This adds a dedicated Ling parser (modeled on the hand-written Qwen3-Coder and Kimi parsers) that terminates reasoning at
</think>or a tool-call marker, prefers the close tag when both are present, defers the streaming split to the final parse so delivered deltas are never reclassified, and keeps trailing prose after the last tool call as content. Adds the Ling 3.0 Flash chat template (byte-identical to the GGUF-embedded template) and tests covering the unclosed-think tool call (full and streaming), closed-think paths, trailing prose, parallel calls, marker-like strings in argument values, andreasoning_format=none.Additional information
This builds upon the initial work that added BailingMoE 3 support #26608. Ling 3.0 also emits stray byte-level tokenizer pieces that decode to invalid UTF-8, which hard-fails the parse layer with a 500. That is fixed separately in #28724. Please note that both changes are needed for reliable usage of Ling 3.0 Flash in llama.cpp.
Validated against Ling 3.0 Flash GGUF on llama-server with
--jinja --reasoning-format deepseek. With this parser and #28724 applied, a 29-task agentic benchmark went from 5 reasoning-only tool-call stops and 1 parse500to 0 of both.Requirements