Skip to content

[sgl-router] Render GLM-5.3 and GLM-5.3-Flash through sglang-processor - #43625

Merged
ShangmingCai merged 8 commits into
mainfrom
kan/sgl-router-glm53
Oct 14, 2026
Merged

ShangmingCai merged 8 commits into
mainfrom
kan/sgl-router-glm53

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Stack 1/3, merge in order: #43625 (GLM-5.3) → #43608 (Kimi-K3) → #43689 (Qwen3.8). This PR is based on main.

Adds GLM-5.3 and GLM-5.3-Flash to sglang-processor. The router renders them, so every text chat forwards the input_ids SGLang would build, and chats without tools are served through the engine's /generate. Follows #43000.

Modifications

  • Render (render/models/glm53.rs): picked by the template, as _is_glm53 does. It builds the template context SGLang's Jinja path builds (Pydantic dumps of messages, history tool calls and tools, _validate_request's schema-type rewrite, kwargs over effort and server defaults) and renders it with Dynamo's Jinja formatter.
  • Left to the engine: media, a chat_template kwarg, -0, and U+001C..U+001F in assistant content (until fix(renderer): strip and split with Python's whitespace in HF templates ai-dynamo/frontend-crates#395). Kwargs SGLang rejects (apply_chat_template's own arguments, invalid documents) are rejected here too.
  • /generate: ports the glm45 reasoning parser, adds ChatModel.always_thinks, and accepts assistant thinking and tool_reference parts. With glm47, chats with tools stay on the engine's route, still with router input_ids. /generate must accept ebnf_full_assistant before tool requests can go through the /generate path; SGLang constrains them with a grammar flagged that way.
  • Also:
    • dynamo-renderer 7.0.1 → 7.1.1, for Python floats in tojson.
    • The schema-type rewrite also fixes DeepSeek-V4/V4.1.
    • The fixture generators run _validate_request and load a Jinja checkpoint's TemplateManager.
    • The processor-model-parity skill now states the goal: all text works, and chat and completions go through /generate.

Checks

  • Render: 112 cases per checkpoint (GLM-5.3@aca966e, GLM-5.3-Flash@eb9eb20), generated with transformers 5.19.0. Each matches SGLang's prompt text and token ids or is rejected as SGLang rejects it, except 3 known gaps left to the engine. The DeepSeek fixtures still pass with token ids.
  • OpenAI layer: openai_parity/glm-5.3.json (SGLang's handler on hand-written GLM outputs) and reasoning_parity/glm45.json.
  • Real weights: GLM-5.3-Flash on 8×B300 with the cookbook's FP8 low-latency recipe and the real router:
    • /generate: 20 chats. The engine logged the same GenerateReqInput for each as when sent directly, and the responses are identical, except two cases that vary between direct runs too (sampling, a 9.8k-token prompt).
    • Engine route: 6 chats with tools; the responses are identical.
    • Also identical: the image chat and the completion.
  • cargo test, clippy -D warnings and the pre-commit hooks pass.

CI States

Latest PR Test (Base): 🚫 Run #38364917377
Latest PR Test (Extra): ❌ Run #38364916866
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 added router run-ci CI: run the baseline test suite on this PR labels Oct 11, 2026
sglang-processor renders GLM-5.3 (ChatFormatter::Glm53) as SGLang's Jinja
path does: picked by its template like template_detection._is_glm53, with
the template context _process_messages and _apply_jinja_template build,
rendered by Dynamo's Jinja formatter. Media, a chat_template kwarg,
apply_chat_template's own arguments as kwargs, and numbers serde_json prints
unlike Python are left to the engine.

sgl-router renders GLM-5.3 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]>
sherlockwu and others added 2 commits October 11, 2026 23:43
- Reserved template kwargs (apply_chat_template's own arguments) are checked
  after the server's defaults merge in, so a default chat_template or
  tokenize no longer renders a prompt SGLang would not.
- History tool calls are dumped to ToolCall's fields, as Pydantic does; GLM's
  template reads tool_call_id before id when it pairs results with calls.
- Tool schemas get _validate_request's in-place type normalization (varchar
  becomes string), for DeepSeek-V4 and V4.1 too. generate_parity.py now runs
  _validate_request, so fixtures see it.
- dynamo-renderer 7.1.1 prints floats in tojson as Python does
  (ai-dynamo/frontend-crates#368), so only -0, which serde_json reads as -0.0,
  is left to the engine; the float known gaps are dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the cookbook's glm45 reasoning parser the router now serves GLM-5.3 chats
through the engine's /generate: think/ ports glm45 (Glm45Detector), and
ChatModel.always_thinks carries template_detection's always-on reasoning for
GLM-5.3's template, which require_reasoning and the reasoning split read.
Lowering also accepts assistant thinking parts and tool_reference parts.

A chat with tools under glm47 keeps the engine's own route, with the router's
input_ids: SGLang constrains it with a grammar flagged ebnf_full_assistant,
which /generate's API (proto/sglang/api/v1/sampling.proto) does not accept.

openai_parity/glm-5.3.json records SGLang's handler on hand-written GLM-5.3
outputs; generate_openai_parity.py loads a Jinja checkpoint's TemplateManager.
The processor-model-parity skill states the goal: every text request works,
and chat and completions go through /generate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Oct 11, 2026
…o the engine

- The template strips assistant content. Python's str.strip also strips
  U+001C..U+001F, the only characters Python counts as whitespace and Rust
  does not; minijinja's strip keeps them, so such content renders on the engine.
- apply_chat_template iterates a documents kwarg and rejects a non-dict item,
  so documents that are not a list of objects (or an empty string or object)
  are rejected, as SGLang rejects them, instead of rendering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sherlockwu and others added 4 commits October 12, 2026 05:39
…hanged

generate_openai_parity.py records always_thinks only when it is set, so the
DeepSeek OpenAI fixtures stay as on main. The U+001C..U+001F workaround names
its retirement condition, ai-dynamo/frontend-crates#395.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The base <think> splitter and the generic OpenAI layer are covered by the
DeepSeek fixtures, so glm45's reasoning cases cover the tool-call boundary
and the GLM-5.3 OpenAI cases cover the reasoning split, continuation, and
lowering (lower_only), plus the requests that stay on the engine's route.

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

The generator's stub reports every checkpoint as text-only, so a media case
records SGLang's text-only rejection even for multimodal checkpoints
(DeepSeek-V4.1-Flash, GLM-5.3-Flash). That matches the processor's policy:
render_request fails on media parts and hosts leave those chats to the engine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The processor's ported `glm45` detector needs the reasoning state the
template sets, as Python's does; Dynamo's parser, which the server used
before, split an output without an opening `<think>` on its own. GLM-5.3
prefills `<think>`, so the server forces it as it already did for
DeepSeek-V4 when the prompt ends in `<think>`.

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

@ShangmingCai ShangmingCai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ShangmingCai
ShangmingCai merged commit 4560da5 into main Oct 14, 2026
135 of 145 checks passed
@ShangmingCai
ShangmingCai deleted the kan/sgl-router-glm53 branch October 14, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation router 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