Fix gemma4 prefill parsing#22325
Open
Quairon-Nailo wants to merge 2 commits intoggml-org:masterfrom
Open
Conversation
Contributor
|
If its primarily a prefill issue, I guess I'll see how we can accommodate. Seems to be a hot issue lately... |
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.
Overview
This PR fixes an issue in the
peg-gemma4chat format parser where prefilled reasoning blocks cause the parser to fail and silently drop the rest of the model's response.The Problem:
As reported and discussed here, the parser's
thoughtrule currently strictly expects the generation to begin with the<|channel>token. When a frontend (like SillyTavern) prefills the<|channel>token into the context to force reasoning, the newly generated text begins withthought\n...or similar. Because it lacks the leading<|channel>, thethoughtrule fails. The parser falls back to evaluating it as standardcontent, which is designed to halt at an unmatched<channel|>token to prevent trailing hallucinations. Consequently, the parser stops prematurely right after the reasoning block, truncating the actual response.The Solution:
data.promptspecifically within the current assistant turn (after<|turn>model) to detect if there is an unclosed<|channel>tag. If an unclosed tag is detected in the current turn, the parser modifies its root structure to use afirst-messagerule. This bypasses standard choice (|) evaluations, eliminating PEG buffering and allowing the prefilled reasoning block to stream live to the user. A newresumed-thoughtrule uses an optional prefix ("thought") and captures all text up to the closing<channel|>tag. This gracefully handles both standard tag-only prefills and arbitrary text prefills seamlessly.Requirements
resumed-thoughtfallback rule, and adding the context-boundary check to restore streaming functionality. I have manually reviewed, rigorously tested edge cases, and fully understand the implemented logic.