Repository navigation
Studio: keep stream deltas that contain U+2028, U+2029 or U+0085 - #17725
danielhanchen merged 5 commits into
Conversation
The durable chat-run worker split each SSE event with str.splitlines(), which also breaks at U+2028, U+2029 and U+0085. JSON leaves those characters unescaped, and both model_dump_json and llama-server write them raw, so a delta holding one was cut in two, failed json.loads and was silently dropped from the stored reply. Split on LF only, as the SSE line endings are already normalized to LF.
httpx aiter_lines() and str.splitlines() also break at U+2028, U+2029 and U+0085, which llama-server, vLLM and pydantic leave unescaped in JSON. The OpenAI passthrough forwarded the broken half as an invalid SSE event, the Anthropic passthrough dropped the delta. Read every upstream stream through one CR/LF-only line iterator and use the same split in the in-process event parsers.
|
@codex review |
1 similar comment
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b81a0348b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if "\n" not in text and "\r" not in text: | ||
| continue |
There was a problem hiding this comment.
Process buffered CRs before skipping newline-free chunks
For CR-delimited upstream streams, if a chunk ends with \r and the next chunk contains no CR/LF, this fast path skips the delimiter already buffered in pending. I reproduced this with a live response yielding a complete data: JSON line ending in CR, followed by data: {: httpx.aiter_lines() delivers the first line when the second chunk arrives, but this replacement blocks until another delimiter or EOF. The relay's _aiter_llama_stream_items consequently can raise its first-token timeout despite having received a complete data line. Account for a held CR in this condition and test delivery while the response remains open; collecting through EOF hides the regression.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 72efd34: a held CR now ends its line on the next chunk, matching httpx aiter_lines(); regression test added.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… stock baseline (#17808) ## Summary `tests/test_fp8_ragged_block_dequant.py::test_ragged_rows_match_block_reference[glm5_3]` and `[ling3]` fail in `Repo tests (CPU, rest)` on every PR whose CI installs unsloth-zoo at or after `898a6b0d` (unslothai/unsloth-zoo#2515). Seen on #17725 and #17801: ``` tests/test_fp8_ragged_block_dequant.py:74: in test_ragged_rows_match_block_reference with pytest.raises(ValueError): E Failed: DID NOT RAISE ValueError ``` unsloth-zoo#2515 now patches `Fp8Dequantize._dequantize_one` on import to dequantize partial edge blocks correctly. Its wrapper is marked `_unsloth_partial_block_patched` and keeps the stock function in `_unsloth_original`. This test's "unpatched" baseline only unwrapped unsloth's own ragged-block wrapper (`_unsloth_ragged_blocks` / `__wrapped__`). So the baseline was actually the zoo-fixed op, and the expected stock `ValueError` never came. The zoo patch is correct; the test's notion of "unpatched" was too narrow. ## Changes (test only) - `_op_cls(patched=False)` unwraps both markers, so the baseline is transformers' own op again. - `test_unpatched_op_carries_no_unsloth_wrapper` pins that the baseline has no unsloth or unsloth-zoo wrapper left. The `ValueError` assertion only means something against the stock op. - `test_ragged_padding_composes_over_the_zoo_partial_block_patch` covers the real-world case, where both patches are live in one process. It stacks unsloth's ragged padding on top of the zoo partial-block patch and checks the block reference for 576x384, 576x2560 and stacked 2x256x200 experts. It skips when the zoo module is absent. ## Verification | unsloth-zoo | before | after | |---|---|---| | `0c225609` (before #2515) | 6 passed | 7 passed, 1 skipped (no zoo patch module) | | `c8655b99` (main) | 2 failed, 4 passed | 8 passed | | `c8655b99`, zoo patch applied explicitly first | 2 failed, 4 passed | 8 passed | | main, with the new unwrap branch removed | | 3 failed (the two reference cases and the new baseline guard) |
…solve new forward globals in the MoE prefix harness (#2517) ## Summary Two zoo tests fail deterministically since #2515 and #2510 landed. They show up in unsloth's `Core zoo` jobs (HF=4.57.6, default and latest) for every unsloth PR whose CI uses zoo `c8655b99`, for example on the staging runs of unslothai/unsloth#17725 and #17801: ``` tests/test_temporary_patches_imports.py::test_temporary_patches_submodule_list_is_complete E AssertionError: New temporary_patches submodule(s) on disk are NOT tested by this suite: ['unsloth_zoo.temporary_patches.fp8_partial_block_dequant'] tests/test_moe_triton_config_cache_dtype.py::test_dtype_change_never_reselects_inside_compiled_forward E NameError: name 'is_mxfp4_expert_param' is not defined ``` ## Changes (tests only) - `tests/test_temporary_patches_imports.py`: add `unsloth_zoo.temporary_patches.fp8_partial_block_dequant` (new in #2515) to `TEMPORARY_PATCHES_SUBMODULES`, so the import smoke test covers it. - `tests/test_moe_triton_config_cache_dtype.py`: `_selection_prefix` execs the start of the real `forward_triton_grouped_gemm`, up to its first `with` block, against a hand-written stub namespace. #2510 made that prefix call `is_mxfp4_expert_param` (to route packed MXFP4 stacks away from the raw Triton GEMM), and the stub namespace had no such name. The stubs are now layered over the real `moe_utils` globals, so a helper the prefix starts calling resolves to the real one while every stubbed name still wins. ## Verification transformers 4.57.6 and 5.17.0, `tests/test_temporary_patches_imports.py tests/test_moe_triton_config_cache_dtype.py`: | | before | after | |---|---|---| | 4.57.6 | 2 failed | both pass (81 passed) | | 5.17.0 | 2 failed | 81 passed, 5 skipped | On 4.57.6 the five other tests in `test_moe_triton_config_cache_dtype.py` error at setup in this local environment. They do the same on zoo `0c225609`, before either PR, so the cause is my environment, not this change. Not covered here: the staging runs also show order-dependent Gemma3 failures (`test_gemma3_fa2_sliding_window_mask.py` "generic Gemma3 attention patch did not install", and `test_gemma3_forced_float32_undo.py::test_bf16_then_fp16_still_installs_forced_set`). Both pass in isolation, so I am keeping them separate.
Resolve conflicts with main's SSE_LINE_END / aiter_sse_lines (unslothai#17725) and NPU error explanation; fold the producer's EOF flush into its read loop.
…in's decoder test test_chat_generation_runs_sse_decoder.py (from unslothai#17725) imported the removed _SSEDecoder. The regex split matches the per-char loop on 30k random split streams and is ~4x faster per chunk.
Studio's chat page streams through durable chat runs, and the run worker's
_SSEDecodersplit each SSE event withstr.splitlines(). That also breaks at U+2028, U+2029 and U+0085, which JSON does not escape: both pydantic'smodel_dump_jsonand llama-server write them raw. A delta holding one of these characters is cut in two,json.loadsfails on the first half, and theexcept/continuedrops the chunk without a log line. The text is missing from the streamed reply and from the stored message, so it stays missing after a reload. Models emit these characters when they repeat text pasted from a web page or a PDF. This is the same character class as #16725 (S3 JSONL).The fix splits on
\nonly. The decoder already turns CRLF into LF and splits events on `, and the stream it reads is Studio's own LF-only SSE, so nothing else changes; multi-linedata:` fields are still joined with newlines.Feeding
_chat_chunk_sseoutput into_SSEDecodera few characters at a time, main drops the content chunk and keeps only the finish chunk; with the fix the content arrives intact. The newtests/test_chat_generation_runs_sse_decoder.py(each separator, LF and CRLF) fails 6 of 7 on main and passes 7 of 7 with the fix; together withtests/test_chat_generation_runs.pythat is 80 passed, on Windows with Python 3.12.Same bug on the upstream streams (added by maintainer)
httpx's
aiter_lines()uses the samestr.splitlines()rule, and every upstream SSE stream Studio reads went through it: the llama-server/v1/chat/completionsand/v1/messagespassthroughs (the API that agents launched withunsloth startand other clients use), external and managed-engine providers (vLLM writes these characters raw too), the subscription Responses client, and research runs.Reproduced on main through the real passthrough routes with a llama-server stream whose delta holds U+2028, U+2029 or U+0085:
/v1/chat/completionsstream: the first half is forwarded as its own SSE event, so the client getsUnterminated stringJSON and the rest of the delta is lost./v1/messagesstream: the delta is dropped, the client receives empty text.Changes:
core/inference/http_stream.py:aiter_sse_lines(response), a drop-in foraiter_lines()that splits only at CR, LF and CRLF (a trailing CR is held until the next chunk), and closes its inneraiter_text()iterator itself. Used at every upstreamaiter_lines()call site and byclosing_response_lines. Objects withoutaiter_textkeep their ownaiter_lines().SSE_LINE_END) in_SSEDecoder, in llama_cpp's_sse_event_payload(first-output detection missed a separator delta) and in the/v1/chat/completionsand/v1/messagesAPI monitors (an upstream error whose message held one was not flagged).Tests:
tests/test_http_stream_sse_lines.py(line-for-line parity with httpxaiter_lines()at every chunk boundary of a mixed CR / LF / CRLF stream, separators kept at every cut, stream closed, llama payload and monitor cases) plus end-to-end passthrough cases intest_openai_passthrough_respawn.pyandtest_anthropic_passthrough_respawn.py, which fail on main and pass here. The backend files with fakes ofaiter_lines()(research runs, managed engines, subscription Responses client, tool confirm) pass unchanged; the failure set of every other file that failed in a loaded full run is identical on main and on this branch. Per event the new iterator costs about 1 us over httpx's.