Skip to content

support optional megatron-bridge backend#9725

Open
hjh0119 wants to merge 5 commits into
modelscope:mainfrom
hjh0119:megatron-bridge
Open

support optional megatron-bridge backend#9725
hjh0119 wants to merge 5 commits into
modelscope:mainfrom
hjh0119:megatron-bridge

Conversation

@hjh0119

@hjh0119 hjh0119 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@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 introduces support for the megatron-bridge backend as an alternative to mcore-bridge in Megatron-SWIFT, including validation constraints, weight loading/saving adapters, and JIT warmup adjustments. Feedback on these changes highlights two issues: first, the MoE check for num_moe_experts in _get_megatron_bridge_model should also check the provider configuration to avoid incorrectly overriding parallel sizes; second, additional_saved_files should be retrieved from processor.model_meta instead of args to ensure custom files are properly copied during checkpoint saving.

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.

Comment thread swift/megatron/model/utils.py Outdated
Comment thread swift/megatron/model/utils.py Outdated
@hjh0119

hjh0119 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini 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 introduces support for the megatron-bridge backend as an alternative to mcore-bridge in Megatron-SWIFT. It adds a new bridge_backend argument, implements the MegatronBridgeBackend adapter class to interface with NVIDIA's AutoBridge, and updates model initialization and validation logic accordingly. Feedback on the changes highlights two issues: first, _check_mcore_bridge() is called unconditionally, which incorrectly enforces mcore-bridge version constraints even when using the megatron-bridge backend; second, the torch module is missing an import in swift/megatron/model/utils.py despite being referenced in type annotations.

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.

Comment thread swift/megatron/arguments/megatron_args.py
Comment thread swift/megatron/model/utils.py
@hjh0119

hjh0119 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

test with sft tp2pp2
image

bias.requires_grad, input_tensor.requires_grad = bias_grad, input_grad
for _ in range(5):
if config.swiglu:
if getattr(config, 'swiglu', getattr(config, 'gated_linear_unit', True)):

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.

Comment thread swift/megatron/init.py
os.environ.pop('VLLM_USE_MODELSCOPE', None)
logging_level = logging.root.level
_patch_unified_memory()
_patch_mcore_bridge()

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
Collaborator Author

Choose a reason for hiding this comment

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

移到MegatronArguments._check_bridge_backend里了

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.

3 participants