Skip to content

[misc] Fix tool-call index, graph padded-row count, and prefill-graph input_embeds refresh - #39574

Merged
hnyls2002 merged 12 commits into
mainfrom
lsyin/misc-runner-moe-fixes
Sep 15, 2026
Merged

hnyls2002 merged 12 commits into
mainfrom
lsyin/misc-runner-moe-fixes

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Five independent fixes in the OpenAI chat server, the CUDA graph runners, and the MoE runners. Each is one or two commits and stands on its own.

Changes

1. Non-streaming tool_calls[i].index is the call ordinal.
_process_tool_calls numbered calls by the detector's tool_index, which for most detectors is the tool's position in the request. Two calls to the same tool therefore both got index=0, while the streaming deltas number them 0 and 1. The non-streaming path now enumerates the parsed calls. Regression test added in test_serving_chat.py.

2. num_token_non_padded is only handed out when it is maintained.
The decode graph runner allocated the num_token_non_padded slot unconditionally, wrote it at capture, and refreshed it at replay only under expert parallelism. Without EP the static ForwardBatch carried a stale capture-time count, while eager batches carry None (ForwardBatch.init_new only fills it under EP). DecodeInputBuffers.create and the dummy-run buffers now allocate the slot only when enable_num_token_non_padded(); the capture-time writes are guarded. Graph and eager batches now follow the same rule: no count unless it is live.

3. The standard MoE path masks padded rows like the a2a path.
DeepseekV2MoE.forward_normal and forward_normal_dual_stream pass forward_batch.num_token_non_padded into top-k, as forward_deepep already does. With EP and the standard dispatcher, padded rows of a CUDA graph batch are now routed to expert id -1 instead of real experts, which also keeps them out of the expert-distribution statistics. Without EP the count is None and routing is unchanged. The dual-stream variant is additionally skipped inside a breakable CUDA graph capture, matching the guard the hc path already has.

4. Prefill CUDA graph replay refreshes the input_embeds slot from input_ids.
When the outer forward calls the captured stack without input_embeds, the replay closure previously left the slot untouched and the graph read the previous batch's embeddings. It now computes them from input_ids via get_input_embeddings().

5. Deferred finalize accepts fp32 expert weights.
FlashInfer >= 0.6.18 types the do_finalize=False weight buffer by content: bf16 for packed routing, the caller's dtype for unpacked routing. The fp32 -> bf16 bit reinterpretation in _make_deferred_finalize_output was only correct for older versions and would corrupt genuine fp32 weights; moe_finalize_fuse_shared already accepts both dtypes.

Also drops the unused ngram_embedding_n/k attributes from the decode graph runner.

Behavior on existing models

  • EP off: MoE routing is bitwise unchanged; the count is None on eager and graph batches alike.
  • EP on with the standard dispatcher: padded rows in CUDA graphs are skipped instead of routed.
  • tool_calls[i].index in non-streaming responses changes for detectors whose tool_index is the tool position, only when several calls appear in one response.

Verification

  • test_serving_chat.py, test/registered/unit/model_executor, test/registered/unit/batch_overlap, the dp-attention, LoRA MoE and EPLB unit tests: pass.
  • Kimi-VL-A3B test_vision_openai_server_a.py (mixed image/text batch, decode CUDA graph, EP off): an earlier revision of this branch crashed with an illegal memory access in the fused MoE kernel because the graph ForwardBatch still carried the stale count; the current head passes, with outputs identical to main. The mixed-batch client was replayed six times.
  • CI on the current head: /rerun-test of test_vision_openai_server_a.py passed (run), and of test_serving_chat.py, test_prefill_cuda_graph_runner.py, test_num_token_non_padded_localization.py passed (run). The full PR Test (Base) run for this head is linked below; the AMD, MLX and NPU lanes currently fail on other open PRs as well.

CI States

Latest PR Test (Base): 🚫 Run #35024279368
Latest PR Test (Extra): ❌ Run #35024279247
Latest PR Test (AMD ROCm 10): 🚫 Run #35024279469

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Sep 15, 2026
@hnyls2002

hnyls2002 commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_vision_openai_server_a.py test_serving_chat.py test_prefill_cuda_graph_runner.py test_num_token_non_padded_localization.py

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_vision_openai_server_a.py test_serving_chat.py test_prefill_cuda_graph_runner.py test_num_token_non_padded_localization.py:

🚀 1-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/vlm/test_vision_openai_server_a.py

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/entrypoints/openai/test_serving_chat.py
cd test/ && python3 registered/unit/model_executor/test_prefill_cuda_graph_runner.py
cd test/ && python3 registered/unit/model_executor/test_num_token_non_padded_localization.py

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_vision_openai_server_a.py test_serving_chat.py test_prefill_cuda_graph_runner.py test_num_token_non_padded_localization.py:

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/vlm/test_vision_openai_server_a.py

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/entrypoints/openai/test_serving_chat.py
cd test/ && python3 registered/unit/model_executor/test_prefill_cuda_graph_runner.py
cd test/ && python3 registered/unit/model_executor/test_num_token_non_padded_localization.py

@hnyls2002
hnyls2002 merged commit 0dabef3 into main Sep 15, 2026
168 of 190 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/misc-runner-moe-fixes branch September 15, 2026 23:37
alisonshao added a commit that referenced this pull request Sep 21, 2026
#39574 started passing forward_batch.num_token_non_padded into the
non-a2a MoE path. That value is the current DP rank's own token count,
but with DP attention the MoE runs over the DP-gathered buffer spanning
every DP rank, so the mask truncates it and each rank sums a differently
truncated partial output.

Only pass the count when attn_dp_size == 1.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…cks, chronologisch)

Grundlage: Präsenz-Scan aller 230 27B-Commits seit 76f8deb gegen diesen Baum
(Stichprobe der hinzugefügten Zeilen je Commit); die 94 fehlenden minus die bewusst
anders gewählten Formen (76e87ac/4ae11ababd -> S3 form.calibration_identity;
479f6ec/d7f588e017/d0fba8955f/34892e3017 -> S2 NF-Formen; 7f81f09/3c14481318 ->
S4/S7a; 3dbb790 line_gate_27b (Werkzeug, Schritt 9); 8604d13 W100-by-name
(Nutzer: bleibt aus); 6545e2c flashinfer-Pin in pyproject (Image-Frage, nicht Baum)).
Liste: 92bbccb eb5d044 829ebd0 431fcbc ef4d11f 6816062 a233e50 2cc593c f0c8451 87cc4fb c529777 31f2dbe c50085a 3301a96 036b368 e1d1fe9 03c68af 6dddc2e 06932b5 87389c4 58a7490 f85ac55 fc64aa5 5aa24dd 97c0e9a 159333c d9f1532 f3c685b 8550655 e50fb59 db2c2ef f09dc0d c255e10 51b810e 28a55a2 34965fc ff3d9cc 340a018 bee5e10 67b6352 fdade85 ed6630d f1c9a43 b434831 517f26d 0b6b60b a40837f 644de86 aff2b7c 197b701 856024b 238512a 9738626 b857a22 1f8c24d d294b3e 810239d b429dfd e714c95 9efd974 3d63e0a d3cfcf3 fee6134 7985b56 49a14e9 fc45706 19c720e 5306bee 6f1235a c98eaa3 93bc802 328349e f9fb3a2 572af73 94fa8b4 d342caa 2fd7d7e 3ebbb96 871d55f 78c2f16 3babf51 196f6a8 e70af54 22eccfc

Inhalt: Upstream-Ports (sgl-project#33758 sgl-project#37818 sgl-project#36738 sgl-project#33459/sgl-project#30096 sgl-project#34446 sgl-project#36267 sgl-project#33778 sgl-project#34859
sgl-project#36415 sgl-project#35255/sgl-project#36638 sgl-project#39858/sgl-project#40259 sgl-project#31417 sgl-project#34892 sgl-project#32225 sgl-project#30832/sgl-project#36626 sgl-project#39574 sgl-project#29579
sgl-project#31468 sgl-project#32575 sgl-project#31648); xsn409/410-Wake-Verdikte; Vision-Linie V1-V3b + xsn438
(SGLANG_WEG2_VISION_FLIP_URGENT); D-Planer L6 (159333c); DFLASH-Window-Pool
sync-frei, PLAN_SYNC_FREE, D-Kollektive (vocab-argmax, a2a-Merge, deferred rebuild),
#DGAP/D_DEFER_SEQ_LENS_CPU; Mamba-Anker Raster 4096 + Per-Path-Cap + Inner-Release;
P-TRIM (--p-trim-end-anchor); FP8 uniform Marlin; ModelOpt/NVFP4 RadixArk; GGUF G1-G6
+ F1/F2; native-mixed sgl-project#38 (sm_8x W4A8, sm_12x CUTLASS/W4A16); RC1-Capture-Set; sgl-project#49
Agent-Turns; dynchunk (--p-chunk-policy, --p-chunk-dynamic-min-tokens).

Auflösungen (Gabel -> Form, Grund):
- L6 d_operating_point_rows: 27B (d) "Token-Vektor auf jeder Position aus der Kapazität"
  nur bei TP-symmetrischem D (Profil d_layout paged_dcp); sonst NF-sgl-project#1293-Pin + NF-Anker-
  Klausel. mamba_ssm_dtype aus EARLY_READ_FACTS nur bei Profil early_read_flags.
  Overhead-Kalibrierung liest mit form.CalibrationIdentity statt LineIdentity.
- RC1 Capture-Set: neuer RecordKey-Term d_capture_set (qwen27b), Leser
  CalibrationIdentity.d_max_running_requests; nextflash unverändert.
- URC Carrier-Hold: 27B _weg2_carrier_hold entfällt (S2 NF-Rotation), Inner-Release und
  Per-Path-Cap bleiben (Env, Default aus; 27b.env setzt sie).
- scheduler_pp_mixin/overlap_utils/batch_result_processor: NF H49/H58 und 27B #PGAP/#DGAP
  komponiert (beide Instrumente getrennt schaltbar).
- schedule_policy: P-TRIM-Kurzschluss vor NF H63-Fold/QSA-Korn; sgl-project#36415 Hoist + NF
  computed_input_len.
- gdn_backend sgl-project#33778: 27B-strided-Verify; NF-Ring flacht beide Layouts ab.
- flashinfer_backend: RC9-Datei + NF-Form-A-Waiver (27B-intern mehrfach gegabelt).
- checkpoint_census: GGUF-Leser + NF exclude_segments (PLE) in einer Aggregation.
- xchg_manifest: FLAT_SEGMENTS in beiden (dst/src) NF-Breitenbedingungen ausgenommen.
- vram_peak_window: NF-Kumulativ-Peak liest über den 27B-Fast-Read.
- FP8: 8c86eb8-Rest nachgezogen (private Workspace-Registry entfernt, wie RC9).
- argv_d: vision= an allen drei Aufrufstellen (inkl. NF --d-only).
- census_checkpoint_decision (W161) jetzt für beide Profile aktiv.

Gates: py_compile aller geänderten Dateien; ruff F821/F811 ohne neue Funde gegenüber
dem Vorgänger (PendingSeqLensCpu ist String-Annotation wie in RC9); dup_defs_gate 0 neu.
Tests: 73 portierte Testdateien, Lauf nach dem Ruhefenster (Boot aktiv).
gokay-ai added a commit to gokay-ai/sglang that referenced this pull request Oct 20, 2026
Since sgl-project#39574, draft ForwardBatch.init_new treated missing input_ids as 0
tokens, so the MoE padded-region mask set every draft topk id to -1 and
the eager draft forward ran without routed experts.

Derive the draft token width from spec_info.num_tokens_per_req when
input_ids is None. The StandardDispatcher half of the original fix is
superseded by sgl-project#40498, which already preserves the -1 sentinel.

Fixes sgl-project#40156

Signed-off-by: GokayAI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail deepseek high priority run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant