Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions vllm/models/deepseek_v4/nvidia/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,20 +993,22 @@ def _init_fused_moe_experts(
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, (
assert self.n_physical_experts % ep_size == 0, (
f"n_physical_experts={self.n_physical_experts} must be divisible by "
f"tp_size={self.tp_size}. Adjust num_redundant_experts."
f"ep_size={ep_size}. Adjust num_redundant_experts."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually too strict - we don't require divisibility for ep_size... at least not in all cases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked a few other FusedMoE models (including DSV2/V3). They also calculate the number of local physical experts as num_physical_experts // ep_size, they just do not assert divisibility. I aligned DeepSeek V4 with them. Currently this is only read by EPLB, but I wonder if we should make a broader change to account for uneven distribution across all models.

)
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
Expand Down
Loading