已开启
[Bug] MoE _compute_load_balance_loss may become constant and ignore routing distribution #95
lishanni创建于 4月20日
4月20日 关联分支 由 [] 改变为 [master]
4月20日 问题后端类型 由 [] 改变为 [Ascend]
4月20日 关联组件 由 [] 改变为 [B-SIG-Parallel]
4月20日 关联了pull request:fix: make moe load-balance loss depend on routing distribution
Problem
In
hyper_parallel/platform/torch/common/moe.py, function_compute_load_balance_losscomputed:expert_fractionwith shape[num_experts]mean_scorewith shape[top_k]This collapses to a near-constant value and does not reflect routing imbalance severity, which is inconsistent with the expected behavior of MoE load-balance auxiliary loss.
Reproduction (simplified)
Use the same
top_scoresbut differentselected_expertsdistributions (balanced vs. heavily imbalanced).The old implementation returns effectively constant behavior; loss does not track imbalance correctly.
Expected
Loss should vary with routing distribution and penalize imbalanced expert usage.
Fix
expert_fractionfrom normalized assignment counts.expert_probby accumulating per-token top-k probabilities onto selected experts.num_experts * sum(expert_fraction * expert_prob)as scalar auxiliary loss.Changed files
hyper_parallel/platform/torch/common/moe.pytests/ut/platform/torch/common/test_moe.py