Skip to content

[Feat] sgl-router: Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor - #43689

Merged
ShangmingCai merged 6 commits into
mainfrom
kan/sgl-router-qwen38
Oct 14, 2026
Merged

ShangmingCai merged 6 commits into
mainfrom
kan/sgl-router-qwen38

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Stack 3/3, merge in order: #43625 (GLM-5.3) → #43608 (Kimi-K3) → #43689 (Qwen3.8). This PR is based on #43608 (kan/sgl-router-kimi-k3), so its diff shows only the Qwen3.8 commits. After the PRs below merge it gets rebased onto main.

Adds Qwen3.8 to sglang-processor and serves it from sgl-router end to end: Qwen3.8-Max (Qwen/Qwen3.8-2.4T-A95B), Qwen3.8-27B and Qwen3.8-Flash-Next. With the cookbook's qwen3 and qwen3_coder parsers, the router renders, tokenizes and parses every text chat and talks to the engine through /generate.

Modifications

  • Render: ChatFormatter::Qwen38 (render/models/qwen38.rs), picked in from_tokenizer_config by its template. SGLang renders Qwen3.8 with apply_chat_template (no encoding spec), so the processor builds the template context _process_messages and _apply_jinja_template build and renders it with Dynamo's Jinja formatter:

    • messages, tools and tool calls as the pydantic dumps give them (Tool.type as sent, Tool's null defer_loading, FunctionResponse's null arguments);
    • content in the template's content format: Max's text-only template gets strings (text parts joined with spaces), the vision template of 27B and Flash-Next gets parts lists, which it concatenates;
    • kwargs over the request effort, then the server's default kwargs; reserved kwargs and documents are checked after the defaults merge in, as for GLM-5.3.

    Where Dynamo departs from Python, the processor fails rather than render differently, so hosts leave the chat to the engine: a later system turn (Dynamo demotes it, the template raises), media, text whose trim differs (U+001C..U+001F), and numbers serde_json prints unlike Python.

  • Parsing:

    • think/models/qwen3.rs: Qwen3Detector, the base detector over <think> with <tool_call> ending the reasoning.
    • tool_call/models/qwen3_coder.rs: Qwen3CoderDetector, streaming and one-shot. Argument values are typed by the request's tool schemas as _convert_param_value types them (int(), float(), json.loads, and the JSON-like subset of ast.literal_eval). Tool detectors now take the request's tools rather than their names, and the parser feature's stream gives an id and name only to a named call item, as Python does.
    • sglang-server, whose parser registry these ports also serve: qwen3 starts in reasoning when the prompt ends in a prefilled <think> (as it already did for DeepSeek-V4), and parallel_tool_calls=false keeps every delta of the first call, which qwen3_coder streams as a name and argument fragments (the response processor too).
    • ChatModel.reasoning_toggle: the template's toggle (enable_thinking, on by default for all three checkpoints), which _get_reasoning_from_request reads. The template prefills <think>\n, so this decides require_reasoning and the forced reasoning split.
  • Router: renders Qwen3.8 through the processor, so every text chat forwards input_ids (AllText), and with the cookbook's parsers lowers it to /generate. required, named and strict tool choices, media and sglext fields such as return_meta_info keep the engine's route.

Left as known differences, where Python itself fails or the case is out of reach:

  • tool argument literals json.dumps cannot serialize (sets, bytes, complex numbers) stay strings; Python drops the call in unary responses and raises mid-stream;
  • \N{...} escapes and lone surrogates in literal-typed arguments stay strings.

Checks

  • Render: 136 cases per checkpoint match SGLang's prompt text and token ids at the pinned revisions; 5 per checkpoint are known_gaps the processor leaves to the engine (trim separators, exponent floats, huge integers).

  • Parsers (fixtures from SGLang's Python): reasoning_parity/qwen3.json (88 cases) and tool_parity/qwen3_coder.json (45 outputs, 50 chunkings, covering schema typing, Unicode decimal digits, Python-literal fallbacks including parenthesized signed numbers, the 200-bracket nesting limit and key merging, truncation, marker splits). A throwaway randomized comparison also matched Python on 60,000 typed values and 50,000 chunked streams (apart from an empty function name, which is served identically).

  • OpenAI layer: openai_parity/qwen3.8-27b.json, 13 cases recorded from OpenAIServingChat against a live Qwen3.8-27B engine (thinking on/off/effort, truncation, continuation, tools with and without thinking, typed arguments, unary and streaming, tool_choice: none, and required left to the engine); generic OpenAI-layer behavior is covered by the other models' fixtures and the live run below: the /generate body and the OpenAI response match.

  • Live, Qwen3.8-27B on one B300 (cookbook GB300 BF16 cell with its default overlays, plus --log-requests-level 3); each chat was sent to the engine directly and through the real sgl-router binary, flushing the cache before each:

    Check Result
    Router chats served via /generate 50 / 61
    Identical engine-side GenerateReqInput on those 50 / 50
    Identical responses on those 48 / 50
    GSM8K (1314, chat API, reasoning_effort=low, greedy) engine 0.977, router 0.979, every router request via /generate

    The two differing responses are a seeded-sampling request that also varies between runs on the engine alone, and an n=2 stream whose choices interleave differently with the same per-choice text. The 11 chats on the engine's route are required/named/strict tools, an image, and rejected requests, which return the same 400 on both paths.

  • cargo test, cargo clippy --all-targets -- -D warnings and cargo fmt --check pass for rust/ and experimental/sgl-router, as do cargo check -p sglang-processor --no-default-features --features render,tokenizer and --features render,openai.


CI States

Latest PR Test (Base): 🚫 Run #38530778150
Latest PR Test (Extra): ❌ Run #38530778201
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

@github-actions github-actions Bot added documentation Improvements or additions to documentation deepseek rust-renderer labels Oct 11, 2026
@sherlockwu
sherlockwu force-pushed the kan/sgl-router-qwen38 branch from 595a22e to 1098847 Compare October 11, 2026 17:49
@github-actions github-actions Bot added the npu label Oct 11, 2026
@sherlockwu
sherlockwu changed the base branch from main to kan/sgl-router-kimi-k3 October 11, 2026 17:50
@sherlockwu
sherlockwu added this pull request to stack #43717 October 11, 2026 17:54
@sherlockwu sherlockwu added run-ci CI: run the baseline test suite on this PR and removed npu labels Oct 11, 2026
@sherlockwu
sherlockwu force-pushed the kan/sgl-router-qwen38 branch from 1098847 to 713de89 Compare October 13, 2026 07:07
@github-actions github-actions Bot added the npu label Oct 13, 2026
@sherlockwu
sherlockwu force-pushed the kan/sgl-router-qwen38 branch from 713de89 to 00230df Compare October 13, 2026 07:14
@sherlockwu
sherlockwu force-pushed the kan/sgl-router-qwen38 branch from fd51a31 to 6082a09 Compare October 13, 2026 08:06
Base automatically changed from kan/sgl-router-kimi-k3 to main October 14, 2026 06:40
@ShangmingCai
ShangmingCai force-pushed the kan/sgl-router-qwen38 branch from 6082a09 to f82ea4c Compare October 14, 2026 07:09
@ShangmingCai ShangmingCai changed the title [sgl-router] Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor [FEAT] sgl-router: Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor Oct 14, 2026
sherlockwu and others added 6 commits October 14, 2026 07:31
…cessor

sglang-processor renders Qwen3.8 (ChatFormatter::Qwen38) as SGLang's Jinja
path does: picked by its template, with the template context
_process_messages and _apply_jinja_template build (pydantic dumps of
messages, tools and tool calls, content in the template's content format,
kwargs over the effort, server defaults), rendered by Dynamo's Jinja
formatter. A later system turn fails as the template makes it fail, where
Dynamo would demote it. Media, a chat_template kwarg, and text or numbers
Python's trim or json.dumps treat unlike Dynamo's are left to the engine.

sgl-router renders Qwen3.8 through the processor, so every text chat forwards
input_ids. The parity generator now renders through _process_messages with
SGLang's TemplateManager, records a Jinja checkpoint's template, and takes
per-case server default kwargs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Dump each tool's `type` as sent: `Tool.type` is any string, and the
  template prints it, where the shared normalizer always wrote "function".
- Check reserved kwargs after the server defaults merge in, as GLM-5.3
  does: a default `tokenize` or `tools` fails `apply_chat_template`.
- Reject `documents` that do not iterate as dicts, as
  `render_jinja_template` does (GLM-5.3's `valid_documents`).
- Regenerate the three fixtures on the rebased generator. SGLang now
  rejects a request `chat_template` kwarg and, serving the checkpoint
  text-only, an image part, so both gaps are closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- think/: `qwen3` (`Qwen3Detector`), the base detector over `<think>`
  with `<tool_call>` ending the reasoning.
- tool_call/: `qwen3_coder` (`Qwen3CoderDetector`), streaming and
  one-shot. Argument values are typed by the request's tool schemas as
  `_convert_param_value` types them (`int()`, `float()`, `json.loads`, and
  the JSON-like subset of `ast.literal_eval`); literals `json.dumps`
  cannot serialize stay strings, where Python fails the call. Tool
  detectors now take the request's tools rather than their names, and the
  parser stream gives an id and name only to a named call item.
- openai/: `ChatModel.reasoning_toggle` carries the template's toggle
  (`enable_thinking`, on by default for Qwen3.8), which
  `_get_reasoning_from_request` reads before the parser's default.
- sgl-router sets it from the formatter, so with the cookbook's `qwen3`
  and `qwen3_coder` parsers Qwen3.8 text chats are rendered, tokenized
  and parsed by the router and sent to the engine's /generate.
- Fixtures from SGLang's Python: reasoning_parity/qwen3.json,
  tool_parity/qwen3_coder.json (44 outputs, 49 chunkings), and
  openai_parity/qwen3.8-27b.json (13 cases recorded on a live
  Qwen3.8-27B engine). The OpenAI-parity generator drops unread meta
  keys before encoding stream deltas, since this engine sends
  `response_sent_to_client_ts` on the first frame only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- sglang-server: the ported `qwen3` detector needs the reasoning state the
  template sets, as Python's does, where Dynamo's parser split an output
  without an opening `<think>` on its own. The server already forced it for
  DeepSeek-V4 when the prompt ends in `<think>`; Qwen3.8's prompt does too,
  with a newline.
- `parallel_tool_calls=false` kept only a choice's first call item, which for
  `qwen3_coder` is the name alone. The response processor and the server's
  stream now keep every item of the first call index.
- `qwen3_coder`: `int()` and `float()` read Unicode decimal digits
  (`123`, `١٢.٥`), and a sign takes a parenthesized number (`-(1)`), as
  in Python. tool_parity covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…izer does

- Blank and comment-only lines around a literal argument are skipped, at any
  indentation, as Python's tokenizer skips them; a last line of bare spaces
  is still an `IndentationError`.
- Hexadecimal, octal and binary integers keep arbitrary precision, as decimal
  ones did. `int()` and decimal literals stop at Python's 4300-digit limit,
  and values `json.dumps` cannot print past it stay strings.

tool_parity covers comment lines, 129-bit and larger radix literals, and the
digit limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ShangmingCai ShangmingCai changed the title [FEAT] sgl-router: Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor [Feat] sgl-router: Render Qwen3.8 (Max, 27B, Flash-Next) through sglang-processor Oct 14, 2026
@sherlockwu
sherlockwu force-pushed the kan/sgl-router-qwen38 branch from 04d2d3e to 21a0e8d Compare October 14, 2026 07:48
@ShangmingCai
ShangmingCai merged commit 817781b into main Oct 14, 2026
105 of 111 checks passed
@ShangmingCai
ShangmingCai deleted the kan/sgl-router-qwen38 branch October 14, 2026 09:09
ShangmingCai added a commit that referenced this pull request Oct 14, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek documentation Improvements or additions to documentation npu 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