support modelopt W4A16 & W4A4 NVFP4 export for grouped MoE weights#4566
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Megatron-Bridge’s ModelOpt export path to support W4A16 NVFP4 and improves NVFP4 export for MoE grouped expert weights by collecting richer quant metadata (including weight_scale_2), syncing metadata across EP/PP groups, and emitting vLLM fused-MoE tensor names during export.
Changes:
- Added W4A16 NVFP4 support to ModelOpt export (
quant_mode="w4a16_nvfp4") and updated exporter selection logic. - Reworked quant-metadata collection/mapping to pull metadata from the actual quantized module/weight (including
weight_scale_2) and to support grouped MoE expert metadata stacking + EP syncing. - Updated unit tests to cover new metadata mapping/quantization behaviors and adjusted patching for
is_quantized.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unit_tests/models/test_modelopt_utils.py | Adds/updates unit tests for NVFP4/W4A16 NVFP4 export, metadata collection/mapping, grouped MoE handling, and fused name emission. |
| tests/unit_tests/models/test_auto_bridge.py | Updates mocks/patches to align with lazy is_quantized import path. |
| src/megatron/bridge/models/conversion/modelopt_utils.py | Implements quant metadata collection (incl. weight_scale_2), grouped expert metadata stacking, fused MoE export naming, and W4A16 NVFP4 support. |
| src/megatron/bridge/models/conversion/auto_bridge.py | Extends ModelOpt export flow to support new quant modes, EP+PP metadata sync, and updated metadata lookup behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
LGTM |
|
Light review - LGTM Thorough ModelOpt NVFP4 / W4A16-NVFP4 export change for Nemotron-H MoE with pre-EP fused-expert quantization. The distributed logic (PP/EP metadata sync, shared-group fallback, byte-view EP all-gather, incomplete-family rejection) is intricate but matched by strong, targeted unit test coverage. Spot checks passed:
Minor observations (non-blocking):
Suggested test cases
|
|
Light review — LGTM Read the full diff across auto_bridge.py, model_bridge.py, modelopt_utils.py, and param_mapping.py. Large but carefully structured feature (W4A16 & W4A4 NVFP4 export for grouped MoE weights) with strong unit coverage. No critical or high-severity issues found. Correctness spot-checks that pass:
Minor (non-blocking): the export_hf_weights_modelopt docstring lists nvfp4 and w4a16_nvfp4; confirm the W4A4 mode string is documented since the title advertises W4A4. Suggested test cases (unit; run under uv run python -m pytest):
No perf tests impacted. |
- Extend AutoBridge.export_hf_weights_modelopt to support quant_mode="w4a16_nvfp4".
- Collect ModelOpt quant metadata from the actual quantized weight/module, including NVFP4 weight_scale_2.
- Map Megatron ModelOpt metadata onto exported HF names before quantization.
- Support grouped MoE expert exports by syncing EP metadata, stacking per-expert metadata, and emitting vLLM ModelOpt fused-MoE tensor names:
- *.experts.w13_weight
- *.experts.w13_weight_scale
- *.experts.w13_weight_scale_2
- *.experts.w2_weight
- *.experts.w2_weight_scale
- *.experts.w2_weight_scale_2
- Keep ignored weights unquantized and skip quantizer tensors during export.
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
|
/ok to test 816c5bf |
What does this PR do ?
support modelopt W4A16 & W4A4 NVFP4 export for grouped MoE weights
Changelog
GitHub Actions CI
See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information