mindspore-ai / mindspore-ai/hyper-parallel
[Bug] MoE _compute_load_balance_loss may become constant and ignore routing distribution
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 53
- Forks
- 63
- Avg merge
- 23h 45m
- Merged PRs (30d)
- 63
Description
Problem
In hyper_parallel/platform/torch/common/moe.py, function _compute_load_balance_loss computed:
expert_fractionwith shape[num_experts]mean_scorewith shape[top_k]- then multiplied via broadcasting and summed all elements
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_scores but different selected_experts distributions (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
- Compute
expert_fractionfrom normalized assignment counts. - Compute
expert_probby accumulating per-token top-k probabilities onto selected experts. - Use
num_experts * sum(expert_fraction * expert_prob)as scalar auxiliary loss. - Add unit test to verify imbalanced routing gets larger loss than balanced routing.
Changed files
hyper_parallel/platform/torch/common/moe.pytests/ut/platform/torch/common/test_moe.py
schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 95
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/95
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with _compute_load_balance_loss in hyper_parallel/platform/torch/common/moe.py, then inspect the related cases in tests/ut/platform/torch/common/test_moe.py. Verify that expert assignment counts and top-k probabilities are accumulated per expert, and add or update the test so imbalanced routing produces a larger loss than balanced routing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100