Skip to content

Fix qwen moe Load balancing loss calculation outside training - #42133

Closed
diegoakel wants to merge 5 commits into
huggingface:mainfrom
diegoakel:fix-qwen3moe-lb-loss
Closed

diegoakel wants to merge 5 commits into
huggingface:mainfrom
diegoakel:fix-qwen3moe-lb-loss

Conversation

@diegoakel

Copy link
Copy Markdown
Contributor

What does this PR do?

Removes the calculation of load balancing loss for Qwen MoE models when outside training mode.

Fixes #42100

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@Rocketknight1

@diegoakel
diegoakel marked this pull request as draft November 10, 2025 18:33
@diegoakel
diegoakel marked this pull request as ready for review November 10, 2025 19:09
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: qwen3_moe, qwen3_omni_moe, qwen3_vl_moe

@Rocketknight1

Copy link
Copy Markdown
Member

Posted in #42100 as well, but do you know how output_router_logits is getting set? This should only happen when that's set to True.

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Thanks @diegoakel! On main the load-balancing loss is only computed when output_router_logits is enabled (see modular_qwen3_moe.py), and @Rocketknight1's question in #42100 about how it got turned on at inference was never resolved, so I'm closing this. Happy to reopen if you have a reproducer on current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3Moe models have bug during generation since they calculate unnecessary load_balancing_loss

3 participants