Fix end-of-turn token leaking into streamed chat output - #747
Open
PratikDhanave wants to merge 1 commit into
Open
Fix end-of-turn token leaking into streamed chat output#747PratikDhanave wants to merge 1 commit into
PratikDhanave wants to merge 1 commit into
Conversation
In `_print_stream`, the guard meant to suppress the end-of-turn marker (`<end_of_turn>` / `<turn|>`) was placed *after* the print and append, with `continue` as the loop body's final statement -- making it a no-op. As a result the end-of-turn marker was both streamed to the user and concatenated into the returned `SamplerOutput.text`, contradicting the "Last token is not printed" comment. Move the guard ahead of the print/append so the marker is skipped as intended.
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.
What
_print_streamingemma/gm/text/_chat_sampler.py(used byChatSampleron the streaming path) is meant to suppress the end-of-turn marker from the streamed/returned text — the comment says "Last token is not printed." But the guard is placed after the work it should gate:Because
print_andappendrun before theif, andcontinueis the final statement in the loop body (so it does nothing), the end-of-turn marker (<end_of_turn>/<turn|>) is:SamplerOutput.text.Any streamed chat turn ending normally therefore leaks the literal end-of-turn token into the user-visible output.
Change
Move the guard ahead of the print/append so the marker is skipped, matching the documented intent. No other behavior change.