-
Notifications
You must be signed in to change notification settings - Fork 142
add nemo_bridge #1050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add nemo_bridge #1050
Changes from all commits
d82146d
a358436
90c2ed0
224f8e1
c0b0f37
2900956
0dd3b6b
961b6c5
108d0f6
438938e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) 2025, BAAI. All rights reserved. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename flagscale/train/megatron/nemo_bridge to flagscale/train/megatron/bridge so that it matches the import pattern from megatron.bridge |
||
|
|
||
| """Megatron Bridge - A component of the Megatron ecosystem.""" | ||
|
|
||
| from megatron.nemo_bridge.models.conversion.auto_bridge import AutoBridge | ||
|
|
||
| __all__ = ["AutoBridge"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Copyright (c) 2025, BAAI. All rights reserved. | ||
|
|
||
| from megatron.nemo_bridge.models.conversion.auto_bridge import AutoBridge | ||
| from megatron.nemo_bridge.models.conversion.model_bridge import MegatronModelBridge | ||
| from megatron.nemo_bridge.models.conversion.param_mapping import ( | ||
| AutoMapping, | ||
| QKVMapping, | ||
| ) | ||
| from megatron.nemo_bridge.models.deepseek.deepseek_v3_bridge import DeepSeekV3Bridge | ||
| from megatron.nemo_bridge.models.qwen.qwen3_bridge import Qwen3Bridge | ||
| from megatron.nemo_bridge.models.hf_pretrained.causal_lm import PreTrainedCausalLM | ||
|
|
||
| __all__ = [ | ||
| "AutoBridge", | ||
| "MegatronModelBridge", | ||
| "QKVMapping", | ||
| "AutoMapping", | ||
| "DeepSeekV3Bridge", | ||
| "Qwen3Bridge", | ||
| "PreTrainedCausalLM", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) 2025, BAAI. All rights reserved. | ||
|
|
||
| from megatron.nemo_bridge.models.conversion.auto_bridge import AutoBridge | ||
|
|
||
| __all__ = [ | ||
| "AutoBridge", | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,243 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copyright (c) 2025, BAAI. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks to me that this file was largely adapted from flagscale/train/megatron/nemo_bridge/models/conversion/auto_bridge.py. We copy-pasted the source and we are claiming copyright for this code. This is not acceptable. We can borrow code from other projects, provided that the license terms grant us this right. In that case, we still have to pay credit to the original authors. We are obliged to mention their copyrights. There are some weird characters in this file which was obviously a character conversion problem during copy/paste. Please fix them as well. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.bridge import AutoBridge as OriginalAutoBridge | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import transformers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch.distributed as dist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from transformers import AutoModelForCausalLM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from transformers.configuration_utils import PretrainedConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.core.transformer.module import MegatronModule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.nemo_bridge.models.conversion import model_bridge | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.nemo_bridge.models.conversion.model_bridge import MegatronModelBridge | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.nemo_bridge.models.hf_pretrained.causal_lm import PreTrainedCausalLM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.bridge.models.hf_pretrained.state import SafeTensorsStateSource | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.bridge.models.hf_pretrained.safe_config_loader import safe_load_config_with_retry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.bridge.models.conversion.utils import get_causal_lm_class_via_auto_map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TypeVar, Union | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+19
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.bridge import AutoBridge as OriginalAutoBridge | |
| import transformers | |
| import torch.distributed as dist | |
| from transformers import AutoModelForCausalLM | |
| from transformers.configuration_utils import PretrainedConfig | |
| from megatron.core.transformer.module import MegatronModule | |
| from megatron.nemo_bridge.models.conversion import model_bridge | |
| from megatron.nemo_bridge.models.conversion.model_bridge import MegatronModelBridge | |
| from megatron.nemo_bridge.models.hf_pretrained.causal_lm import PreTrainedCausalLM | |
| from megatron.bridge.models.hf_pretrained.state import SafeTensorsStateSource | |
| from megatron.bridge.models.hf_pretrained.safe_config_loader import safe_load_config_with_retry | |
| from megatron.bridge.models.conversion.utils import get_causal_lm_class_via_auto_map | |
| from typing import TypeVar, Union | |
| from pathlib import Path | |
| from pathlib import Path | |
| from typing import TypeVar, Union | |
| import torch.distributed as dist | |
| import transformers | |
| from transformers import AutoModelForCausalLM | |
| from transformers.configuration_utils import PretrainedConfig | |
| from megatron.bridge import AutoBridge as OriginalAutoBridge | |
| from megatron.bridge.models.conversion.utils import get_causal_lm_class_via_auto_map | |
| from megatron.bridge.models.hf_pretrained.safe_config_loader import safe_load_config_with_retry | |
| from megatron.bridge.models.hf_pretrained.state import SafeTensorsStateSource | |
| from megatron.core.transformer.module import MegatronModule | |
| from megatron.nemo_bridge.models.conversion import model_bridge | |
| from megatron.nemo_bridge.models.conversion.model_bridge import MegatronModelBridge | |
| from megatron.nemo_bridge.models.hf_pretrained.causal_lm import PreTrainedCausalLM |
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message strings contain garbled replacement characters (e.g., �~\~W). This will render poorly for users and makes logs hard to read; replace with the intended symbol/text (e.g., plain "Error:" / "Unsupported:" or a proper Unicode character) and ensure the file encoding is UTF-8 clean.
| f"\n�~\~W Model architecture not supported by AutoBridge\n\n" | |
| f"\nError: Model architecture not supported by AutoBridge\n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these weird characters?
There are some other similar cases in this string.
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple Ruff/pycodestyle violations in this block (e.g., if modeling_path : / elif ... and config : whitespace before :, and import os,sys multiple imports on one line + missing whitespace after comma). These will fail lint; please normalize to standard formatting (if ...: and one import per line).
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from_hf_config swallows exceptions when importing/building the dynamic HF model (print(f"import module error: {e}")) and then continues, potentially returning an AutoBridge with hf_model still None. This will cause failures later in a much less debuggable place. Raise an exception (or re-raise with context) if the model class can't be loaded, and ensure hf_model is non-None before returning.
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_hf_weights calls PreTrainedCausalLM.from_pretrained(hf_path) twice (the first result is immediately overwritten). This adds unnecessary IO/memory overhead; remove the redundant first call and load once with the correct trust_remote_code value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nemo megatron-bridge supports pip install for usage, ref https://pypi.org/project/megatron-bridge/
please remove source codes