@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 342c58bc54
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 4, 18:45 UTC

[BugFix]fix Qwen3 MoE call gate twice (#40664)

Signed-off-by: Kunshang Ji <kunshang.ji@intel.com>

Kunshang Ji committed Apr 23, 2026 at 13:04 UTC 342c58bc548f6dd38c1039fdc1c5af014ee9a268
1 file changed +13 -5
vllm/model_executor/models/qwen3_moe.py
+13 -5
@@ -231,11 +231,19 @@ class Qwen3MoeSparseMoeBlock(nn.Module):
231 if self.is_sequence_parallel:
232 hidden_states = sequence_parallel_chunk(hidden_states)
233
234 - # router_logits: (num_tokens, n_experts)
235 - router_logits, _ = self.gate(hidden_states)
236 - final_hidden_states = self.experts(
237 - hidden_states=hidden_states, router_logits=router_logits
238 - )
234 + if self.experts.is_internal_router:
235 + # In this case, the gate/router runs inside the FusedMoE class
236 + final_hidden_states = self.experts(
237 + hidden_states=hidden_states, router_logits=hidden_states
238 + )
239 + else:
240 + # Actually this will be dead code, since we always pass gate into
241 + # FusedMoE in the current implementation. But we keep this code
242 + # here for clarity and future flexibility.
243 + router_logits, _ = self.gate(hidden_states)
244 + final_hidden_states = self.experts(
245 + hidden_states=hidden_states, router_logits=router_logits
246 + )
247
248 if self.is_sequence_parallel:
249 final_hidden_states = tensor_model_parallel_all_gather(