@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 8df98c2161
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 14, 04:15 UTC

[perf] Enable concurrent execution of "shared_experts" and "selected_experts" in qwen3-next (#27578)

Signed-off-by: zjy0516 <riverclouds.zhu@qq.com>

Jiangyun Zhu committed Oct 29, 2025 at 16:12 UTC 8df98c2161e28387391b667201f8458c2bdf29f4
1 file changed +12 -5
vllm/model_executor/models/qwen3_next.py
+12 -5
@@ -159,6 +159,7 @@ class Qwen3NextSparseMoeBlock(nn.Module):
159
160 self.experts = SharedFusedMoE(
161 shared_experts=self.shared_expert,
162 + gate=self.gate,
163 num_experts=self.n_routed_experts,
164 top_k=config.num_experts_per_tok,
165 hidden_size=config.hidden_size,
@@ -181,11 +182,17 @@ class Qwen3NextSparseMoeBlock(nn.Module):
182 if self.is_sequence_parallel:
183 hidden_states = sequence_parallel_chunk(hidden_states)
184
184 - # router_logits: (num_tokens, n_experts)
185 - router_logits, _ = self.gate(hidden_states)
186 - final_hidden_states = self.experts(
187 - hidden_states=hidden_states, router_logits=router_logits
188 - )
185 + if self.experts.is_internal_router:
186 + # In this case, the gate/router runs inside the FusedMoE class
187 + final_hidden_states = self.experts(
188 + hidden_states=hidden_states, router_logits=hidden_states
189 + )
190 + else:
191 + # router_logits: (num_tokens, n_experts)
192 + router_logits, _ = self.gate(hidden_states)
193 + final_hidden_states = self.experts(
194 + hidden_states=hidden_states, router_logits=router_logits
195 + )
196
197 if self.shared_expert is not None:
198 final_hidden_states = final_hidden_states[0] + final_hidden_states[1]