@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 1b769dccf3
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, 23:45 UTC

[Bugfix] Fix Ernie4_5_MoeForCausalLM shared experts (#21717)

Signed-off-by: Jee Jee Li <pandaleefree@gmail.com>

Jee Jee Li committed Jul 28, 2025 at 19:02 UTC 1b769dccf335efe666246094f6c99221a2c13c66
1 file changed +6 -5
vllm/model_executor/models/ernie45_moe.py
+6 -5
@@ -109,8 +109,8 @@ class Ernie4_5_MoeMoE(nn.Module):
109 layer_idx = extract_layer_index(prefix)
110 self.layer_idx = layer_idx
111 self.tp_size = get_tensor_model_parallel_world_size()
112 - self.moe_num_shared_experts = getattr(config, "moe_num_shared_experts",
113 - None)
112 + self.has_shared_experts = (getattr(config, "moe_num_shared_experts", 0)
113 + > 0)
114
115 if self.tp_size > config.moe_num_experts:
116 raise ValueError(
@@ -137,7 +137,7 @@ class Ernie4_5_MoeMoE(nn.Module):
137 prefix=f"{prefix}.experts",
138 e_score_correction_bias=self.gate.e_score_correction_bias)
139
140 - if self.moe_num_shared_experts is not None:
140 + if self.has_shared_experts:
141 intermediate_size = (config.moe_intermediate_size *
142 config.moe_num_shared_experts)
143 self.shared_experts = Ernie4_5_MoeMLP(
@@ -153,7 +153,8 @@ class Ernie4_5_MoeMoE(nn.Module):
153 orig_shape = hidden_states.shape
154 hidden_dim = hidden_states.shape[-1]
155 hidden_states = hidden_states.view(-1, hidden_dim)
156 - if self.moe_num_shared_experts is not None:
156 + shared_output = None
157 + if self.has_shared_experts:
158 shared_output = self.shared_experts(hidden_states)
159
160 router_logits, _ = self.gate(hidden_states)
@@ -161,7 +162,7 @@ class Ernie4_5_MoeMoE(nn.Module):
162 final_hidden_states = self.experts(hidden_states=hidden_states,
163 router_logits=router_logits)
164
164 - if self.moe_num_shared_experts is not None and \
165 + if self.has_shared_experts and \
166 shared_output is not None:
167 final_hidden_states = final_hidden_states + shared_output
168