Skip to content

Studio: fix broken Chinese, Japanese and emoji text in gpt-oss replies - #11720

Merged
Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:harmony-stream-utf8
Sep 24, 2026
Merged

Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:harmony-stream-utf8

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When chatting with gpt-oss, characters like Chinese, Japanese and emoji sometimes show up as � or go missing. This happens when one character is split across two pieces of the reply.

This waits until the character is complete before sending it.

@Lyxot Lyxot self-assigned this Sep 24, 2026
Stripping U+FFFD from every channel segment deferred a closed segment's trailing replacement character until end(), which then emitted it after later channels, so reasoning text could land after </think> in the answer. Strip only the trailing U+FFFD of the whole decode in put(), as _mlx_stop_cut does; end() decodes everything again and releases any bytes that never resolved. The stop-sequence path is unchanged, since _mlx_stop_cut already keeps its cut off an unresolved tail.
@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Pushed one follow-up commit on top of this PR:

  • 857bf70 fix(studio): hold back only the open tail of a harmony decode. The original change stripped a trailing U+FFFD from every channel segment, including closed ones. When a reasoning segment ended in an unresolved byte right before <|end|>, its � was deferred to end() and emitted after the final channel, so reasoning text landed after </think> in the answer (<think>ab</think>xy�). Now only the trailing U+FFFD of the whole decode is held back, in put(), which is the same rule _mlx_stop_cut already applies on the stop-sequence path. end() still re-decodes everything, so bytes that never resolve are still delivered. The final flag and _raw state are gone, and the production change is now one line. The test also ends the analysis segment with an unresolved byte.

Validation: test_transformers_stop_sequences.py, test_safetensors_reasoning_stream.py and test_refactor_guard.py pass. The new test fails on the merge base and on the per-segment strip. Streaming CJK and emoji split byte by byte through a real tokenizers ByteLevel decoder gives the exact text with no � chunks, with and without stop sequences.

@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Codex review and CI on a staging copy with the same head (857bf705b3): Lyxot#85

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Fixes lost CJK and emoji characters in gpt-oss streaming; Codex and staging CI are clean at 857bf70.

@Lyxot
Lyxot merged commit 7501b31 into unslothai:main Sep 24, 2026
40 of 41 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
unslothai#11720)

HarmonyTextStreamer now holds back the trailing U+FFFD of each decode until the next token resolves it, so a character split across tokens is no longer shown as a replacement character and lost. end() still delivers bytes that never resolve.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants