From 9db58ab547516435b544ae050dd6c2f91b52bcf3 Mon Sep 17 00:00:00 2001 From: Sihan Chen <757407490@qq.com> Date: Tue, 20 Oct 2026 18:00:39 +0800 Subject: [PATCH] [Fix] eplb: Fix Qwen3 MoE output corruption after EPLB rebalance (#39580) Signed-off-by: Spycsh --- python/sglang/srt/models/qwen3_moe.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/models/qwen3_moe.py b/python/sglang/srt/models/qwen3_moe.py index 5cb3b37161..7d35ab6fc5 100644 --- a/python/sglang/srt/models/qwen3_moe.py +++ b/python/sglang/srt/models/qwen3_moe.py @@ -338,10 +338,20 @@ class Qwen3MoeSparseMoeBlock(nn.Module): num_tokens, hidden_dim = hidden_states.shape hidden_states = hidden_states.view(-1, hidden_dim) + dispatch_info = ( + ExpertLocationDispatchInfo.init_new(layer_id=self.layer_id) + if get_exec().moe.enable_eplb + else None + ) + if hidden_states.shape[0] > 0: # router_logits: (num_tokens, n_experts) router_logits, _ = self.gate(hidden_states) - topk_output = self.topk(hidden_states, router_logits) + topk_output = self.topk( + hidden_states, + router_logits, + expert_location_dispatch_info=dispatch_info, + ) else: topk_output = self.topk.empty_topk_output(hidden_states.device) final_hidden_states = self.experts(hidden_states, topk_output)