Skip to content

Implement Quantile Balancing in MoE - #5349

Merged
Mellonta merged 1 commit into
NVIDIA:mainfrom
Mellonta:haoranz
Jul 15, 2026
Merged

Implement Quantile Balancing in MoE#5349
Mellonta merged 1 commit into
NVIDIA:mainfrom
Mellonta:haoranz

Conversation

@Mellonta

@Mellonta Mellonta commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Adding Quantile Balancing (QB) MoE.

Standard MoE load balancing adds an auxiliary loss whose gradient nudges the router toward uniform expert usage. QB instead enforces balance directly through a per-expert routing bias, with no auxiliary loss and no gradient contribution, load balancing is handled entirely by a bias that is updated once per global batch from a quantile estimate. From marin's report: https://openathena.ai/blog/quantile-balancing/

Conceptually, it can be understood as a two-part process run after each step, based on the scores that each token generates for each expert.

  1. For each token, compute the threshold score required to become activated.
  2. For each expert, using the result from step 1, determine the bias that would activate a balanced number of tokens.

Usage

--moe-router-load-balancing-type quantile_balancing
--moe-router-quantile-balancing-ema 0.0   # optional; 0.0 (default) = no memory, e.g. 0.9 to smooth
--moe-aux-loss-coeff 0                     # aux loss must be off

Verified on 2B models

@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Mellonta

Copy link
Copy Markdown
Contributor Author

/claude review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test b4dde89

@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test 4b2f1d7

@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test 2c1fadf

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Jul 13, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Jul 13, 2026
@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test 6e0ef96

@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test c1123ab

@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test f1dddce

Signed-off-by: Haoran Zhang <haoranz@nvidia.com>
@Mellonta

Copy link
Copy Markdown
Contributor Author

/ok to test cd4aed8

@Mellonta

Copy link
Copy Markdown
Contributor Author

Also fixes a pre-existing order-dependent hang in test_shared_expert_forward_backward: it seeded only CUDA but uses use_cpu_initialization, so inherited CPU-RNG state could drift in some ranks and cause a deadlock. now seeded via _set_random_seed.

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29379425584

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29381411801

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

Labels

Approved All necessary approvals have been made complexity: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants