Skip to content

[megatron] fix: MTP patch for newer mcore#5587

Open
HollowMan6 wants to merge 1 commit intoverl-project:mainfrom
HollowMan6:mtp_patch
Open

[megatron] fix: MTP patch for newer mcore#5587
HollowMan6 wants to merge 1 commit intoverl-project:mainfrom
HollowMan6:mtp_patch

Conversation

@HollowMan6
Copy link
Collaborator

What does this PR do?

Fix regression introduced in #5561

As mentioned in #5323 (comment), there's no compute_output_layer_and_language_model_loss in new mcore and everything needs to be handled by process_mtp_loss https://github.com/NVIDIA/Megatron-LM/blob/9a19203af5f8941e4ff9528443e3e5b8928b8c81/megatron/core/models/gpt/gpt_model.py#L651

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

@HollowMan6 HollowMan6 requested a review from ISEEKYAN as a code owner March 14, 2026 00:51
Copilot AI review requested due to automatic review settings March 14, 2026 00:51
@HollowMan6 HollowMan6 requested review from ArronHZG, ISEEKYAN and wuxibin89 and removed request for ISEEKYAN, Copilot and vermouth1992 March 14, 2026 00:51
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a regression in multi-token prediction (MTP) when using newer versions of megatron-core. It correctly switches to the new process_mtp_loss helper function while maintaining backward compatibility. My review includes a suggestion to refine the compatibility check to make it more robust and prevent it from unintentionally masking potential bugs, which will improve the code's maintainability and ease of debugging.

Copilot AI review requested due to automatic review settings March 14, 2026 00:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Megatron GPTModel postprocess monkey-patch to prefer Megatron-LM’s newer process_mtp_loss helper when available, while keeping a fallback implementation for older Megatron-LM versions.

Changes:

  • Extend _megatron_gptmodel_postprocess signature to accept additional keyword arguments (**kwargs) for compatibility with upstream callers.
  • Use megatron.core.transformer.multi_token_prediction.process_mtp_loss when present; otherwise fall back to the existing manual MTP loss path.
  • Add logic to select cp_group from either self.pg_collection.cp or self.cp_group for the upstream helper path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

There's no compute_output_layer_and_language_model_loss in
new mcore and everything needs to be handled by process_mtp_loss

Signed-off-by: Hollow Man <hollowman@opensuse.org>
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.

2 participants