Skip to content

Add RMSNorm latent up-projection - #6803

Open
harryzhou2000 wants to merge 1 commit into
NVIDIA:mainfrom
harryzhou2000:hhanyu/k3-latent-rmsnorm-main
Open

harryzhou2000 wants to merge 1 commit into
NVIDIA:mainfrom
harryzhou2000:hhanyu/k3-latent-rmsnorm-main

Conversation

@harryzhou2000

@harryzhou2000 harryzhou2000 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do ?

Add an optional RMSNorm immediately before LatentMoE's duplicated latent up-projection. This matches the routed-expert aggregation in the Kimi K3 technical report, where the combined routed latent result is normalized before projecting back to model width.

Dev counterpart: #6804

Design

  • Add moe_latent_up_projection_rmsnorm, valid only when moe_latent_size is set.
  • Add TERMSNormDuplicatedLinear, a thin MCore wrapper around TE LayerNormLinear with normalization="RMSNorm" hard-coded.
  • Keep TE execution local (tp_size=1) because the latent up-projection is duplicated across TP ranks, while retaining the owning TP group for checkpoint metadata and MCore gradient-reduction/SP tags.
  • Select the fused RMSNorm-linear wrapper only for the latent up-projection. The latent down-projection and shared-expert path are unchanged; shared-expert output is added after the routed up-projection.
  • Reject the unsupported inference-optimized combination explicitly instead of silently dropping RMSNorm.
  • Thread the existing GTP rematerialization and replica groups into the wrapper. Only the linear weight is GTP-sharded; the RMSNorm scale and optional full-width bias remain replicated.

Issue tracking

Linked issue: N/A

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Focused unit coverage includes BF16 numerical forward/backward checks, real TP2 with sequence parallelism, explicit checkpoint process-group metadata, Blackwell MXFP8 forward/backward with aligned dimensions, and real four-rank GTP execution with and without bias. No separate functional test was added because this is a module-local selection and wrapper change.

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

Testing

Validated on NVIDIA B200 GPUs with PyTorch 2.12 nightly and Transformer Engine 2.20 development sources.

Checkpoint/rebase validation on the current tip also passed:

  • --use-checkpoint-args restores both moe_latent_size and moe_latent_up_projection_rmsnorm.
  • The hybrid-model golden-config comparator includes the new selector and passes.
  • The repository autoformatter and git diff --check pass.
2 ranks: tests/unit_tests/transformer/moe/test_latent_moe_layer.py
Result: 19 passed per rank

4 ranks: tests/unit_tests/generalized_tensor_parallel/test_gtp_basics.py -k RMSNormDuplicatedLinearGTP
Result: 2 passed per rank

The test suites exercise TP1 BF16, real TP2+SP BF16, MXFP8 forward/backward, and main-only GTP bias/no-bias behavior. git diff --check, import sorting, and Python compilation also pass.

@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 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.

@harryzhou2000
harryzhou2000 marked this pull request as ready for review August 25, 2026 02:20
@harryzhou2000
harryzhou2000 requested review from a team as code owners August 25, 2026 02:20
Signed-off-by: Harry Zhou <hhanyu@nvidia.com>

This branch has not been deployed

No deployments
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.

1 participant