Repository navigation
[Refactor] moe: Derive routing inputs from the layer and active forward - #44994
Merged
Merged
Conversation
ch-wan
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
JustinTong0323,
Qiaolin-Yu,
Ying1123,
fzyzcjy,
hnyls2002,
iforgetmyname,
ispobock,
kpham-sgl,
merrymercy,
mickqian,
ping1jing2,
pyc96,
whybeyoung,
xutizhou,
yhyang201 and
yuan-luo
as code owners
October 18, 2026 12:07
This was referenced Oct 18, 2026
ch-wan
changed the base branch from
cheng/refactor/moe-layer-backend-semantics
to
main
October 20, 2026 23:17
ch-wan
requested review from
1am9trash,
AgainstEntropy,
BowenBao,
Jiminator,
hubertlu-tw,
kevin-mii,
kkHuang-amd,
niehen6174 and
yichiche
as code owners
October 20, 2026 23:17
4 of 5 tasks
Jacob0226
added a commit
to Jacob0226/sglang
that referenced
this pull request
Oct 21, 2026
Follow sgl-project#44994: TopK derives num_token_non_padded and the expert-location dispatch info itself, so _gate_and_topk drops both and the one-launch router reads them from moe.topk.routing_inputs(). Co-authored-by: Cursor <[email protected]>
05yuki
added a commit
to 05yuki/deepseek-v4.1-flash-1017-ktransformers
that referenced
this pull request
Oct 21, 2026
…lts remeasured in one launch - SGLang main moves from ed0b8f43 to da7e3f1c (149 commits). Its TopK now resolves --init-expert-location for every router (sgl-project/sglang#44994), so the placement patch no longer remaps logical to physical ids in the KT wrapper: done twice, the output was garbage with no error. The patch keeps the routing dump only. prefill-lend and stream-prefill follow upstream's padded-query buffer, tail source and CUTLASS workspace changes. - serve.sh / lib/kt-lend-auto.sh: until a setup has fitted the prefill plan's cost, the plan uses a prior (KT_PREFILL_PLAN_COST_PRIOR, measured on two 16 GB cards). With a row-only cost, a new setup planned 13,312-row chunks at 1M and the indexer's scores ran out of memory. - Results, every row from one launch at the new tag: decode Japanese prose 45.1, code 33.8, math 37.6 tok/s; prefill 35K 758, 1M 579 tok/s. The previous README took the 131K-1M rows from an earlier launch. - Checked: tool calls 5/5, an 11.8K-token document summarised correctly, paired NLL 3.1489, no out-of-memory up to 1M. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01C2UBZdnrDZSBh8yQz8rc9g
This was referenced Oct 22, 2026
4 of 5 tasks
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was part of a stack (oldest at bottom):
Motivation
Model forwards can omit expert placement or the live token count, routing logical IDs against physical expert weights or processing padding as real tokens. Move those decisions into TopK and the active forward. Automatic padding also makes inactive routes reachable at EP1, so every affected consumer must skip their data, weights and expert addresses safely.
Modifications
sglang-kernel==0.4.10GGUF provider with Python block-size selection, safe vector indices, masked inactive intermediates/contributions, and initialized MMQ slack metadata. Retain the AOT source fixes for future wheel builds..zero_()call; set its CI runtime estimate to 720 seconds to cover cold compilation.CI repairs and validation
Current head:
2447ebc8cd21ba19ceb5f94c67826d30ff4aeaa0; base #44993 is4275a5026050615139c3658a72b6a7d05d65b17f. Updated by normal fast-forward pushes.Two latest repairs:
ForwardMetadata, while CK still received the backend's stale prompt table. Measured Q had 80 rows but the passed offsets reached 4,648, immediately followed by the GPU memory fault. Publish ordinary prefill offsets into the same metadata owner and consume that owner's view in CK, ASM and 5D prefill. Kernel selection, KV padding and speculative helpers are unchanged. #40872 describes the same defect with a producer-side repair; this patch keeps the existing per-forward owner authoritative at consumers.AMD before/after: the unchanged EAGLE canary failed with a memory fault on both this stack and its original main base. After repair, all 20 requests and original assertions passed (50.6s process). A second serialized observation run passed too: CK received
[0,4,...,80], all 588 eager CK calls returned, and no malformed query CSR or HSA fault was observed. Decode graphs and all test assertions remained enabled as configured. Hardware: one AMD MI350X; original CI used MI300. Torch 2.11.0+rocm10.0.0, Triton 3.8.0, AITER 2bb549102, CK 96afae1d5. NHD/BF16 is exercised; the corresponding 5D/FP8/ASM corrections have source review coverage. Final source differs from the tested repair only by removing a stale comment. Independent source review and configured pre-commit checks passed.H200 fixture runtime: Torch 2.13.0+cu130, Triton 3.7.1, sglang-kernel 0.4.7, FlashInfer 0.6.18. This is single-GPU routing validation, not eight-GPU collective or full-model validation.
Other failures in the latest CI run:
Earlier CI-only repairs at
0a3e1cfa68remain included: inherited DeepSeek dual-stream fixture correction from #44993, current activation import, Bailing NextN/V3 parity ownership, and Python 3.11 wheel selection in the simulator job. Their recorded validation was 54 quantization tests, 85 kernel namespace tests, the complete DeepSeek opcheck/compile/graph-replay test at both production revisions, two parity tests, 49 fusion-gate tests plus 11 subtests, and artifact-name matching. Those checks were not rerun for these bounded changes. Full CI and full-model acceptance remain pending; earlier validation below stays tied to its named revisions.Earlier validation after rebase
Head:
5a0a941ff3013d5c98cff1a5854d03bebff7324c. Rebased onto main553836c1647b3bfbeb266b49d76ec2c9df012425; basecheng/refactor/moe-layer-backend-semanticsisfc2dd3d90bf86fe1b61741c1bb8d28a4e121dc8a.GPU, full-model accuracy/throughput and full CI were not rerun for this rebase. Prior hardware measurements below remain evidence for their named earlier revisions; checked CUTLASS/Marlin/GGUF consumer sources are unchanged, which is source evidence rather than a new GPU run.
Previous validation (before rebase)
Previous head:
068e12b7c155babfdc6eea074812b12c7830a3df, including #44993 atb37b73a1ae1bdf3d73b6108deb76a14679a079b4, all lower PRs, and main693d33330647c57f82e09ac39a34122fa46b5763.sglang-kernel 0.4.10. Incompatible FlashInfer 0.7.1 cubin/cache packages were ignored; kernels compiled as needed.Earlier validation at the preceding heads remains historical: 856 CPU tests across 43 modules with 7 skips, 18 native Marlin cases, 2 prior CUTLASS FP8 methods and 4 GGUF cases against the published 0.4.10 wheel. The new focused CPU and 3-method CUTLASS runs above replace the corresponding coverage for this revision; the Marlin/GGUF kernels are unchanged this round.
The earlier reduced Qwen3 TP4/EP4 reverse-placement graph smoke matched 72 generated IDs and logprobs at its recorded revision; it was not rerun as full-model validation here. No new all-valid reduction latency, dropped-block scan cost or serving throughput measurement is claimed. Native TRT-LLM selector parity, full-model accuracy, ROCm/NPU/AMX and external FlashInfer/HPC/KT consumer coverage remain unverified. Full CI has not been established for this head.
Main integration for merge
Current head:
ad06555c737b78c7767cba9b51e0c2ba6305b8ed. Integrated main at533020b500ba781bfafd1f5cbadabaf03d8986f7with a history-preserving merge.Retained TopK's ownership of per-call routing inputs, combined draft identity placement with main's explicit
uses_expert_locationAPI, preserved main's gfx1250 expert-parallel support, and reconciled the dispatcher and MegaMoE fixtures. Removed an automatically restored Qwen3 model-side dispatch input; the model routing audit found no remaining legacy inputs across 297 model files.Independent static review and the normal configured pre-commit hooks passed for these integration changes. Unit/GPU tests and CI were not rerun for this landing; earlier results remain tied to their stated revisions. The two reviewed Muse/W4A8 allocation costs will be repaired in a separate follow-up PR.
CI States
Latest PR Test (Base): 🚫 Run #39514945471
Latest PR Test (Extra): 🚫 Run #39514945509
Latest PR Test (AMD ROCm 10): 🚫 Run #39514945468