Skip to content

Megatron-Bridge import example in launcher for Nemotron Super V3 [OMNIML-4827] - #1516

Merged
jenchen13 merged 5 commits into
mainfrom
jennifchen/mbridge_import
May 27, 2026
Merged

Megatron-Bridge import example in launcher for Nemotron Super V3 [OMNIML-4827]#1516
jenchen13 merged 5 commits into
mainfrom
jennifchen/mbridge_import

Conversation

@jenchen13

@jenchen13 jenchen13 commented May 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: New feature

Add Megatron-Bridge import example in launcher for Nemotron Super V3

Usage

# Usage:
#   export SLURM_HOST=<slurm-host>
#   export SLURM_ACCOUNT=<your-team>
#   export SLURM_PARTITION=<gpu-partition>   # default: batch
#   export SLURM_JOB_DIR=/home/scratch.<user>/experiments
#   export HF_TOKEN=<your-hf-token>          # gated model
#   cd tools/launcher
#   uv run launch.py --yaml examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml --yes

Testing

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅ / ❌ / N/A
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: ✅ / ❌ / N/A
  • Did you write any new necessary tests?: ✅ / ❌ / N/A
  • Did you update Changelog?: ✅ / ❌ / N/A
  • Did you get Claude approval on this PR?: ✅ / ❌ / N/A

Additional Information

Summary by CodeRabbit

  • New Features

    • Added a Megatron-Bridge Hugging Face → Megatron checkpoint import entrypoint (CPU-capable) and an example pipeline for importing the Nvidia Nemotron-3 Super 120B model.
    • Exposed an output_dir global variable for pipeline interpolation.
  • Chores

    • Updated pinned Megatron-LM module.
    • Extended .gitignore to cover .env-* variants.

Review Change Stack

Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
@jenchen13
jenchen13 requested a review from ChenhanYu May 18, 2026 20:26
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a bash entrypoint to run Megatron-Bridge HF→Megatron conversion, a Slurm job example invoking it, an optional output_dir global variable for pipeline YAMLs, and small infra updates (Megatron-LM submodule pin and .env-* in .gitignore).

Changes

Megatron-Bridge Checkpoint Import

Layer / File(s) Summary
GlobalVariables output_dir addition
tools/launcher/core.py
Adds optional output_dir field to GlobalVariables enabling <<global_vars.output_dir>> in pipeline YAMLs.
Megatron-Bridge import script implementation
tools/launcher/common/megatron_bridge/import/import.sh
import.sh validates HF_MODEL_ID, computes OUTPUT_DIR (default pwd) and megatron path <basename(HF_MODEL_ID)>-MCore, defaults TORCH_DTYPE=bfloat16, creates the output dir, and execs /opt/Megatron-Bridge/examples/conversion/convert_checkpoints.py import with --hf-model, --megatron-path, and --torch-dtype.
Job example wiring
tools/launcher/examples/nvidia/.../megatron_bridge_import.yaml
Adds a Slurm pipeline YAML example that calls the import script with HF_MODEL_ID and OUTPUT_DIR, configures container nvcr.io/nvidia/nemo:26.04, 1 node / 8 GPUs, batch partition, and 4-hour time limit.
Submodule and .gitignore updates
tools/launcher/modules/Megatron-LM, .gitignore
Pins Megatron-LM submodule to a new commit and adds .env-* to .gitignore.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed PR introduces Megatron-Bridge import with no security anti-patterns: no unsafe torch.load, numpy.load, eval/exec, hardcoded trust_remote_code, new nosec comments, or unsafe dependencies.
Title check ✅ Passed The title directly and specifically references the main addition: a Megatron-Bridge import example for Nemotron Super V3 in the launcher.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jennifchen/mbridge_import

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tools/launcher/launch.py (1)

74-74: ⚡ Quick win

Avoid hardcoding relative_path length.

This is easy to desync from include_pattern and can silently break packager mapping when entries change.

Proposed refactor
-packager = run.PatternPackager(
-    include_pattern=[
+_include_patterns = [
         "modules/Megatron-LM/megatron/*",
         "modules/Megatron-LM/examples/*",
         "modules/Megatron-LM/*.py",
         "modules/Megatron-Bridge/src/*",
         "modules/Megatron-Bridge/examples/*",
         "modules/Megatron-Bridge/pyproject.toml",
         "modules/Megatron-Bridge/README.md",
         "modules/Model-Optimizer/modelopt/*",
         "modules/Model-Optimizer/modelopt_recipes/*",
         "modules/Model-Optimizer/examples/*",
         "examples/*",
         "common/*",
-    ],
-    relative_path=[LAUNCHER_DIR] * 12,
+]
+
+packager = run.PatternPackager(
+    include_pattern=_include_patterns,
+    relative_path=[LAUNCHER_DIR] * len(_include_patterns),
 )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/launcher/launch.py` at line 74, The hardcoded repeat count in the
relative_path assignment (relative_path=[LAUNCHER_DIR] * 12) can get out of sync
with include_pattern; change it to derive the repeat length from the
include_pattern (e.g. relative_path=[LAUNCHER_DIR] * len(include_pattern) or
equivalent) so that relative_path size always matches include_pattern length
(reference variables: relative_path, LAUNCHER_DIR, include_pattern).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/launcher/common/megatron_bridge/import/import.sh`:
- Around line 45-49: The current import check only verifies importability and
can pick up an older installed megatron.bridge; change the logic so we force
local resolution by verifying the imported module's file path is inside
BRIDGE_DIR (or else install). Replace the simple import test with a Python check
that imports megatron.bridge, inspects megatron.bridge.__file__ (or uses
importlib to get the module path), resolves it to an absolute path and exits
nonzero if that path does not start with the absolute BRIDGE_DIR; keep the pip
install -e "${BRIDGE_DIR}" step to run when the path check fails. This ensures
the script uses the submodule under BRIDGE_DIR rather than an unrelated
site-packages version.

In
`@tools/launcher/examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml`:
- Line 26: Replace the hardcoded OUTPUT_DIR value with a launcher interpolation
variable: remove "/scratchspace/megatron-bridge" and set OUTPUT_DIR to use the
shared launcher global var (e.g., <<global_vars.OUTPUT_DIR>>); update any
accompanying docs/examples to reference the global var if needed and ensure the
global_vars entry is defined in the launcher YAML set so the
megatron_bridge_import.yaml's OUTPUT_DIR uses <<global_vars.OUTPUT_DIR>> instead
of the literal path.

---

Nitpick comments:
In `@tools/launcher/launch.py`:
- Line 74: The hardcoded repeat count in the relative_path assignment
(relative_path=[LAUNCHER_DIR] * 12) can get out of sync with include_pattern;
change it to derive the repeat length from the include_pattern (e.g.
relative_path=[LAUNCHER_DIR] * len(include_pattern) or equivalent) so that
relative_path size always matches include_pattern length (reference variables:
relative_path, LAUNCHER_DIR, include_pattern).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3c1a8d8d-8cbf-4959-8dc3-ee644e8af2e1

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4f4cc and e5c6b67.

📒 Files selected for processing (6)
  • .gitmodules
  • tools/launcher/common/megatron_bridge/import/import.sh
  • tools/launcher/examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml
  • tools/launcher/launch.py
  • tools/launcher/modules/Megatron-Bridge
  • tools/launcher/modules/Megatron-LM

Comment thread tools/launcher/common/megatron_bridge/import/import.sh Outdated
@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.77%. Comparing base (48fbac0) to head (60939b4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1516      +/-   ##
==========================================
+ Coverage   76.70%   76.77%   +0.06%     
==========================================
  Files         477      477              
  Lines       51977    51977              
==========================================
+ Hits        39869    39903      +34     
+ Misses      12108    12074      -34     
Flag Coverage Δ
regression 15.23% <ø> (+0.06%) ⬆️
unit 52.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tools/launcher/common/megatron_bridge/import/import.sh
jenchen13 added 2 commits May 26, 2026 08:56
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
@jenchen13
jenchen13 requested a review from kevalmorabia97 May 27, 2026 14:20
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>

@coderabbitai coderabbitai 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.

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tools/launcher/core.py (1)

139-145: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Define and maintain explicit module exports for this new public field.

GlobalVariables gained output_dir at Line 145, but the module still does not define an explicit __all__ export surface. Please add/update __all__ so this public API expansion is intentional and stable.

As per coding guidelines, "Define the public API with __all__ at the top of each module and re-export via from .module import * in __init__.py files."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/launcher/core.py` around lines 139 - 145, Add or update the
module-level __all__ to explicitly declare the public API (including
"GlobalVariables") so the newly added GlobalVariables.output_dir is
intentionally exported; place __all__ at the top of the module and include all
other public names from this file, and ensure the package __init__.py re-exports
the module via "from .core import *" so consumers see the updated public
surface.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/launcher/core.py`:
- Line 145: Add a regression test that verifies the new global variable
global_vars.output_dir is interpolated into both args and env like the existing
hf_model checks: create a test (e.g., test_global_vars_output_dir_interpolation)
that sets global_vars.output_dir to a sample value, constructs a launcher/job
spec with args and env entries containing the token <<global_vars.output_dir>>,
runs the same interpolation routine used by the hf_model tests (the helper or
method those tests call), and assert that the token is replaced with the sample
path in both the args list and environment dict; mirror the structure and
assertions of the hf_model interpolation tests so the new test validates both
args and env interpolation for output_dir.

---

Outside diff comments:
In `@tools/launcher/core.py`:
- Around line 139-145: Add or update the module-level __all__ to explicitly
declare the public API (including "GlobalVariables") so the newly added
GlobalVariables.output_dir is intentionally exported; place __all__ at the top
of the module and include all other public names from this file, and ensure the
package __init__.py re-exports the module via "from .core import *" so consumers
see the updated public surface.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e25f9ee3-5962-4d2a-a763-49b32fcd1609

📥 Commits

Reviewing files that changed from the base of the PR and between 22d35bc and 338d268.

📒 Files selected for processing (2)
  • tools/launcher/core.py
  • tools/launcher/examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/launcher/examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml

Comment thread tools/launcher/core.py
hf_model: str = None
hf_data: str = None
hf_local: str = None
output_dir: str = None

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a regression test for <<global_vars.output_dir>> interpolation.

Line 145 introduces a new interpolated global var, but there’s no corresponding test case in the provided tools/launcher/tests/test_core.py snippets. Please add one test mirroring the existing hf_model interpolation checks for args/environment using output_dir.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/launcher/core.py` at line 145, Add a regression test that verifies the
new global variable global_vars.output_dir is interpolated into both args and
env like the existing hf_model checks: create a test (e.g.,
test_global_vars_output_dir_interpolation) that sets global_vars.output_dir to a
sample value, constructs a launcher/job spec with args and env entries
containing the token <<global_vars.output_dir>>, runs the same interpolation
routine used by the hf_model tests (the helper or method those tests call), and
assert that the token is replaced with the sample path in both the args list and
environment dict; mirror the structure and assertions of the hf_model
interpolation tests so the new test validates both args and env interpolation
for output_dir.

@kevalmorabia97 kevalmorabia97 left a comment

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.

Much cleaner.

@jenchen13
jenchen13 enabled auto-merge (squash) May 27, 2026 15:12
@jenchen13 jenchen13 changed the title Megatron-Bridge import example in launcher for Nemotron Super V3 Megatron-Bridge import example in launcher for Nemotron Super V3 [OMNIML-4827] May 27, 2026
@jenchen13
jenchen13 merged commit b49f9b9 into main May 27, 2026
40 checks passed
@jenchen13
jenchen13 deleted the jennifchen/mbridge_import branch May 27, 2026 15:36
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-05-27 15:37 UTC

jenchen13 added a commit that referenced this pull request May 27, 2026
### What does this PR do?

Type of change: New feature

Add Megatron-Bridge import example in launcher for Nemotron Super V3

### Usage

```python
# Usage:
#   update .env-slurm with environment variables
#   cd tools/launcher
#   uv run launch.py --yaml examples/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16/megatron_bridge_import.yaml --yes
```

### Testing
<!-- Mention how have you tested your change if applicable. -->

### Before your PR is "*Ready for review*"

Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).

Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(...,
weights_only=False)`, `pickle`, etc.).

- Is this change backward compatible?: ✅ / ❌ / N/A <!--- If ❌, explain
why. -->
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: ✅ / ❌ / N/A
<!--- Mandatory -->
- Did you write any new necessary tests?: ✅ / ❌ / N/A <!--- Mandatory
for new features or examples. -->
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅ / ❌ / N/A <!--- Only for new features, API changes, critical bug fixes
or backward incompatible changes. -->
- Did you get Claude approval on this PR?: ✅ / ❌ / N/A <!--- Run
`/claude review`. NVIDIA org members can self-trigger for complex
changes; orthogonal to CodeRabbit. -->

### Additional Information
<!-- E.g. related issue. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Megatron-Bridge Hugging Face→Megatron checkpoint import
(CPU-capable entrypoint) and an example pipeline for importing the
Nvidia Nemotron-3 Super 120B model.
  * Exposed an `output_dir` global variable for pipeline interpolation.

* **Chores**
  * Updated pinned Megatron-LM module.
  * Extended .gitignore to cover `.env*` variants.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/NVIDIA/Model-Optimizer/pull/1516?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
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