Repository navigation
[Fix] sglang-processor: Follow Python's OpenAI layer through #43027, #37577, #43006, #43026, #43005 - #44243
Merged
Conversation
…43006, #43026, #43005 The /generate path the router and Rust server serve chats through had fallen behind five Python changes on main: - #43027: chat messages and stream deltas omit `tool_calls` when there are none. - #37577: chat and completions requests forward `watermark` into sampling params; the router served it through /generate and dropped it. - #43006: DeepSeek-V4 and V4.1 render no tools under `tool_choice: "none"`, or under a named choice no request tool matches. - #43026: every chunk of a chat stream carries the same `created`. - #43005: with cache reporting on, usage reports `cached_tokens: 0`. Regenerate the openai_parity and DeepSeek render fixtures from Python on main, add synthetic `watermark` cases for chat and completions, and check that a stream's chunks share one `created`. sgl-router's DeepSeek fixture generator passed `tools=None` to `_apply_jinja_template`, which #43006 now reads; pass the tools `_process_messages` would. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t value Replaying chunks back to back rarely crosses a second boundary, so the parity-test check passed even with per-chunk `now()` restored. Pin the responder's `created` to 1 instead: any chunk that re-reads the clock now fails deterministically. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…44269) Co-authored-by: Shangming Cai <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…main The fixture from #43689 was recorded before #43027, so its responses still carried `"tool_calls": null`, which this branch now omits like Python does. Regenerated with tests/scripts/generate_openai_parity.py from main's Python at the pinned revision, replaying the recorded engine output. Besides the dropped `tool_calls`, only `created`/tool-call ids change and the defaults pick up `watermark` (#37577) and `return_flat_raw_output_top_logprobs`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
TODO:
Locally: |
The experimental router does not need to support engines older than the `watermark` sampling param (#37577), so mirror Python's OpenAI layer and always send `"watermark"` in `sampling_params`. This raises the minimum engine for lowered OpenAI requests to #37577: older engines reject the key with `TypeError: Unexpected keyword argument 'watermark'`. This reverts commit 2353159. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Motivation
sgl-router and the Rust server serve OpenAI chats through
/generate, usingrust/sglang-processorto do what Python's OpenAI layer does. Five Python changes merged to main after the processor's parity fixtures were recorded, so the Rust path no longer matches Python's:/generatepath did insteadtool_calls"tool_calls": nullin chat messages and in tool-parsing stream deltaswatermark/generatewithout the field, so a client that asked for a watermark got unwatermarked outputtool_choice: "none"createdprompt_tokens_detailswhen the cached count was 0 under--enable-cache-reportThe fixtures were recorded before these changes, so the tests kept passing. I found the first two by running Qwen3.8-27B through the router against the engine's own
/v1/chat/completions(#43689). The other three surfaced when I regenerated the fixtures from Python on main.Modifications
openai/chat.rs,openai/completions.rs: forwardwatermarkintosampling_params(validation stays with the engine's tokenizer manager, which serves both routes); omit nulltool_callsfrom unary messages and tool-parsing stream deltas; give each chat stream a singlecreated.openai/wire.rs: keepprompt_tokens_detailswithcached_tokens: 0when cache reporting is on.render/models/deepseek_v4.rs,deepseek_v41.rs: render request tools only whenserving_chatpasses them on (tool_choiceother than"none", and a named choice must match a request tool). The tools are still validated either way, as pydantic does.openai_parity/*(offline, reusing the recorded engine outputs), the DeepSeek render fixtures intests/fixtures/parity/, and sgl-router'stests/fixtures/deepseek/. Added syntheticwatermarkcases for chat (GLM-5.3) and completions (DeepSeek-V4-Flash-0731).tests/openai_parity.rs: a streamed response fails if its chunks disagree oncreated.wire.rsgets a unit test for zero cached tokens.generate_deepseek_parity.pypassedtools=Noneto_apply_jinja_template, which the DeepSeek branch ignored until fix(openai): honor tool_choice=none in DeepSeek encoders #43006. It now passes the tools_process_messageswould. With that, regeneration only changes the twotools_nonecases.The fixture diffs are mostly churn:
createdtimestamps, randomcall_ids (the test ignores both), the newwatermark/return_flat_raw_output_top_logprobsdefaults, andchat_encoding_specfor the DeepSeek fixtures. The semantic changes are the removedtool_calls: nullkeys and the twotools_noneprompts.Accuracy Tests
cargo test -p sglang-processor --all-featurespasses, with token ids checked against the cached pinned checkpoints. Run against the oldsrc/, the regenerated fixtures fail.cargo testpasses (1077 + 208 + 138 + 8), as dosglang-rendererandsglang-server. Clippy and pre-commit are clean.--chat-routing reorg) built from [Feat] sgl-router: Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor #43689 with this branch merged in. In the 48-case router-vs-engine suite, every case served through/generatematches the engine's route ininput_idsand response, apart from the expectedn: 2stream interleaving and seeded sampling. No result masking was needed. Before this change, thewatermark: Nonesampling key and"tool_calls": nullhad to be masked to get there.watermarkrequest through the router now takes/generateand gets the same 400 as the engine's own route, both for a bad key and when the server was not started with--enable-watermark. All 62 chunks of a streamed chat share onecreated.Checklist
CI States
Latest PR Test (Base): ✅ Run #38563387498
Latest PR Test (Extra): ❌ Run #38563387814
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.