Skip to content

Add MTP-only training mode - #7021

Merged
cuichenx merged 5 commits into
NVIDIA:mainfrom
YanivDorGalron:freeze-base-model-for-mtp
Sep 3, 2026
Merged

cuichenx merged 5 commits into
NVIDIA:mainfrom
YanivDorGalron:freeze-base-model-for-mtp

Conversation

@YanivDorGalron

Copy link
Copy Markdown
Contributor

Freeze backbone parameters and skip their autograd graph so MTP layers train with reduced optimizer and activation memory.

Description

Add --freeze-base-model-for-mtp to train only Multi-Token Prediction (MTP) layers while keeping the base model frozen.

When enabled, this change:

  • keeps only mtp.layers.* parameters trainable
  • excludes backbone parameters from optimizer and DDP gradient buffers
  • runs the GPT or Hybrid backbone decoder under torch.no_grad() during training
  • freezes backbone MoE router expert-bias updates while preserving MTP router updates
  • requires --mtp-num-layers and rejects use with --freeze-all-layers

This reduces optimizer state, gradient storage, and backbone activation memory during MTP-only training.

Testing

Ran targeted tests on one GPU using torch.distributed.run:

  • argument validation
  • Hybrid decoder gradient context
  • MTP forward/backward with and without full recomputation
  • verification that only MTP parameters receive gradients and optimizer state

Freeze backbone parameters and skip their autograd graph so MTP layers train with reduced optimizer and activation memory.

Signed-off-by: Yaniv Galron <ygalron@nvidia.com>
@YanivDorGalron
YanivDorGalron requested a review from a team as a code owner September 1, 2026 14:49
@YanivDorGalron
YanivDorGalron requested a review from a team September 1, 2026 14:49
@YanivDorGalron
YanivDorGalron requested review from a team as code owners September 1, 2026 14:49
@copy-pr-bot

copy-pr-bot Bot commented Sep 1, 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.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft September 1, 2026 14:49
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@YanivDorGalron
YanivDorGalron marked this pull request as ready for review September 1, 2026 14:54
@fanshiqing

Copy link
Copy Markdown
Member

/ok to test 3b907ec

Signed-off-by: Yaniv Galron <ygalron@nvidia.com>
@fanshiqing

Copy link
Copy Markdown
Member

/ok to test 0f20933

Signed-off-by: Yaniv Galron <ygalron@nvidia.com>
Comment thread megatron/training/training.py Outdated
return model_list


def _add_model_freeze_pre_wrap_hook(model_config, args):

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.

one nit. since only 2 settings from args are needed here, can we pass those explicitly? imo limiting state that's exposed in these small funcs keeps them focused, avoids vaguely related logic from being added just because args is available.

@ericharper
ericharper enabled auto-merge September 3, 2026 01:35
@ericharper

Copy link
Copy Markdown
Contributor

/ok to test 9abda94

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Sep 3, 2026
@ericharper
ericharper added this pull request to the merge queue Sep 3, 2026
@maanug-nv
maanug-nv removed this pull request from the merge queue due to a manual request Sep 3, 2026
Signed-off-by: Yaniv Galron <ygalron@nvidia.com>
@cuichenx

cuichenx commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test 603059e

@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

Merged via the queue into NVIDIA:main with commit 7db926d Sep 3, 2026
102 checks passed

This branch was previously deployed

2 inactive deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.