Repository navigation
Emit only the new scalars when a token extends the previous character - #613
Merged
davidkoski merged 1 commit intoSep 10, 2026
Merged
Conversation
NaiveStreamingDetokenizer.next() measured the common prefix between the previous decode and the new one in Characters, so a token that appended a combining scalar (U+FE0F, a zero-width joiner, an accent) to the previous character re-emitted the whole merged cluster: a ZWJ flag sequence streamed as its base flag repeated, a quote followed by a variation selector as two quotes. The prefix is now measured in Unicode scalars, which compares exactly and keeps the fallback for tokenizers whose decode is not append-only. Four tests in StreamingDetokenizerTests stream a ZWJ flag sequence, a variation selector after an ASCII quote, a combining accent, and a variation selector after a multi-byte character split across two tokens, and compare the scalar sequence with the full decode.
davidkoski
approved these changes
Sep 10, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Looks great, nice find! Thank you.
5 tasks done
wballard
added a commit
to swissarmyhammer/mlx-swift-lm-old
that referenced
this pull request
Sep 14, 2026
Apply the upstream commits e3d4a20..3e6ea1e as a 3-way patch. CLAUDE.md is excluded. - db05290 Let training differentiate the gated-delta recurrence (ml-explore#616) - 4c3d793 Emit only the new scalars when a token extends the previous character (ml-explore#613) - 1012230 Gemma 4 VLM: fuse float32 logit softcapping (ml-explore#615) - 9ce5b4f Fix generation loop blocking Swift cooperative workers (ml-explore#611) - 238ad74 Add configuration-based LoRA metadata discovery (ml-explore#597) - 604fae7 RotatingKVCache: make trim wrap-aware instead of corrupting the ring (ml-explore#584) - a56aee3 Add bounded cross-dialect tool-call recovery (ml-explore#548) - 3e6ea1e Reuse the KV cache for append-only media turns (ml-explore#515) Conflict resolutions: - Evaluate.swift: keep the shared generateSpeculativeStream helper. It now receives parameters and tools, and passes tools and toolCallPolicy to TextToolTokenLoopHandler for the draft-model and MTP paths. - PromptCacheReusePolicy.swift: keep the package access of the turn fields, and make canSplitPreparedMedia package also. reconcilePromptCache has no prepared input to split, thus it answers .appendMediaSuffix with nil. - ToolCallFormat.swift: keep buffersEntireResponse and add supportsBareJSON. - ToolCallProcessor.swift: the buffersEntireResponse check stays first in processChunk. The recovery scanner path comes after it. Follow-up changes: - AllowedToolOutputRouter: join adjacent response outputs into one event. The recovery scanner can divide response text at a "<" that does not start a call. - Gemma4FusionTests: delete testFusionLatency. It runs only when an environment variable is set, and stable runs no skipped tests. Tests: all five bundles pass with no skipped test (MLXLMTests 1170 Swift Testing + 693 XCTest, MLXGuidedGenerationTests 70, MLXFoundationModelsTests 213, CXGrammarTests 7, MLXHuggingFaceMacrosTests 5). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TEgdBA8Ap14pU1EfmHkazD
djandrewgibbons
pushed a commit
to djandrewgibbons/mlx-swift-lm
that referenced
this pull request
Sep 26, 2026
…ml-explore#613) NaiveStreamingDetokenizer.next() measured the common prefix between the previous decode and the new one in Characters, so a token that appended a combining scalar (U+FE0F, a zero-width joiner, an accent) to the previous character re-emitted the whole merged cluster: a ZWJ flag sequence streamed as its base flag repeated, a quote followed by a variation selector as two quotes. The prefix is now measured in Unicode scalars, which compares exactly and keeps the fallback for tokenizers whose decode is not append-only. Four tests in StreamingDetokenizerTests stream a ZWJ flag sequence, a variation selector after an ASCII quote, a combining accent, and a variation selector after a multi-byte character split across two tokens, and compare the scalar sequence with the full decode.
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 #612.
NaiveStreamingDetokenizer.next()measured the common prefix between the previous decode and the new one inCharacters, so a token that appended a combining scalar (U+FE0F, a zero-width joiner, an accent) to the previous character turned the whole merged grapheme cluster into "new" text and re-emitted its base. The prefix is now measured in Unicode scalars, which compares exactly and keeps the #465 behaviour for tokenizers whose decode is not append-only. Four tests inStreamingDetokenizerTestsstream a ZWJ flag sequence, a variation selector after an ASCII quote, a combining accent, and a variation selector after a multi-byte character split across two tokens, and compare the scalar sequence with the full decode; they fail onmainand pass with this change.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.