[MoE] Add optional output normalization for latent MoE - #6449
Open
86MaxCao wants to merge 1 commit into
Open
Conversation
Add moe_latent_output_norm config that applies a TENorm over the latent dimension to the combined routed-expert output, after token combination and before the up-projection back to the transformer hidden size. Disabled by default; the normalization type and epsilon follow the existing normalization/layernorm_epsilon configs. Signed-off-by: 晞孟 <ximeng.czq@alibaba-inc.com>
6 tasks
5 tasks
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.
What does this PR do?
Add an optional normalization layer on the combined routed-expert output in latent MoE, applied after token combination and before the up-projection back to the transformer hidden size.
Motivation
Megatron Core already supports latent MoE through
moe_latent_size(down-projection → routed experts → combine → up-projection), but the combined latent output is fed intofc2_latent_projwith no way to normalize it. The Kimi K3 technical report (§2.3.1 "Normalized LatentMoE", Eq. 11) shows this step is a necessary part of the latent-MoE pipeline: the aggregated routed representation varies in scale with expert selection and routing weights, and normalizing it before the up-projection stabilizes training and improves validation loss. Since the normalization point sits between dispatcher combine andfc2_latent_projinsideMoELayer's execution flow, it belongs in the layer itself rather than in model-specific wrapper code.This PR exposes it as an optional, architecture-agnostic configuration that is disabled by default. Kimi K3 is the first public consumer; nothing in the implementation is K3-specific, and it works uniformly across token dispatchers (allgather / alltoall) and expert-parallel layouts.
A concurrent Megatron-Bridge integration (NVIDIA-NeMo/Megatron-Bridge#5130) currently duplicates
MoELayer.postprocessto insert exactly this normalization; landing the option in Core would let that integration drop the override.Changes
New config field
moe_latent_output_norm: bool = False. When enabled, the combined routed-expert output is normalized in the latent dimension after combine and before the up-projection:transformer_config.py: addmoe_latent_output_normfield + validation requiringmoe_latent_size.moe_layer.py: buildrouted_expert_norm = TENorm(...)when enabled; apply it inpostprocessbetweencombine_postprocessandfc2_latent_proj. The norm type and epsilon follow the existingnormalization/layernorm_epsilonconfigs.arguments.py/checkpointing.py: argument validation, pass-through, and checkpoint restore. The CLI flag--moe-latent-output-normis auto-generated and requires--moe-latent-size.test_latent_moe_layer.py: enable the option in the layer test; add config-validation and execution-order tests; use latent sizes 64/128.Test plan
pytest tests/unit_tests/transformer/moe/test_latent_moe_layer.py(14 passed: allgather/alltoall × TE/local × grouped/non-grouped GEMM × latent size 64/128, plus config-validation and execution-order tests)--moe-latent-output-normIssue tracking
Linked issue: Fix #6448
Contribution process
Pre-checks