From 2d8fc90638dd5275f7bb1f5e21b2d12927a5dd12 Mon Sep 17 00:00:00 2001 From: arham766 Date: Sun, 5 Jul 2026 13:39:11 -0700 Subject: [PATCH 1/2] fix: raise ValueError for unknown awq() algorithm instead of silent no-op awq() checked the algorithm string with two if-in tests and no else, so a typo like "awq-lite" returned an uncalibrated model with no signal. awq is public API; only the mtq.quantize config layer validates the Literal. Raise before any model mutation, matching the module's fail-fast style. Internal callers audited: svdquant hardcodes a valid value and mode.py values are pydantic-validated. Part of the findings in #1902. Signed-off-by: arham766 --- modelopt/torch/quantization/model_calib.py | 6 ++++++ tests/unit/torch/quantization/test_calib.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/modelopt/torch/quantization/model_calib.py b/modelopt/torch/quantization/model_calib.py index 661f429b2f5..0b36a9b4d95 100644 --- a/modelopt/torch/quantization/model_calib.py +++ b/modelopt/torch/quantization/model_calib.py @@ -1165,6 +1165,12 @@ def awq( See :class:`AWQFullCalibConfig ` for details on the remaining arguments. """ + if algorithm not in ["awq_lite", "awq_clip", "awq_full"]: + raise ValueError( + f"Invalid AWQ algorithm {algorithm!r}. " + "Valid algorithms are 'awq_lite', 'awq_clip', and 'awq_full'." + ) + with SequentialQuantizer.convert_to_single_quantizer(model): if algorithm in ["awq_full", "awq_lite"]: awq_lite(model, forward_loop, **kwargs) diff --git a/tests/unit/torch/quantization/test_calib.py b/tests/unit/torch/quantization/test_calib.py index 9e58185e383..1aaaabe7605 100644 --- a/tests/unit/torch/quantization/test_calib.py +++ b/tests/unit/torch/quantization/test_calib.py @@ -26,6 +26,7 @@ from modelopt.torch.quantization.config import QuantizerAttributeConfig from modelopt.torch.quantization.model_calib import ( apply_pre_quant_scale_and_smooth, + awq, disable_pre_quant_scale_and_resmooth, layerwise_calibrate, ) @@ -391,6 +392,19 @@ def _forward_loop(m): ) +def test_awq_unknown_algorithm_raises(): + """awq() must fail fast on an unknown algorithm instead of silently skipping calibration.""" + model = _SimpleMLP() + + with pytest.raises(ValueError, match="Invalid AWQ algorithm 'awq-lite'"): + awq(model, algorithm="awq-lite") + + # Valid algorithm strings still go through: awq_lite without a forward_loop + # warns and skips instead of raising. + with pytest.warns(UserWarning, match="forward_loop must be provided"): + awq(model, forward_loop=None, algorithm="awq_lite") + + def test_smoothquant_enable_disable(): torch.manual_seed(1234) model = _SimpleMLP() From a11b3cd9db7a7d2604aab11d69522a52bbfb334f Mon Sep 17 00:00:00 2001 From: arham766 Date: Sun, 5 Jul 2026 19:12:56 -0700 Subject: [PATCH 2/2] docs: document the algorithm arg and the fail-fast ValueError in awq() Signed-off-by: arham766 --- modelopt/torch/quantization/model_calib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modelopt/torch/quantization/model_calib.py b/modelopt/torch/quantization/model_calib.py index 0b36a9b4d95..7a01c3f4559 100644 --- a/modelopt/torch/quantization/model_calib.py +++ b/modelopt/torch/quantization/model_calib.py @@ -1161,6 +1161,11 @@ def awq( model: Model to be calibrated. forward_loop: A callable which takes the model as argument and forwards calibration data through the model. + algorithm: The AWQ variant to run; one of ``"awq_lite"``, + ``"awq_clip"``, or ``"awq_full"``. + + Raises: + ValueError: If ``algorithm`` is not one of the valid AWQ algorithms. See :class:`AWQFullCalibConfig ` for details on the remaining arguments.