Skip to content

Add ModelOpt QAD skill for Slurm workflows - #2010

Open
mxinO wants to merge 17 commits into
mainfrom
mxin/qad-skill
Open

Add ModelOpt QAD skill for Slurm workflows#2010
mxinO wants to merge 17 commits into
mainfrom
mxin/qad-skill

Conversation

@mxinO

@mxinO mxinO commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new feature

Adds a general Slurm-only QAD skill based on the supported Megatron Bridge
workflow. The skill:

  • starts from a measured BF16-to-PTQ benchmark gap and preserves the preceding
    PTQ configuration or recipe;
  • gates QAD on exact Megatron Bridge model support and successful Megatron PTQ,
    using its master-rank quantizer summary as a scoped amax sanity check;
  • requires model- and hardware-derived TP/PP/CP/EP/ETP topology selection;
  • streams and randomly samples only the required
    nvidia/Nemotron-Cascade-2-SFT-Data token budget and uses Megatron sequence
    packing;
  • defaults to 32K sequences, LR 1e-5 with cosine decay, a 1000-step cap, and
    GBS 512;
  • requires explicit user authorization because QAD is costly, validates two
    batches every 25 steps, saves every 50 steps, and monitors a decreasing
    smoothed loss trend;
  • evaluates an early checkpoint around step 150 and continues only when
    benchmark recovery and the loss trend justify more training;
  • follows the established common Slurm and remote-execution guidance instead of
    duplicating mutable commands from the Megatron Bridge README.

Also exposes Megatron Bridge save_interval, exit_interval, and
exit_duration_in_mins through examples/megatron_bridge/distill.py, with example-test coverage for checkpoint
and ModelOpt-state preservation at an early exit.

Usage

Use the QAD skill to recover the measured BF16-to-PTQ benchmark gap for
<model> on <Slurm cluster>, preserving the validated PTQ recipe.

Testing

  • PYTHONPATH=$PWD pre-commit run --all-files
    • Passed every hook on the rebased branch, including Ruff, Ruff format, mypy,
      YAML/recipe validation, launcher reference validation, Bandit, generated
      arguments, symlink synchronization, and Markdown lint.
  • python ~/.codex/skills/.system/skill-creator/scripts/quick_validate.py .agents/skills/qad
    • Skill is valid!

Qwen3-0.6B result-bearing validation:

  • Resources: one exclusive node, 8 H100 GPUs

  • Container: nvcr.io/nvidia/nemo:26.06

  • Quantization: NVFP4, group size 16, embedding excluded

  • QAD topology: TP=1, PP=1, CP=4, EP=1, DP=2

  • Training validation configuration: sequence length 32768, MBS=1, GBS=8,
    train_iters=1000, LR 1e-5 / minimum LR 1e-6, 50 warmup iterations,
    cosine decay, eval_interval=150, exit_interval=150,
    exit_duration_in_mins=220

  • This result-bearing run used the then-current coupled eval/save cadence. The
    final skill now validates two batches every 25 steps and saves every 50; the
    example test covers the independent checkpoint cadence.

  • The reduced GBS 8 is intentionally validation-only; the skill retains GBS 512
    as the production default.

  • Data: exactly 10,000,000 sampled tokens from four
    nvidia/Nemotron-Cascade-2-SFT-Data configs:

    • math: 2,306,011 tokens / 364 documents
    • science: 1,191,257 tokens / 285 documents
    • chat: 6,142,077 tokens / 1,800 documents
    • instruction following: 360,655 tokens / 411 documents
  • Megatron built packed 32K GPT samples from the materialized prefixes; the full
    dataset was not downloaded.

  • QAD loss was finite and decreased from 0.2640341 at iteration 10 to
    0.1060580 at iteration 150. Final gradient norm was 0.747, with zero
    skipped and zero NaN iterations. Validation distillation loss was
    0.09715855.

  • The iteration-150 checkpoint saved successfully with modelopt_state, and
    both PTQ and QAD-150 exported to unified Hugging Face format.

  • Identical full MMLU 0-shot comparison through the Megatron evaluator:

    Model Accuracy
    BF16 0.39517164
    PTQ 0.32851446
    QAD-150 0.38740921

    QAD-150 recovered 0.05889475 / 0.06665718 = 88.35% of the measured PTQ gap,
    so validation stopped at the early evidence gate rather than continuing
    blindly toward 1000 iterations.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • 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?: ✅
  • Did you update Changelog?: N/A — this adds an agent skill and example-only
    lifecycle flags.
  • Did you get Claude approval on this PR?: N/A

Additional Information

All seven branch commits are cryptographically signed and include a
Signed-off-by trailer.

Summary by CodeRabbit

  • New Features
    • Updated the QAD skill documentation with a clear “Execute in this order” workflow, including a revised default recovery training policy.
    • Added a new nemotron-cascade-2 dataset blend configuration with an increased token budget.
    • Enhanced the MeGatron Bridge distillation CLI with stricter interval argument validation and support for configurable save-and-exit controls.
  • Documentation
    • Expanded Megatron Bridge README guidance for dataset preparation, token-budget recalculation, and resume expectations.
  • Tests
    • Improved distillation and QAD tests to validate early-exit behavior and checkpoint expectations.
    • Added unit tests covering distillation CLI interval validation.

mxinO added 5 commits July 23, 2026 13:03
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 an authorized Slurm-based QAD workflow, a materialized Nemotron Cascade dataset blend, and configurable distillation save/exit controls. Tests cover CLI validation, zero evaluation iterations, early termination, and checkpoint state.

Changes

QAD workflow support

Layer / File(s) Summary
QAD workflow definition
.agents/skills/qad/SKILL.md, .claude/skills/qad
Defines authorized PTQ-gap recovery, topology constraints, QAD execution, monitoring, resume rules, recovery criteria, evidence reporting, and the shared Claude skill link.
Materialized QAD data preparation
examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml, examples/megatron_bridge/README.md
Adds the eight-source Nemotron Cascade blend with a 17.3B-token budget and documents packed 32K data, the validation holdout, and resume requirements.
Distillation checkpoint and exit controls
examples/megatron_bridge/distill.py, tests/examples/megatron_bridge/test_distill.py, tests/examples/megatron_bridge/test_qad.py
Adds validated interval arguments, configurable save and exit controls, and tests for argument handling, early termination, and checkpoint state.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: chenhanyu, jenchen13

Sequence Diagram(s)

sequenceDiagram
  participant DistillCLI
  participant TrainingConfig
  participant CheckpointConfig
  participant CheckpointFilesystem
  DistillCLI->>TrainingConfig: pass exit interval and duration
  DistillCLI->>CheckpointConfig: select save interval
  TrainingConfig->>CheckpointFilesystem: save checkpoint and exit
  CheckpointFilesystem-->>DistillCLI: report latest checkpointed iteration
Loading
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly describes the main change: adding a ModelOpt QAD skill for Slurm-based workflows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 No modelopt/examples Python or dependency files changed in HEAD^..HEAD; the only diff is a markdown skill file, so no critical security anti-patterns were introduced.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mxin/qad-skill

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

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.82%. Comparing base (c94405e) to head (7850116).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2010      +/-   ##
==========================================
+ Coverage   60.21%   61.82%   +1.60%     
==========================================
  Files         519      519              
  Lines       59377    59377              
==========================================
+ Hits        35755    36709     +954     
+ Misses      23622    22668     -954     
Flag Coverage Δ
examples 33.16% <ø> (+2.05%) ⬆️
unit 55.14% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

mxinO added 4 commits July 23, 2026 13:37
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>

# Conflicts:
#	examples/megatron_bridge/distill.py
Signed-off-by: Meng Xin <mxin@nvidia.com>
@mxinO
mxinO marked this pull request as ready for review July 28, 2026 01:10
@mxinO
mxinO requested review from a team as code owners July 28, 2026 01:10

@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: 2

🧹 Nitpick comments (1)
.agents/skills/qad/assets/nemotron-cascade-2-blend.yaml (1)

5-43: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Pin the dataset revision for reproducible data.

All entries use the floating nvidia/Nemotron-Cascade-2-SFT-Data identifier without a revision, while .agents/skills/qad/SKILL.md Lines 206-209 require reporting an exact source revision. Pin the revision in the blend schema if supported, or capture and validate the resolved revision in the generated artifact.

🤖 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 @.agents/skills/qad/assets/nemotron-cascade-2-blend.yaml around lines 5 - 43,
Pin every nvidia/Nemotron-Cascade-2-SFT-Data entry in the blend configuration to
an immutable dataset revision using the schema’s supported revision field. If
the blend schema cannot express revisions, update the generation flow to record
and validate the resolved revision in the output artifact, preserving the
requirement from SKILL.md for an exact source revision.
🤖 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 @.agents/skills/qad/SKILL.md:
- Around line 160-164: Update the initial-stage instructions around the training
configuration and the QAD-150 export/evaluation steps to record the actual exit
iteration, distinguish duration-triggered exits before iteration 150, and run
the 150-step gate only when checkpoint 150 exists; otherwise mark the stage
incomplete and direct the operator to resume or relaunch instead of labeling an
earlier checkpoint as QAD-150.

In `@examples/megatron_bridge/distill.py`:
- Around line 164-184: Validate eval_interval, eval_iters, save_interval,
exit_interval, and exit_duration_in_mins immediately after CLI parsing,
rejecting zero or negative values before they reach scheduling or validation
logic; if any zero value is intentionally supported as a disable sentinel,
handle it explicitly and consistently instead.

---

Nitpick comments:
In @.agents/skills/qad/assets/nemotron-cascade-2-blend.yaml:
- Around line 5-43: Pin every nvidia/Nemotron-Cascade-2-SFT-Data entry in the
blend configuration to an immutable dataset revision using the schema’s
supported revision field. If the blend schema cannot express revisions, update
the generation flow to record and validate the resolved revision in the output
artifact, preserving the requirement from SKILL.md for an exact source revision.
🪄 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: 8c080adc-5bf5-4c53-95fb-5a0e5b8a1bad

📥 Commits

Reviewing files that changed from the base of the PR and between 33d05b0 and 95e29fa.

📒 Files selected for processing (5)
  • .agents/skills/qad/SKILL.md
  • .agents/skills/qad/assets/nemotron-cascade-2-blend.yaml
  • .claude/skills/qad
  • examples/megatron_bridge/distill.py
  • tests/examples/megatron_bridge/test_qad.py

Comment thread .agents/skills/qad/SKILL.md Outdated
Comment thread examples/megatron_bridge/distill.py Outdated
Comment thread examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml
mxinO added 3 commits July 29, 2026 07:49
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@nvidia.com>
@mxinO
mxinO requested a review from jenchen13 July 29, 2026 08:25

@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

🧹 Nitpick comments (1)
tests/examples/megatron_bridge/test_distill.py (1)

68-69: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the exit code directly.

match="2" performs a regex match against the exception text and is not an exact code assertion. Capture the exception and check exc_info.value.code == 2.

🤖 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 `@tests/examples/megatron_bridge/test_distill.py` around lines 68 - 69, Update
the get_args test to capture the SystemExit exception from distill.get_args()
and assert that exc_info.value.code equals 2, replacing the regex-based
match="2" check while preserving the expected SystemExit behavior.
🤖 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 `@tests/examples/megatron_bridge/test_distill.py`:
- Around line 45-48: Move the dynamic distill import out of both test bodies and
load the module once at file scope, after making the example directory
importable. Remove the duplicated importlib.import_module calls from
test_distill_rejects_invalid_intervals and the other test, preserving their
existing test behavior; only retain dynamic loading if a documented optional or
circular dependency requires it.

---

Nitpick comments:
In `@tests/examples/megatron_bridge/test_distill.py`:
- Around line 68-69: Update the get_args test to capture the SystemExit
exception from distill.get_args() and assert that exc_info.value.code equals 2,
replacing the regex-based match="2" check while preserving the expected
SystemExit behavior.
🪄 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: 5638b3cc-36d5-46f8-a5bf-961199ff07aa

📥 Commits

Reviewing files that changed from the base of the PR and between 62fda52 and 1688751.

📒 Files selected for processing (3)
  • .agents/skills/qad/SKILL.md
  • examples/megatron_bridge/distill.py
  • tests/examples/megatron_bridge/test_distill.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/megatron_bridge/distill.py
  • .agents/skills/qad/SKILL.md

Comment thread tests/examples/megatron_bridge/test_distill.py Outdated
Comment thread .agents/skills/qad/SKILL.md Outdated
Comment thread .agents/skills/qad/SKILL.md
Comment thread .agents/skills/qad/SKILL.md Outdated
Signed-off-by: Meng Xin <mxin@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)
examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml (1)

5-45: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Add a dataset revision to each Hugging Face source
prepare_megatron_data_blend.py forwards hf_dataset/hf_name/hf_split with streaming and no revision field, so these sources can drift and make BF16/PTQ/QAD runs non-reproducible. Add a revision key here and thread it through, or persist the resolved commit in the generated artifact.

🤖 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 `@examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml` around lines 5 -
45, Add an explicit Hugging Face revision to every source entry in the YAML
blend, using the same pinned revision for the Nemotron-Cascade-2-SFT-Data
dataset. Ensure prepare_megatron_data_blend.py propagates each source’s revision
through the streaming load path, or records the resolved commit in the generated
artifact so runs remain reproducible.
🤖 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 @.agents/skills/qad/SKILL.md:
- Around line 96-101: Update the Megatron resume policy in the recovery
instructions to allow extending or removing the duration-based exit limit when a
later recovery target requires more time. Continue preserving prepared data,
checkpoint lineage, optimizer/scheduler state, iteration, consumed samples,
topology, and all other training arguments; retain the absolute exit_interval
only when sufficient.

---

Outside diff comments:
In `@examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml`:
- Around line 5-45: Add an explicit Hugging Face revision to every source entry
in the YAML blend, using the same pinned revision for the
Nemotron-Cascade-2-SFT-Data dataset. Ensure prepare_megatron_data_blend.py
propagates each source’s revision through the streaming load path, or records
the resolved commit in the generated artifact so runs remain reproducible.
🪄 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: d29c7d8f-3e17-4f3d-b6c0-fd303c6a1c75

📥 Commits

Reviewing files that changed from the base of the PR and between 1688751 and 49a456d.

📒 Files selected for processing (4)
  • .agents/skills/qad/SKILL.md
  • examples/megatron_bridge/README.md
  • examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml
  • tests/examples/megatron_bridge/test_distill.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/megatron_bridge/README.md

Comment thread .agents/skills/qad/SKILL.md Outdated
mxinO added 2 commits July 30, 2026 03:25
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@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.

Caution

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

⚠️ Outside diff range comments (1)
.agents/skills/qad/SKILL.md (1)

45-53: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Constrain ETP to the supported value of 1.

examples/megatron_bridge/distill.py hard-sets provider.expert_tensor_parallel_size = 1 because expert tensor parallelism is unsupported. This skill currently lets operators derive/select ETP and uses it in the EDP calculation; choosing ETP > 1 will therefore be silently overridden, making the documented topology and sizing checks inconsistent with the actual launch.

Proposed clarification
- derive the smallest fitting node count and TP/PP/CP/EP/ETP from
+ derive the smallest fitting node count and TP/PP/CP/EP from
  student and teacher architecture, 32K activation memory,
  and available GPU memory.
...
- EDP = world_size / (ETP * EP * PP)
+ ETP = 1; EDP = world_size / (EP * PP)
🤖 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 @.agents/skills/qad/SKILL.md around lines 45 - 53, Update the topology
guidance in “Choose topology explicitly” to require ETP = 1, remove ETP as a
selectable/derived value, and simplify the EDP calculation to use the fixed
supported value. Keep the existing integrality and expert-count checks
consistent with this constraint, matching the hard-coded setting in distill.py.
🤖 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.

Outside diff comments:
In @.agents/skills/qad/SKILL.md:
- Around line 45-53: Update the topology guidance in “Choose topology
explicitly” to require ETP = 1, remove ETP as a selectable/derived value, and
simplify the EDP calculation to use the fixed supported value. Keep the existing
integrality and expert-count checks consistent with this constraint, matching
the hard-coded setting in distill.py.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bfc1d9f2-5710-4e18-911d-568d0da8ecec

📥 Commits

Reviewing files that changed from the base of the PR and between 49a456d and 23e83d7.

📒 Files selected for processing (1)
  • .agents/skills/qad/SKILL.md

mxinO added 2 commits July 30, 2026 04:16
Signed-off-by: Meng Xin <mxin@nvidia.com>
Signed-off-by: Meng Xin <mxin@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.

4 participants