Repository navigation
🐞 Tokenizer: Flush held text when streaming generation ends - #670
Merged
davidkoski merged 1 commit intoOct 6, 2026
Merged
davidkoski merged 1 commit into
davidkoski merged 1 commit into
Conversation
This was referenced Oct 3, 2026
aleroot
force-pushed
the
alessio/streaming-detokenizer-finalization
branch
from
October 6, 2026 18:53
54d3f42 to
9f7d582
Compare
davidkoski
approved these changes
Oct 6, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Change looks good, thank you!
wballard
added a commit
to swissarmyhammer/mlx-swift-lm-old
that referenced
this pull request
Oct 7, 2026
Apply the upstream commit ecd8e88..4ea4225 as a 3-way patch. CLAUDE.md is excluded. - 4ea4225 Tokenizer: Flush held text when streaming generation ends (ml-explore#670) The patch applies with no conflicts. Each stable user of NaiveStreamingDetokenizer and TokenLoopHandler.onGenerationEnd is the same as upstream, thus no stable-only path needs the new finish() flush. Tests (xcrun xctest): MLXLMTests 1351 Swift Testing and 716 XCTest tests pass. MLXGuidedGenerationTests 70, MLXFoundationModelsTests 349, CXGrammarTests 7, MLXHuggingFaceMacrosTests 5 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Proposed changes
Fixes #636
NaiveStreamingDetokenizer holds decoded text ending in a replacement character while waiting for more tokens. When generation ends, that buffered text is never emitted, potentially dropping both the replacement character and valid preceding text.
Add an idempotent finish() method and flush pending text through the existing generation, reasoning, tool, and framed-output pipelines. Final text passes through the usual stop-string filtering and parsers, while preserving consumer cancellation and frame boundaries.
Related to #636 and #619. This addresses dropped text at stream completion; arbitrary cleanup-induced prefix rewrites still require tokenizer-aware buffered decoding.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.