Skip to content

[megatron] fix: add backward compatibility with older Megatron-Bridge versions#6682

Open
nuerxiati wants to merge 1 commit into
verl-project:mainfrom
nuerxiati:bridge
Open

[megatron] fix: add backward compatibility with older Megatron-Bridge versions#6682
nuerxiati wants to merge 1 commit into
verl-project:mainfrom
nuerxiati:bridge

Conversation

@nuerxiati

@nuerxiati nuerxiati commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Add concise overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.

After #6335 (bc3f3bf0), verl adopted several new Megatron-Bridge APIs that do not exist in older versions. Using the latest verl with an older Megatron-Bridge causes ImportError and AttributeError at runtime.

  • Add backward-compatible fallbacks in three files so that the latest verl works with both new and old Megatron-Bridge versions without requiring a Bridge upgrade.

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.

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

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.

Code Review

This pull request updates verl/models/mcore/bridge.py to provide fallback implementations for LinearForLastLayer, make_value_model, and freeze_moe_router in case they cannot be imported from megatron.bridge.training.utils.train_utils. This ensures compatibility and robustness when those specific utilities are not available. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@nuerxiati nuerxiati changed the title [megatron] fix: add backward-compatible fallback for bridge.py imports with older Megatron-Bridge [megatron] fix: add backward compatibility with older Megatron-Bridge versions Jun 11, 2026
@@ -15,12 +15,91 @@

try:

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.

releases/v0.8.0是否也可以增加该版本兼容PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已提:#6695

raise

try:
from megatron.bridge.training.utils.train_utils import LinearForLastLayer, freeze_moe_router, make_value_model

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

加上注释表明分支兼容情况

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -15,12 +15,85 @@

try:
from megatron.bridge import AutoBridge

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

原pr中from megatron.bridge.models.conversion.param_mapping import AutoMapping,AutoMapping.register_module_type("LinearForLastLayer", "replicated")这段代码确认一下是否不需要

):
layer.mlp.shared_experts.gate_bias.requires_grad = False
return model

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lora相关代码均已删除,不支持lora兼容

# 3. The distributed optimizer must only track trainable (adapter) parameters
# See Megatron-Bridge docs: training/peft.md

# Register PEFT transformation as pre-wrap hook if peft_cls is specified

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这段注释为啥删除了,尽量不要影响gpu相关逻辑和注释

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已恢复

Comment thread verl/utils/megatron_utils.py Outdated
ddp_config = None
if wrap_config.wrap_with_ddp:
try:
from megatron.bridge.training.utils.config_utils import create_ddp_config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里也加上注释

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@nuerxiati nuerxiati force-pushed the bridge branch 3 times, most recently from 5bd697c to 9554d40 Compare June 12, 2026 07:47
wucong25
wucong25 previously approved these changes Jun 12, 2026
raise

# Megatron-Bridge >= v0.5.0 exposes these symbols in train_utils.
# Megatron-Bridge < v0.5.0 does not, so we fall back to local implementations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is compatibility with the legacy version of megatron-bridge still required?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants