[DeepSeek V4] Fix fused MoE expert distribution (#57465)

Signed-off-by: Itay Alroy <ialroy@nvidia.com>
Co-authored-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
This commit is contained in:
Itay Alroy
2026-09-18 15:17:07 +00:00
committed by GitHub
co-authored by Tyler Michael Smith
parent dbf4b89cf2
commit 017dced6a6
+5 -7
View File
@@ -993,20 +993,18 @@ class DeepseekV4MoE(nn.Module):
prefix: str,
) -> None:
parallel_config = vllm_config.parallel_config
self.tp_rank = get_tensor_model_parallel_rank()
ep_group = get_ep_group()
ep_size = ep_group.world_size
ep_rank = ep_group.rank_in_group
eplb_config = parallel_config.eplb_config
self.n_redundant_experts = eplb_config.num_redundant_experts
self.n_shared_experts = config.n_shared_experts or 0
self.n_logical_experts = self.n_routed_experts
self.n_physical_experts = self.n_logical_experts + self.n_redundant_experts
assert self.n_physical_experts % self.tp_size == 0, (
f"n_physical_experts={self.n_physical_experts} must be divisible by "
f"tp_size={self.tp_size}. Adjust num_redundant_experts."
)
self.n_local_physical_experts = self.n_physical_experts // self.tp_size
self.n_local_physical_experts = self.n_physical_experts // ep_size
self.n_local_experts = self.n_local_physical_experts
self.experts_start_idx = self.tp_rank * self.n_local_experts
self.experts_start_idx = ep_rank * self.n_local_experts
self.experts_end_idx = self.experts_start_idx + self.n_local_experts
self.physical_expert_start = self.experts_start_idx
self.physical_expert_end = self.experts_end_idx