docs(moe): correct moe_router_topk_scaling_factor docstring#4470
Open
edenfunf wants to merge 2 commits intoNVIDIA:mainfrom
Open
docs(moe): correct moe_router_topk_scaling_factor docstring#4470edenfunf wants to merge 2 commits intoNVIDIA:mainfrom
edenfunf wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
) The docstring stated the scaling factor "only works when moe_router_pre_softmax enabled", but topk_routing_with_score_function applies it unconditionally on the post-top-k probabilities for every score_function and pre_softmax setting. All shipped recipes (DeepSeek-R1, Kimi-K2, Llama-4, Nemotron, etc.) rely on this by combining a non-None scaling factor with the default moe_router_pre_softmax=False. Update the docstring to describe the actual behavior, and add a parametrized unit test in test_routers.py that pins the contract across {pre_softmax, score_function}.
Member
|
/ok to test 864f518 |
yaox12
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1875.
The docstring of
moe_router_topk_scaling_factor(transformer_config.py:694) said it "only works when moe_router_pre_softmax enabled", but the code intopk_routing_with_score_function(moe_utils.py:818) applies the scaling unconditionally on the post-top-k probabilities for everyscore_functionand regardless ofmoe_router_pre_softmax:Several shipped recipes confirm the current code behavior is the intended contract — they set a non-None scaling factor while keeping the default
moe_router_pre_softmax=False:examples/post_training/modelopt/conf/deepseek-ai/DeepSeek-R1.sh(2.5)examples/post_training/modelopt/conf/moonshotai/Kimi-K2-Instruct.sh(2.827)examples/post_training/modelopt/conf/meta-llama/Llama-4-Scout-17B-16E-Instruct.sh(1.0)examples/post_training/modelopt/conf/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16.sh(5.0)So the fix is on the docs side, not the code side.
Changes
megatron/core/transformer/transformer_config.py— rewrite the docstring to describe the actual unconditional post-top-k scaling behavior.tests/unit_tests/transformer/moe/test_routers.py— addtest_topk_scaling_factor_applies_for_all_pre_softmax_settings, a parametrized unit test that pins the contract over the cross product of{use_pre_softmax: True/False}×{score_function: softmax/sigmoid}.Test plan
Run on a Linux box / CI:
Local result (4/4 PASS, ~3.3s, CPU-only — no CUDA / process group required):
The test asserts:
If a future change ever re-introduces the "only when pre_softmax" gating, this test will fail in the
pre_softmax=Falsecases, surfacing the silent breakage in production recipes.