Repository navigation
chat : fix gemma4 required tool grammar - #29115
Conversation
|
He's right, though. An interaction of two
|
pwilkin
left a comment
There was a problem hiding this comment.
For required tool calls this is the right workaround, but we should think about a way to fix the "double until" behavior.
|
Well, that's why we remove them! It's only a problem in a CFG grammar. The PEG parser, being greedy, doesn't have the same issue. For grammars, |
This problem will mostly go away once we add token-aware parsing and we can construct grammars that operate on tokens. |
Under tool_choice required the auto-parser grammar accepted any text before the tool call, and it accepts end of generation only after a call. A model that starts answering in prose can then keep writing until the context fills and never call. Qwen3-1.7B does this on a second turn of "Say hello.", ending with no tool call and no error. The required grammar of the json_native, tag_json and tag_tagged builders now accepts the reasoning block, whitespace and then the call, as the Gemma 4 parser does since ggml-org#29115. Without reasoning extraction the block is kept as content, so a thinking model can still think before the call; a peek on the start tag keeps a partial tag from streaming out as content. The whitespace allowance covers templates whose reasoning end tag carries no newline, such as QwQ, whose generation prompt opens the block. auto and none are unchanged. Co-authored-by: Claude Opus 5.5 <[email protected]>
Under tool_choice required the auto-parser grammar accepted any text before the tool call, and it accepts end of generation only after a call. A model that starts answering in prose can then keep writing until the context fills and never call. Qwen3-1.7B does this on a second turn of "Say hello.", ending with no tool call and no error. The required grammar of the json_native, tag_json and tag_tagged builders now accepts the reasoning block, whitespace and then the call, as the Gemma 4 parser does since ggml-org#29115. Without reasoning extraction the block is kept as content, so a thinking model can still think before the call; a peek on the start tag keeps a partial tag from streaming out as content. The whitespace allowance covers templates whose reasoning end tag carries no newline, such as QwQ, whose generation prompt opens the block. auto and none are unchanged. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit c407611)
Overview
Fixes #29089. The parsing for awkward edge cases negatively impacts the grammar when
tool_choice = required.Requirements