Skip to content

[Fix] sglang-processor: Follow Python's OpenAI layer through #43027, #37577, #43006, #43026, #43005 - #44243

Merged
ShangmingCai merged 6 commits into
mainfrom
kan/router-openai-main-parity
Oct 14, 2026
Merged

ShangmingCai merged 6 commits into
mainfrom
kan/router-openai-main-parity

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

sgl-router and the Rust server serve OpenAI chats through /generate, using rust/sglang-processor to 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:

Python change What the /generate path did instead
#43027 — omit absent tool_calls sent "tool_calls": null in chat messages and in tool-parsing stream deltas
#37577 — request watermark served the request through /generate without the field, so a client that asked for a watermark got unwatermarked output
#43006 — DeepSeek honors tool_choice: "none" still rendered every tool into DeepSeek-V4/V4.1 prompts (279 tokens instead of 5 for the fixture case)
#43026 — stable stream created stamped each chat stream chunk with the current time
#43005 — report zero cached tokens dropped prompt_tokens_details when the cached count was 0 under --enable-cache-report

The 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: forward watermark into sampling_params (validation stays with the engine's tokenizer manager, which serves both routes); omit null tool_calls from unary messages and tool-parsing stream deltas; give each chat stream a single created.
  • openai/wire.rs: keep prompt_tokens_details with cached_tokens: 0 when cache reporting is on.
  • render/models/deepseek_v4.rs, deepseek_v41.rs: render request tools only when serving_chat passes them on (tool_choice other than "none", and a named choice must match a request tool). The tools are still validated either way, as pydantic does.
  • Fixtures regenerated from Python on main: openai_parity/* (offline, reusing the recorded engine outputs), the DeepSeek render fixtures in tests/fixtures/parity/, and sgl-router's tests/fixtures/deepseek/. Added synthetic watermark cases for chat (GLM-5.3) and completions (DeepSeek-V4-Flash-0731).
  • tests/openai_parity.rs: a streamed response fails if its chunks disagree on created. wire.rs gets a unit test for zero cached tokens.
  • sgl-router's generate_deepseek_parity.py passed tools=None to _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_messages would. With that, regeneration only changes the two tools_none cases.

The fixture diffs are mostly churn: created timestamps, random call_ ids (the test ignores both), the new watermark / return_flat_raw_output_top_logprobs defaults, and chat_encoding_spec for the DeepSeek fixtures. The semantic changes are the removed tool_calls: null keys and the two tools_none prompts.

Accuracy Tests

  • cargo test -p sglang-processor --all-features passes, with token ids checked against the cached pinned checkpoints. Run against the old src/, the regenerated fixtures fail.
  • sgl-router cargo test passes (1077 + 208 + 138 + 8), as do sglang-renderer and sglang-server. Clippy and pre-commit are clean.
  • Live, Qwen3.8-27B: one engine plus sgl-router (--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 /generate matches the engine's route in input_ids and response, apart from the expected n: 2 stream interleaving and seeded sampling. No result masking was needed. Before this change, the watermark: None sampling key and "tool_calls": null had to be masked to get there.
  • A watermark request through the router now takes /generate and 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 one created.

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.

…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]>
ShangmingCai and others added 3 commits October 15, 2026 00:37
…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]>
@ShangmingCai

ShangmingCai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

TODO:

Locally: cargo test -p sglang-processor --all-features passes (openai_parity with no skipped cases), fmt and clippy are clean, and the experimental/sgl-router test suite passes.

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]>
@ShangmingCai
ShangmingCai merged commit 204644c into main Oct 14, 2026
118 of 123 checks passed
@ShangmingCai
ShangmingCai deleted the kan/router-openai-main-parity branch October 14, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek run-ci CI: run the baseline test suite on this PR rust-renderer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants