Skip to content

fix: raise ValueError for unknown awq() algorithm instead of silent no-op#1908

Open
arham766 wants to merge 2 commits into
NVIDIA:mainfrom
arham766:fix/awq-unknown-algorithm
Open

fix: raise ValueError for unknown awq() algorithm instead of silent no-op#1908
arham766 wants to merge 2 commits into
NVIDIA:mainfrom
arham766:fix/awq-unknown-algorithm

Conversation

@arham766

@arham766 arham766 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Bug 2 in #1902: awq() silently no-ops on an unknown algorithm string (public all API; only the mtq.quantize config layer Literal-validates). Now raises ValueError before any model mutation, listing the valid algorithms. Internal callers audited: svdquant hardcodes awq_lite; mode.py values are pydantic-validated. Regression test asserts the raise and that the valid path still works.

Usage

N/A

Testing

Regression tests included (added to existing unit test files; each was verified to fail with the fix reverted). Full tests/unit/torch quantization+export+utils+opt battery passes locally with all sibling fixes applied (962 passed). Note: the test-suite PRs #1903-#1907 contain behavior-documenting NOTE tests that pin the OLD behavior fixed here — whichever lands second will be rebased to flip those assertions (happy to do so).

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅ (error-raising on previously-silent invalid input / warning removal / exception-path cleanup only)
  • 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
  • Did you get Claude approval on this PR?: N/A (external contributor)

Additional Information

Issue: #1902

Summary by CodeRabbit

  • Bug Fixes

    • Added early validation for unsupported AWQ algorithm values, now failing fast with a clear ValueError.
    • Improved calibration behavior when forward_loop isn’t provided in supported scenarios, emitting a UserWarning instead of failing unexpectedly.
  • Tests

    • Added a unit test to verify an invalid AWQ algorithm raises the expected error.
    • Added coverage to confirm the forward_loop=None warning behavior during AWQ calibration.

…o-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 NVIDIA#1902.

Signed-off-by: arham766 <arhamislam766@yahoo.com>
@arham766 arham766 requested review from a team as code owners July 5, 2026 20:40
@arham766 arham766 requested a review from sugunav14 July 5, 2026 20:40
@copy-pr-bot

copy-pr-bot Bot commented Jul 5, 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 Jul 5, 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: d7e29c2d-4f7d-439c-b389-cfca7ab9d442

📥 Commits

Reviewing files that changed from the base of the PR and between 2d8fc90 and a11b3cd.

📒 Files selected for processing (1)
  • modelopt/torch/quantization/model_calib.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • modelopt/torch/quantization/model_calib.py

📝 Walkthrough

Walkthrough

awq() now documents and enforces the allowed AWQ algorithm names, raising ValueError for unsupported values. The unit tests cover both the new failure path and the existing warning behavior when forward_loop is omitted.

Changes

AWQ Algorithm Validation

Layer / File(s) Summary
Validate algorithm argument and test coverage
modelopt/torch/quantization/model_calib.py, tests/unit/torch/quantization/test_calib.py
awq() adds a valid-algorithm guard and updated docstring, and the unit test imports awq to verify the invalid-value error and the forward_loop=None warning path.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 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 The title clearly matches the main change: awq() now raises a ValueError for unknown algorithms instead of silently no-oping.
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 Changed files add only AWQ validation/test code; scans found no torch.load/allow_pickle/trust_remote_code/eval/exec/nosec or new deps.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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.

🧹 Nitpick comments (1)
modelopt/torch/quantization/model_calib.py (1)

1158-1173: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider documenting algorithm and the new ValueError.

The docstring lists only model and forward_loop in Args, omitting algorithm and the fail-fast ValueError this change introduces. As per coding guidelines, "Document public APIs with docstrings, including examples when useful."

📝 Suggested docstring addition
     Args:
         model: Model to be calibrated.
         forward_loop: A callable which takes the model as argument and
             forwards calibration data through the model.
+        algorithm: One of "awq_lite", "awq_clip", or "awq_full".
+
+    Raises:
+        ValueError: If `algorithm` is not one of the supported values.
🤖 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 `@modelopt/torch/quantization/model_calib.py` around lines 1158 - 1173, Update
the apply AWQ public API docstring in model_calib.py to document the algorithm
parameter alongside model and forward_loop, and add a Raises section for the
ValueError thrown when algorithm is not one of awq_lite, awq_clip, or awq_full.
Use the existing apply AWQ function and its algorithm validation block as the
reference points, and keep the wording aligned with the current
AWQFullCalibConfig docs.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@modelopt/torch/quantization/model_calib.py`:
- Around line 1158-1173: Update the apply AWQ public API docstring in
model_calib.py to document the algorithm parameter alongside model and
forward_loop, and add a Raises section for the ValueError thrown when algorithm
is not one of awq_lite, awq_clip, or awq_full. Use the existing apply AWQ
function and its algorithm validation block as the reference points, and keep
the wording aligned with the current AWQFullCalibConfig docs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 578676b8-cc2f-4eb9-8f69-d6f6d20bd9c1

📥 Commits

Reviewing files that changed from the base of the PR and between b96a785 and 2d8fc90.

📒 Files selected for processing (2)
  • modelopt/torch/quantization/model_calib.py
  • tests/unit/torch/quantization/test_calib.py

Signed-off-by: arham766 <arhamislam766@yahoo.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.

1 participant