Skip to content

fix: guard MoE branch when quantization_format is None - #2185

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/unified-export-hf-guard-moe-branch-when-quantization
Open

fix: guard MoE branch when quantization_format is None#2185
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:bugfix/unified-export-hf-guard-moe-branch-when-quantization

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Aug 13, 2026

Copy link
Copy Markdown

This PR addresses the following issue in modelopt/torch/export/unified_export_hf.py: guard MoE branch when quantization_format is None.

Changes

  • modelopt/torch/export/unified_export_hf.py: guard MoE branch when quantization_format is None.

Details

--- a/modelopt/torch/export/unified_export_hf.py
+++ b/modelopt/torch/export/unified_export_hf.py
@@ -1,5 +1,6 @@
-        # For MoE models update pre_quant_scale to average pre_quant_scale amongst experts
-        if is_moe(module) and (
-            quantization_format is not QUANTIZATION_NONE
-            and ("awq" in quantization_format or quantization_format == QUANTIZATION_NVFP4_SVDQUANT)
-        ):
+        # For MoE models update pre_quant_scale to average pre_quant_scale amongst experts
+        if is_moe(module) and (
+            quantization_format is not None
+            and quantization_format != QUANTIZATION_NONE
+            and ("awq" in quantization_format or quantization_format == QUANTIZATION_NVFP4_SVDQUANT)
+        ):

Tests

  • tests/torch/export/test_unified_export_hf.py
--- /dev/null
+++ b/tests/torch/export/test_unified_export_hf.py
@@ -0,0 +1,41 @@
+import unittest
+from unittest.mock import patch
+
+from modelopt.torch.export.unified_export_hf import requantize_resmooth_fused_llm_layers
+
+
+class TestRequantizeResmoothFusedLLMLayers(unittest.TestCase):
+    def test_moe_branch_handles_none_quantization_format(self):
+        """Regression: MoE branch must not raise TypeError when quantization_format is None."""
+        class FakeModel:
+            pass
+
+        moe_module = object()
+        model = FakeModel()
+        model.named_modules = lambda: [("moe", moe_module)]
+
+        with patch(
+            "modelopt.torch.export.unified_export_hf.get_quantization_format",
+            return_value=None,
+        ) as mock_get_format, \
+            patch(
+            "modelopt.torch.export.unified_export_hf.is_moe",
+            return_value=True,
+        ) as mock_is_moe, \
+            patch(
+            "modelopt.torch.export.unified_export_hf.collect_shared_input_modules",
+            return_value=({}, {}),
+        ) as mock_collect, \
+            patch(
+            "modelopt.torch.export.unified_export_hf.fuse_prequant_to_linear",
+        ) as mock_fuse:
+            requantize_resmooth_fused_llm_layers(model)
+
+        mock_get_format.assert_called_once_with(model)
+        mock_is_moe.assert_called_once_with(moe_module)
+        mock_fuse.assert_not_called()
+        mock_collect.assert_called_once()

Contributor guidelines

Per this repo's CONTRIBUTING.md:

  • All commits are signed off (Signed-off-by trailer, DCO).

Summary by CodeRabbit

  • Bug Fixes
    • Improved MoE pre-quantization handling when no quantization format is specified.
    • Preserved existing AWQ and SVDQuant processing behavior.

Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
@andrewwhitecdw
andrewwhitecdw requested a review from a team as a code owner August 13, 2026 00:11
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 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.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8d115bd5-207c-4daa-84b3-1ecaeae9406c

📥 Commits

Reviewing files that changed from the base of the PR and between b96841d and 2c976ec.

📒 Files selected for processing (1)
  • modelopt/torch/export/unified_export_hf.py

📝 Walkthrough

Walkthrough

The MoE pre-quantization resmoothing condition now requires a non-null quantization format before excluding QUANTIZATION_NONE. AWQ and SVDQuant handling remains unchanged.

Changes

MoE resmoothing

Layer / File(s) Summary
Quantization format guard
modelopt/torch/export/unified_export_hf.py
The resmoothing branch now checks that quantization_format is not None before comparing it with QUANTIZATION_NONE.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Mergeability Score: ⚪ Minimal · up to 2c976

This localized change prevents a TypeError when MoE export runs with no quantization format and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: meenchen


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Security Anti-Patterns ❓ Inconclusive The working tree has no diff, so PR-introduced security changes cannot yet be verified. Provide the PR base revision or an applicable git diff for changed modelopt/examples files.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: guarding the MoE branch when quantization_format is None.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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.

1 participant