-
Notifications
You must be signed in to change notification settings - Fork 240
nemotron-3-super model support #2912
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
72c5b89
nemotron 3 super model support
liding-nv 02c4646
update
liding-nv 7618457
lint
liding-nv 8fc0f7d
clean up
liding-nv b30a725
clean up
liding-nv 2fe99b1
src/megatron/bridge/models/nemotronh/nemotron_h_bridge.py
liding-nv 13d58bb
comments
liding-nv ce3d13e
update
liding-nv f313561
fix tests
liding-nv 772b6a6
tests
liding-nv af7187a
Merge branch 'main' into super-v3-pr
liding-nv 4d22705
update
liding-nv 62776b9
Merge branch 'main' into super-v3-pr
liding-nv 564e071
add cp>1 examples
liding-nv 20955dd
Merge branch 'main' into super-v3-pr
liding-nv a7a52a5
readme
liding-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -xeuo pipefail | ||
|
|
||
| # Workspace directory for checkpoints and results | ||
| WORKSPACE=${WORKSPACE:-/workspace} | ||
|
|
||
| MODEL_NAME=NVIDIA-Nemotron-3-Super-120B-A12B-BF16 | ||
| HF_MODEL_ID=nvidia/$MODEL_NAME | ||
|
|
||
| # Import HF → Megatron | ||
| uv run torchrun --nproc_per_node=8 examples/conversion/convert_checkpoints_multi_gpu.py import \ | ||
| --hf-model $HF_MODEL_ID \ | ||
| --megatron-path ${WORKSPACE}/models/$MODEL_NAME \ | ||
| --tp 1 --ep 8 | ||
|
|
||
|
|
||
| # Export Megatron → HF | ||
| uv run torchrun --nproc_per_node=8 examples/conversion/convert_checkpoints_multi_gpu.py export \ | ||
| --hf-model $HF_MODEL_ID \ | ||
| --megatron-path ${WORKSPACE}/models/$MODEL_NAME/iter_0000000 \ | ||
| --hf-path ${WORKSPACE}/models/$MODEL_NAME-hf-export \ | ||
| --tp 1 --ep 8 | ||
|
|
||
|
|
||
| # Round-trip validation | ||
| uv run torchrun --nproc_per_node=8 \ | ||
| examples/conversion/hf_megatron_roundtrip_multi_gpu.py \ | ||
| --hf-model-id $HF_MODEL_ID \ | ||
| --megatron-load-path ${WORKSPACE}/models/$MODEL_NAME/iter_0000000 \ | ||
| --tp 1 --ep 8 |
107 changes: 107 additions & 0 deletions
107
examples/models/nemotron_3/super/finetune_nemotron_3_super.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import logging | ||
| import os | ||
| import sys | ||
| from typing import Tuple | ||
|
|
||
| import torch | ||
| from omegaconf import OmegaConf | ||
|
|
||
| from megatron.bridge.recipes.nemotronh.nemotron_3_super import ( | ||
| nemotron_3_super_peft_config, | ||
| nemotron_3_super_sft_config, | ||
| ) | ||
| from megatron.bridge.training.config import ConfigContainer | ||
| from megatron.bridge.training.finetune import finetune | ||
| from megatron.bridge.training.gpt_step import forward_step | ||
| from megatron.bridge.training.utils.omegaconf_utils import ( | ||
| apply_overrides, | ||
| create_omegaconf_dict_config, | ||
| parse_hydra_overrides, | ||
| ) | ||
|
|
||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def parse_cli_args() -> Tuple[argparse.Namespace, list[str]]: | ||
| """Parse command line arguments, separating known script args from OmegaConf overrides.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="Finetune Nemotron 3 Super model using Megatron-Bridge with YAML and CLI overrides", | ||
| formatter_class=argparse.RawTextHelpFormatter, | ||
| ) | ||
| parser.add_argument( | ||
| "--config-file", | ||
| type=str, | ||
| help="Path to the YAML OmegaConf override file.", | ||
| ) | ||
| parser.add_argument("--peft", type=str, help="Type of PEFT to use") | ||
| parser.add_argument("--seq-length", type=int, default=8192, help="Sequence length") | ||
|
|
||
| # Parse known args for the script, remaining will be treated as overrides | ||
| args, cli_dotlist_overrides = parser.parse_known_args() | ||
| return args, cli_dotlist_overrides | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """ | ||
| Entry point for the Nemotron 3 Super finetuning script. | ||
| """ | ||
| args, cli_overrides = parse_cli_args() | ||
|
|
||
| if args.peft is None or (isinstance(args.peft, str) and args.peft.lower() == "none"): | ||
| cfg: ConfigContainer = nemotron_3_super_sft_config() | ||
| else: | ||
| cfg: ConfigContainer = nemotron_3_super_peft_config(peft_scheme=args.peft) | ||
| cfg.model.seq_length = args.seq_length | ||
|
|
||
| # Convert the initial Python dataclass to an OmegaConf DictConfig for merging | ||
liding-nv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| merged_omega_conf, excluded_fields = create_omegaconf_dict_config(cfg) | ||
|
|
||
| # Load and merge YAML overrides if a config file is provided | ||
| if args.config_file: | ||
| logger.debug(f"Loading YAML overrides from: {args.config_file}") | ||
| if not os.path.exists(args.config_file): | ||
| logger.error(f"Override YAML file not found: {args.config_file}") | ||
| sys.exit(1) | ||
| yaml_overrides_omega = OmegaConf.load(args.config_file) | ||
| merged_omega_conf = OmegaConf.merge(merged_omega_conf, yaml_overrides_omega) | ||
| logger.debug("YAML overrides merged successfully.") | ||
|
|
||
| # Apply command-line overrides using Hydra-style parsing | ||
| if cli_overrides: | ||
| logger.debug(f"Applying Hydra-style command-line overrides: {cli_overrides}") | ||
| merged_omega_conf = parse_hydra_overrides(merged_omega_conf, cli_overrides) | ||
| logger.debug("Hydra-style command-line overrides applied successfully.") | ||
|
|
||
| # Apply the final merged OmegaConf configuration back to the original ConfigContainer | ||
| logger.debug("Applying final merged configuration back to Python ConfigContainer...") | ||
| final_overrides_as_dict = OmegaConf.to_container(merged_omega_conf, resolve=True) | ||
| # Apply overrides while preserving excluded fields | ||
| apply_overrides(cfg, final_overrides_as_dict, excluded_fields) | ||
|
|
||
| # Start training | ||
| logger.debug("Starting finetuning...") | ||
| finetune(config=cfg, forward_step_func=forward_step) | ||
|
|
||
| if torch.distributed.is_initialized(): | ||
| torch.distributed.destroy_process_group() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
100 changes: 100 additions & 0 deletions
100
examples/models/nemotron_3/super/pretrain_nemotron_3_super.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import logging | ||
| import os | ||
| import sys | ||
| from typing import Tuple | ||
|
|
||
| import torch | ||
| from omegaconf import OmegaConf | ||
|
|
||
| from megatron.bridge.recipes.nemotronh.nemotron_3_super import ( | ||
| nemotron_3_super_pretrain_config as pretrain_config, | ||
| ) | ||
| from megatron.bridge.training.config import ConfigContainer | ||
| from megatron.bridge.training.gpt_step import forward_step | ||
| from megatron.bridge.training.pretrain import pretrain | ||
| from megatron.bridge.training.utils.omegaconf_utils import ( | ||
| apply_overrides, | ||
| create_omegaconf_dict_config, | ||
| parse_hydra_overrides, | ||
| ) | ||
|
|
||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def parse_cli_args() -> Tuple[argparse.Namespace, list[str]]: | ||
| """Parse command line arguments, separating known script args from OmegaConf overrides.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="Pretrain Nemotron 3 Super model using Megatron-Bridge with YAML and CLI overrides", | ||
| formatter_class=argparse.RawTextHelpFormatter, | ||
| ) | ||
| parser.add_argument( | ||
| "--config-file", | ||
| type=str, | ||
| help="Path to the YAML OmegaConf override file. Default: conf/llama3_8b_pretrain_override_example.yaml", | ||
| ) | ||
|
|
||
| # Parse known args for the script, remaining will be treated as overrides | ||
| args, cli_dotlist_overrides = parser.parse_known_args() | ||
| return args, cli_dotlist_overrides | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """ | ||
| Entry point for the Nemotron 3 Super pretraining script. | ||
| """ | ||
liding-nv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| args, cli_overrides = parse_cli_args() | ||
|
|
||
| cfg: ConfigContainer = pretrain_config() | ||
|
|
||
| # Convert the initial Python dataclass to an OmegaConf DictConfig for merging | ||
| merged_omega_conf, excluded_fields = create_omegaconf_dict_config(cfg) | ||
|
|
||
| # Load and merge YAML overrides if a config file is provided | ||
| if args.config_file: | ||
| logger.debug(f"Loading YAML overrides from: {args.config_file}") | ||
| if not os.path.exists(args.config_file): | ||
| logger.error(f"Override YAML file not found: {args.config_file}") | ||
| sys.exit(1) | ||
| yaml_overrides_omega = OmegaConf.load(args.config_file) | ||
| merged_omega_conf = OmegaConf.merge(merged_omega_conf, yaml_overrides_omega) | ||
| logger.debug("YAML overrides merged successfully.") | ||
|
|
||
| # Apply command-line overrides using Hydra-style parsing | ||
| if cli_overrides: | ||
| logger.debug(f"Applying Hydra-style command-line overrides: {cli_overrides}") | ||
| merged_omega_conf = parse_hydra_overrides(merged_omega_conf, cli_overrides) | ||
| logger.debug("Hydra-style command-line overrides applied successfully.") | ||
|
|
||
| # Apply the final merged OmegaConf configuration back to the original ConfigContainer | ||
| logger.debug("Applying final merged configuration back to Python ConfigContainer...") | ||
| final_overrides_as_dict = OmegaConf.to_container(merged_omega_conf, resolve=True) | ||
| # Apply overrides while preserving excluded fields | ||
| apply_overrides(cfg, final_overrides_as_dict, excluded_fields) | ||
|
|
||
| # Start training | ||
| logger.debug("Starting pretraining...") | ||
| pretrain(config=cfg, forward_step_func=forward_step) | ||
|
|
||
| if torch.distributed.is_initialized(): | ||
| torch.distributed.destroy_process_group() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.