Skip to content

chore: request handler fix for sglang + deepseekv4 end to end + sglang chat processor fix for deepseek v4 tool calling - #8701

Merged
dmitry-tokarev-nv merged 2 commits into
codex/deepseek-v4-parsersfrom
rihuo/run_deepseek_v4
Apr 24, 2026
Merged

chore: request handler fix for sglang + deepseekv4 end to end + sglang chat processor fix for deepseek v4 tool calling #8701
dmitry-tokarev-nv merged 2 commits into
codex/deepseek-v4-parsersfrom
rihuo/run_deepseek_v4

Conversation

@richardhuo-nv

@richardhuo-nv richardhuo-nv commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Make SGLang-backed Dynamo run DeepSeek-V4 end-to-end. Two fixes:

  • Decode handler crash on older SGLang builds: DecodeWorkerHandler passes return_routed_experts unconditionally to Engine.async_generate, which fails on SGLang builds that don't have the kwarg yet.
  • DeepSeek-V4 prompt rendering: DS-V4 ships without an HF chat template, so the existing tokenizer.apply_chat_template path produces wrong prompts for tool calls and thinking mode. DS-V4 needs SGLang's custom encoding_dsv4.encode_messages.

Changes

components/src/dynamo/sglang/_compat.py

  • ensure_sglang_top_level_exports() — restores sgl.Engine / sgl.ServerArgs on SGLang 0.5.x snapshots that don't re-export them.
  • filter_supported_async_generate_kwargs(engine, kwargs) — inspects Engine.async_generate signature (cached) and drops kwargs the installed engine can't accept; **kwargs signatures pass through unchanged.

components/src/dynamo/sglang/request_handlers/llm/decode_handler.py

  • Route return_routed_experts through the filter at both prefill and decode async_generate call sites.

components/src/dynamo/frontend/sglang_prepost.py

  • Detect DeepSeek-V4 by model/parser name when the tokenizer has no chat_template, and render via sglang.srt.entrypoints.openai.encoding_dsv4.encode_messages.
  • Thinking mode derives from chat_template_kwargs.thinking; reasoning_effort is clamped to {max, high, None}.
  • Tool filtering (handles tool_choice="none" and named tool choice) extracted into _filter_template_tools so both paths share it.
  • Version-safe wrapper for SGLang's get_json_schema_constraint / parser.get_structure_constraint, which gained parallel_tool_calls in a later release.

components/src/dynamo/sglang/publisher.py

  • Add from __future__ import annotations.

Tests

  • components/src/dynamo/frontend/tests/test_sglang_processor_unit.py (+316): DS-V4 detection, tool filtering, thinking / reasoning-effort, parallel-tool-calls wrapper.
  • components/src/dynamo/sglang/tests/test_sglang_unit.py (+98): async_generate kwarg filter.

Notes for reviewers

  • Base branch is codex/deepseek-v4-parsers, not main — confirm merge order so this doesn't land orphaned.
  • DS-V4 path raises ValueError at request time if the SGLang build lacks encoding_dsv4. Runtime-visible, not at startup — acceptable for now, flag if we'd rather fail fast at worker init.
  • DS-V4 detection triggers when tokenizer.chat_template is None AND any of model / tool-call-parser / reasoning-parser normalizes to contain deepseekv4.

Test plan

  • New unit tests pass (test_sglang_processor_unit.py, test_sglang_unit.py).
  • E2E DS-V4 checkpoint with tool calling: named tool_choice, tool_choice="none", and parallel calls.
  • Run against an SGLang build with return_routed_experts support and one without — confirm no crash in either case.

Where should the reviewer start?

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • closes GitHub issue: #xxx

Open in Devin Review

fix

fix

fix

fix

fix
@richardhuo-nv
richardhuo-nv requested review from a team as code owners April 24, 2026 20:57
@github-actions github-actions Bot added chore backend::sglang Relates to the sglang backend frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` labels Apr 24, 2026
@dmitry-tokarev-nv
dmitry-tokarev-nv merged commit d116e2a into codex/deepseek-v4-parsers Apr 24, 2026
71 of 73 checks passed
@dmitry-tokarev-nv
dmitry-tokarev-nv deleted the rihuo/run_deepseek_v4 branch April 24, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend::sglang Relates to the sglang backend chore frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants