Skip to content

fix: preserve split UTF-8 before streaming stop sequences - #2437

Open
cloudgpuapp wants to merge 1 commit into
abetlen:mainfrom
cloudgpuapp:fix/stream-stop-utf8
Open

cloudgpuapp wants to merge 1 commit into
abetlen:mainfrom
cloudgpuapp:fix/stream-stop-utf8

Conversation

@cloudgpuapp

Copy link
Copy Markdown
Contributor

What changed

Decode the buffered tail as one UTF-8 string when flushing a text completion without logprobs. Previously, the final flush decoded each token separately, so a character split between two tokens could disappear when the second token also contained the stop sequence.

The regression feeds two synthetic tokens, splitting é across their byte payloads. It also covers ASCII before the stop marker and a marker with no preceding text. The token-wise logprobs path is unchanged.

Tests

  • Regression on upstream c0d5530: 1 failed, 2 passed.
  • With the patch: 8 passed across streaming, grammar, and chat-format tests on macOS ARM64 with Python 3.13 and the pinned native library. The streaming cases use synthetic tokens.
  • Ruff lint and formatting checks passed.

Related background: #372. The regression here targets the final flush when a stop sequence is found.

AI assistance: Used to investigate the issue, write the patch and tests, and prepare this description.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant