Skip to content

[Dev] feat(moe): Support placing MTP layers into standalone stages - #1916

Merged
chtruong814 merged 14 commits into
NVIDIA:devfrom
BestJuly:lit/mtp_layer_standalone_dev
Nov 2, 2025
Merged

[Dev] feat(moe): Support placing MTP layers into standalone stages#1916
chtruong814 merged 14 commits into
NVIDIA:devfrom
BestJuly:lit/mtp_layer_standalone_dev

Conversation

@BestJuly

@BestJuly BestJuly commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

What does this PR do ?

Support placing MTP to a standalone stage, e.g., MTP in the 2nd last VPP stage for better VPP balance.
PR for main branch: PR2136

Highlights

This document outlines the design of a new MTP (Multi-Token Prediction) standalone feature. This feature allows MTP layers to be placed into a standalone VPP (Virtual Pipeline Parallelism) stage, rather than being confined to the last VPP stage.

Key Benefits:

  • Enhanced Flexibility in MTP VPP Placement
    • MTP layers can now be positioned in either the last or second-to-last VPP stage, offering greater control over pipeline configuration.
  • Improved Load Balancing
    • The MTP standalone feature isolates transformer block-related computations, which have a similar computational cost to a normal transformer block. This split, with MTP loss calculation remaining in the second-to-last VPP stage, contributes to a more balanced workload.
  • Minimal Impact on Existing Code Paths
    • The design aims for near-zero impact on current code. A minor change involves the final layernorm layer, which will now be placed at the end of the decoder stage. In scenarios where the last stage contains only MTP layers and loss, this layernorm will reside in the second-to-last layer alongside a decoder layer. While this differs from previous implementations (where the final layernorm was always in the last stage), bitwise correctness has been validated under various conditions, including forceful layernorm placement and disabled gradient clipping.

Considerations:

  • Changes in P2P Communication Shapes
    • The need to pass original and MTP hidden states to subsequent VPP stages will alter p2p communication shapes. To mitigate the impact on core communication, the shape is communicated upfront when MTP standalone settings are detected in the pipeline layout.

Design idea

We split MTP computation into two parts

  • Output head computation.
  • Others.
image

The advantage is that we put the MTP loss computation as main, so for the untie embedding part, the MTP loss can use exactly the same code path of the lm loss as they are in the same vpp stage, which is simpler than putting MTP loss calculation in the same vpp stage as MR#2996 so that we can avoid bugs related to this. With the new design, the DSv3 TFLOPs will also be compatible with the #2996 one which included in the 0.13 EA branch.We divide MTP computation into two parts: output head computation and others. This approach offers the advantage of treating MTP loss computation as primary. Consequently, for the untied embedding, the MTP loss can utilize the exact same code path as the LM loss, as they are within the same VPP stage. This simplifies the process compared to placing MTP loss calculation in the same VPP stage as MR#2996, thereby mitigating potential bugs. Furthermore, this new design ensures DSv3 TFLOPs compatibility with the #2996 version included in the 0.13 EA branch.

Perf and results

Perf

  • The throughput in DSv3 is on par or even higher than 0.13 EA (where we use previous design for this standalone feature).

Convergence

On full DSv3
(Real training mode) Almost overlapped with the main branch settings for the metrics which is related to convergence.

Deterministic correctness check
We validate the correctness in mainly two parts (when using different pp layout, can be bitwise aligned when manually disabling grad clipping)

  • Deterministic alignment between main branch and this MR.
    • The same pipeline layout settings;
    • Different pipeline layout settings.
  • Deterministic alignment within this MR to validate the compatibility of 1F1B overlap.

@BestJuly BestJuly self-assigned this Oct 24, 2025
@BestJuly
BestJuly requested review from a team as code owners October 24, 2025 07:16
@BestJuly
BestJuly requested a review from yanring October 24, 2025 07:17
@BestJuly BestJuly added module: moe Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. labels Oct 24, 2025
@BestJuly

Copy link
Copy Markdown
Contributor Author

/ok to test 4a342ec

@BestJuly
BestJuly force-pushed the lit/mtp_layer_standalone_dev branch from 4a342ec to ef3337c Compare October 28, 2025 08:22
@ko3n1g ko3n1g added this to the Core 0.16 milestone Oct 28, 2025
@BestJuly
BestJuly force-pushed the lit/mtp_layer_standalone_dev branch from ef3337c to 3e5cd0a Compare October 28, 2025 08:29
shifangx and others added 14 commits October 30, 2025 01:30
move output layer outside mtp block

support mtp layer for --pipeline-model-parallel-layout

run test with mtp on the second last vpp stage, with the following error
message.

can run, but need to check lm loss and mtp loss with baseline.

fix some issue by refering to MR2996

Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
…apes later

Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
Signed-off-by: Li Tao <lit@nvidia.com>
@BestJuly

Copy link
Copy Markdown
Contributor Author

Pipeline 37554648 triggered in gitlab for functional test validation.

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

Labels

core_dev_r0.15.0 Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. module: moe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants