Fix zero expert routed ids for MoE backends (#30387)

This commit is contained in:
Xiaoyu Zhang
2026-07-08 21:23:25 +08:00
committed by GitHub
parent 108a183f6b
commit b8ca06fdad
2 changed files with 69 additions and 1 deletions
@@ -1307,7 +1307,9 @@ def zero_experts_compute_triton(
zero_expert_scales[zero_expert_mask] = 0.0
normal_expert_mask = expert_indices >= num_experts
expert_indices[normal_expert_mask] = -1
# Keep a valid routed-expert id for MoE kernels that do not accept negative
# ids. The zero scale below still removes the routed-expert contribution.
expert_indices[normal_expert_mask] = 0
expert_scales[normal_expert_mask] = 0.0
output = torch.zeros_like(hidden_states).to(hidden_states.device)