Text-based state machine - #1501
Merged
Merged
Conversation
Replace the token-based SequenceStateMachine with a StopSequenceMatcher (EOS/stop words, token-level, used by the batch generator) and a TextStateMachine that matches decoded text to track reasoning/tool state and strip control sequences. Matching on text rather than token ids is robust to tokenization differences (e.g. a marker's trailing '>' merging with the next byte) and keeps state on stop, so tool calls with an empty tool_call_end (Mistral/ Devstral) are no longer dropped. Also wires a reasoning->tool transition.
angeloskath
force-pushed
the
str-state-machine
branch
from
July 8, 2026 22:25
87fc6e2 to
bc20a49
Compare
Collaborator
|
Beautiful fix, thank you! Splitting it into two machines makes a lot of sense: one on decoded text for stripping thinking / tool-calling, one on token ids to stop generation. Nice buffering approach to ensure that we find a full match. |
nastya236
approved these changes
Jul 8, 2026
This was referenced Jul 8, 2026
This was referenced Aug 19, 2026
Closed
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.
The token based SequenceStateMachine has a design flaw that makes it impossible to identify the state change because substrings can be encoded in different ways.
This replaces it with TextStateMachine so we switch state on the actual string and not the tokens. It also introduces a StopSequenceMatcher that can be used to make sure that generation stops on specific token sequences.
This fixes #1373, #1447, #1406, #1336, #1160 .