Skip to content

fix: handle list-format quant_cfg from ModelOpt PR #1094 - #4187

Merged
jenchen13 merged 12 commits into
NVIDIA:mainfrom
ChenhanYu:chenhany/fix-quant-cfg-list-format
Apr 28, 2026
Merged

fix: handle list-format quant_cfg from ModelOpt PR #1094#4187
jenchen13 merged 12 commits into
NVIDIA:mainfrom
ChenhanYu:chenhany/fix-quant-cfg-list-format

Conversation

@ChenhanYu

Copy link
Copy Markdown
Contributor

ModelOpt PR #1094 changed quant_cfg from a flat dict keyed by quantizer name to an ordered list of QuantizerCfgEntry dicts with an explicit 'quantizer_name' field. quantize.py was directly indexing the dict (e.g. quant_cfg['medusa_heads*'] = ...) which crashes with a TypeError when quant_cfg is a list.

Add _set_quant_cfg_entry() and _get_quant_cfg_entry() helpers that write to and read from either format, and update all call sites in get_modelopt_torch_quantization_config(), get_first_layers_disabled_config(), and get_last_layers_disabled_config() to use them.

What does this PR do ?

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact the @mcore-oncall.

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@copy-pr-bot

copy-pr-bot Bot commented Apr 7, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft April 7, 2026 21:43
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@ChenhanYu
ChenhanYu force-pushed the chenhany/fix-quant-cfg-list-format branch 2 times, most recently from cf20883 to 7d8d36f Compare April 8, 2026 04:42
@ChenhanYu
ChenhanYu force-pushed the chenhany/fix-quant-cfg-list-format branch from 1550efc to 8bc5455 Compare April 15, 2026 03:36
@copy-pr-bot

copy-pr-bot Bot commented Apr 15, 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.

ChenhanYu and others added 3 commits April 20, 2026 14:38
ModelOpt PR NVIDIA#1094 changed quant_cfg from a flat dict keyed by quantizer
name to an ordered list of QuantizerCfgEntry dicts with an explicit
'quantizer_name' field.  quantize.py was directly indexing the dict
(e.g. quant_cfg['*medusa_heads**'] = ...) which crashes with a TypeError
when quant_cfg is a list.

Add _set_quant_cfg_entry() and _get_quant_cfg_entry() helpers that write
to and read from either format, and update all call sites in
get_modelopt_torch_quantization_config(), get_first_layers_disabled_config(),
and get_last_layers_disabled_config() to use them.

Signed-off-by: chenhany <chenhany@nvidia.com>
ModelOpt PR NVIDIA#1094 changed QuantizerCfgEntry to require quantizer attributes
under a 'cfg' sub-key rather than at the top level. Update fp8_config and
fp4_config in quantize.py accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
initialize_megatron() and pretrain() no longer accept
extra_args_provider and args_defaults after commit 97aca2f.
Use parse_and_validate_args() from megatron.training.arguments
to parse args before calling initialize_megatron()/pretrain().

Affected files:
- quantize.py, validate.py, prune.py, mmlu.py, export.py
- convert_model.py, offline_feature_extract.py, generate.py
- finetune.py (uses pretrain() instead of initialize_megatron())

Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
@ChenhanYu
ChenhanYu force-pushed the chenhany/fix-quant-cfg-list-format branch from 8bc5455 to c11adb0 Compare April 20, 2026 21:51
…ency-ext

Some container versions renamed get_write_results_queue to
_get_write_results_queue. Add fallback import to handle both.
Set DISABLE_NVRX=1 to force HAVE_NVRX=False and use mcore's own
checkpoint implementation. Workaround for containers where nvrx is
incompatible with the installed PyTorch version.
nvidia-resiliency-ext's FileSystemWriterAsync is incompatible with
some container PyTorch versions. DISABLE_NVRX forces mcore fallback.
@jenchen13
jenchen13 self-requested a review April 21, 2026 16:08
#!/bin/bash

# Disable nvidia-resiliency-ext (incompatible with some container PyTorch versions)
export DISABLE_NVRX=1

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.

can you add this in arguments.sh instead of in multiple places?


ModelOpt PR #1094 changed quant_cfg from a flat dict keyed by quantizer name
to an ordered list of QuantizerCfgEntry dicts with an explicit "quantizer_name"
field. This helper writes to either format so callers don't need to branch.

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.

could this be moved to ModelOpt quant cfg class to add get/set functions so that it is backward compatible?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The old format is problematic and deprecated, but backward compatibility is kept:

The ModelOpt code automatically convert the old formatted configs into new format configs at the time parsing the config

The issues we were hitting are from code manipulating the old formatted configs, such as updating quantization format of one quantizer. These code is not in consideration for backward compatibility.

We do not want to bring those manipulation code back into modelopt library.

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.

I've updated the code to convert from old dict format to list format if it detects an old modelopt config, and to only manipulate list configs

jenchen13 and others added 4 commits April 27, 2026 11:43
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
@jenchen13
jenchen13 requested a review from shengliangxu April 27, 2026 19:38
@jenchen13
jenchen13 marked this pull request as ready for review April 27, 2026 19:38
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team April 27, 2026 19:38
@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Apr 27, 2026
@jenchen13
jenchen13 requested review from AAnoosheh, kevalmorabia97 and shengliangxu and removed request for shengliangxu April 27, 2026 19:41
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
@jenchen13

Copy link
Copy Markdown
Contributor

/ok to test a62125b

@jenchen13
jenchen13 added this pull request to the merge queue Apr 28, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25056285782

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25056874744

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 28, 2026
@jenchen13
jenchen13 added this pull request to the merge queue Apr 28, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25068932293

Merged via the queue into NVIDIA:main with commit 9816140 Apr 28, 2026
69 checks passed
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
…A#4187)

Signed-off-by: chenhany <chenhany@nvidia.com>
Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Jennifer Chen <jennifchen@nvidia.com>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
…A#4187)

Signed-off-by: chenhany <chenhany@nvidia.com>
Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Jennifer Chen <jennifchen@nvidia.com>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
…A#4187)

Signed-off-by: chenhany <chenhany@nvidia.com>
Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Jennifer Chen <jennifchen@nvidia.com>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
…A#4187)

Signed-off-by: chenhany <chenhany@nvidia.com>
Signed-off-by: Chenhan Yu <chenhany@nvidia.com>
Signed-off-by: Jennifer Chen <jennifchen@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Jennifer Chen <jennifchen@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants