Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a state assignment in the disaggregation connection and casts top-k IDs to int32 in the Mega MoE layer for better type consistency. Feedback suggests also casting top-k weights to float32 to ensure compatibility with JIT-compiled kernels and consistency with the empty-token branch.
There was a problem hiding this comment.
disaggregation fake backend modification LGTM
There was a problem hiding this comment.
Thanks for the review! I just squashed the commits into one and force-pushed, so the previous approval got cleared. Could you re-approve when you get a chance? No code changes, just a clean single commit now.
There was a problem hiding this comment.
Actually, I haven't approved yet since mega_moe part still requires a review from other reviewers. I am not an expert on mega moe, so you should ping other reviewers to check this fix, then we can run the CI.
There was a problem hiding this comment.
Thanks for the clarification! Got it.
66004ad to
78bc9a5
Compare
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
78bc9a5 to
5da4443
Compare
|
/rerun-test test_deepseek_v4_flash_fp4_megamoe_b200.py |
|
⛔ |
|
/rerun-test test_deepseek_v4_flash_fp4_megamoe_b200.py |
|
⛔ |
|
/rerun-test test_deepseek_v4_flash_fp4_megamoe_b200.py |
|
🚀 |
…g kv_args (#25380) Co-authored-by: JoeLee314 <liqichao@baidu.com>
…g kv_args (sgl-project#25380) Co-authored-by: JoeLee314 <liqichao@baidu.com>
Motivation
When serving DeepSeek-V4-Pro with MegaMoE enabled (
SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE=1) and disaggregation decode mode (--disaggregation-transfer-backend fake --ep-dispatch-algorithm fake), the server crashes during initialization with two independent errors:Bug 1 — dtype mismatch in
mega_moe_pre_dispatch:The
topk_output.topk_idsisint64with-ep-dispatch-algorithm fake, but the JIT-compiledmega_moe_pre_dispatchkernel only acceptsint32.Here is the analys:
--ep-dispatch-algorithmis not set,ExpertLocationDispatchInfo.init_new()returns None (expert_location_dispatch.py:50), sotopk_ids_logical_to_physical()returnstopk_idsas-is —int32is preserved.--ep-dispatch-algorithm fakeis set, it routes to_topk_ids_logical_to_physical_dynamic()(expert_location_dispatch.py:93), which does:topk_ids = info.partial_logical_to_all_physical_map[topk_ids, chosen_dispatch_index]partial_logical_to_all_physical_mapis created viatorch.tensor()without an explicit dtype, defaulting toint64(expert_location_dispatch.py:422). In PyTorch, tensor indexing result dtype follows the source tensor, not the index tensor — soint64_tensor[int32_idx]returnsint64, silently undoing the earlier.to(torch.int32)cast.int64topk_idsthen flows intomega_moe_pre_dispatchwhich only acceptsint32, triggering the TVM dtype check error.Bug 2 —
FakeKVManagermissingkv_argsattribute:FakeKVManagerinherits fromBaseKVManagerbut does not store theargsparameter asself.kv_args, unlikeCommonKVManager. The disaggregation decode event loop accessesself.kv_manager.kv_args.state_types, which crashes at runtime.Both bugs are hit when running:
SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE=1 \ SGLANG_OPT_FIX_HASH_MEGA_MOE=1 \ SGLANG_OPT_FIX_MEGA_MOE_MEMORY=1 \ SGLANG_OPT_FIX_NEXTN_MEGA_MOE=1 \ SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=8320 \ SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK=256 \ sglang serve \ --trust-remote-code \ --model-path DeepSeek-V4-Pro \ --tp 8 --dp 8 --enable-dp-attention \ --moe-a2a-backend deepep \ --disaggregation-mode decode \ --ep-dispatch-algorithm fake \ --disaggregation-transfer-backend fake \ --dist-init-addr 127.0.0.1:30435 \ --mem-fraction-static 0.85 \ --host 0.0.0.0 --port 30001Modifications
python/sglang/srt/layers/moe/mega_moe.py—_run_mega_routed:topk_idstoint32before passing tomega_moe_pre_dispatch, since the kernel only acceptsint32tensors. Theelsebranch already creates anint32empty tensor, so this makes the two branches consistent.The alternative would be fixing _topk_ids_logical_to_physical_dynamic() or the map dtype in expert_location_dispatch.py. However, casting at the MegaMoE entry point (mega_moe.py) is a more robust choice because:
python/sglang/srt/disaggregation/fake/conn.py—FakeKVManager.__init__:self.kv_args = args, matching the pattern already used inCommonKVManager. This is needed because the decode event loop accessesself.kv_manager.kv_args.state_typesduring preallocation.Accuracy Tests
Not applicable — the first fix is a dtype cast that preserves values (int64→int32 is safe since expert indices are small), and the second fix stores a reference that was already being accessed at runtime.
Speed Tests and Profiling
Not applicable — both fixes are one-line changes with no impact on the forward compute path. The
.to(torch.int32)cast is a no-op when the tensor is already on GPU and the values fit in int32.Verified that the server starts successfully and prints
The server is fired up and ready to roll!with the above command on 8× NVIDIA B200 GPUs.Checklist
CI States
Latest PR Test (Base): ❌ Missing
run-cilabel — add it to run CI tests.Latest PR Test (Extra): ❌ Blocked —
run-ciis required first.