Skip to content

fix(quantization): accept QuantizeAlgorithmConfig in get_modelike_from_algo_cfg (#201)#1528

Merged
realAsma merged 1 commit into
mainfrom
oncallbot/fix-201
May 21, 2026
Merged

fix(quantization): accept QuantizeAlgorithmConfig in get_modelike_from_algo_cfg (#201)#1528
realAsma merged 1 commit into
mainfrom
oncallbot/fix-201

Conversation

@realAsma
Copy link
Copy Markdown
Contributor

@realAsma realAsma commented May 21, 2026

Fixes #201

get_modelike_from_algo_cfg was typed to accept QuantizeAlgoCfgType (which includes QuantizeAlgorithmConfig instances), but the body only handled list / str / None / dict and raised ValueError("Invalid config type") for QuantizeAlgorithmConfig instances. This broke the documented pattern of passing typed config objects (MaxCalibConfig, AWQLiteCalibConfig, etc.) via quant_config['algorithm'].

The fix pre-converts a QuantizeAlgorithmConfig instance to its model_dump() dict at function entry, so the existing dict path handles it unchanged. Two-line change; no new branch needed.

Verification: added a unit test in tests/unit/torch/quantization/test_mode.py that builds a MaxCalibConfig, calls get_modelike_from_algo_cfg on both the object and its equivalent dict, and asserts the two paths produce the same tuple. Also covers the list-of-object path.

Opened by OnCallBot on behalf of realAsma. Please review the diff before merging.

cc Chenjie Luo (module owner for torch.quantization)

Summary by CodeRabbit

  • New Features

    • get_modelike_from_algo_cfg now accepts configuration objects directly alongside existing input formats.
  • Tests

    • Added regression test to verify configuration object handling works correctly.

Review Change Stack

…m_algo_cfg (#201)

Signed-off-by: realAsma <akuriparambi@nvidia.com>
@realAsma realAsma requested a review from a team as a code owner May 21, 2026 21:38
@realAsma realAsma requested a review from meenchen May 21, 2026 21:38
@realAsma realAsma added the bug Something isn't working label May 21, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

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: 6e0a6a62-53b5-432f-824b-f80ab0bb2567

📥 Commits

Reviewing files that changed from the base of the PR and between c9098b6 and 2ade0e2.

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

📝 Walkthrough

Walkthrough

This PR resolves a type-hint discrepancy in get_modelike_from_algo_cfg by adding support for QuantizeAlgorithmConfig instances. The function now converts config objects to dictionaries before processing, and a regression test validates the new capability.

Changes

QuantizeAlgorithmConfig Input Support

Layer / File(s) Summary
Config object handling in get_modelike_from_algo_cfg
modelopt/torch/quantization/mode.py
get_modelike_from_algo_cfg now detects QuantizeAlgorithmConfig instances and converts them to dictionaries using model_dump() before proceeding with existing parsing logic.
Regression test for QuantizeAlgorithmConfig input
tests/unit/torch/quantization/test_mode.py
Test module imports MaxCalibConfig and get_modelike_from_algo_cfg, then verifies the function accepts config objects by comparing object-based and dict-based inputs for equality, asserting the dumped config appears in the result, and confirming list-wrapped inputs behave consistently.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately describes the main change: accepting QuantizeAlgorithmConfig instances in get_modelike_from_algo_cfg function.
Linked Issues check ✅ Passed The PR fully addresses issue #201 by implementing support for QuantizeAlgorithmConfig instances in get_modelike_from_algo_cfg and includes a comprehensive test.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the issue: the core fix in mode.py and the regression test in test_mode.py are both necessary and related.
Security Anti-Patterns ✅ Passed No security anti-patterns detected. Changes use safe model_dump() conversion; no torch.load, numpy.load, trust_remote_code, eval, exec, nosec, or new dependencies present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch oncallbot/fix-201

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-05-21 22:39 UTC

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.72%. Comparing base (c9098b6) to head (2ade0e2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1528      +/-   ##
==========================================
- Coverage   76.75%   76.72%   -0.03%     
==========================================
  Files         476      476              
  Lines       51811    51813       +2     
==========================================
- Hits        39767    39756      -11     
- Misses      12044    12057      +13     
Flag Coverage Δ
examples 41.63% <50.00%> (+0.90%) ⬆️
gpu 59.51% <50.00%> (-0.59%) ⬇️
regression 15.21% <0.00%> (+0.07%) ⬆️
unit 52.62% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@realAsma realAsma enabled auto-merge (squash) May 21, 2026 22:15
@realAsma realAsma merged commit b02e888 into main May 21, 2026
50 checks passed
@realAsma realAsma deleted the oncallbot/fix-201 branch May 21, 2026 22:39
jenchen13 pushed a commit that referenced this pull request May 27, 2026
…m_algo_cfg (#201) (#1528)

Fixes #201

`get_modelike_from_algo_cfg` was typed to accept `QuantizeAlgoCfgType`
(which includes `QuantizeAlgorithmConfig` instances), but the body only
handled list / str / None / dict and raised `ValueError("Invalid config
type")` for `QuantizeAlgorithmConfig` instances. This broke the
documented pattern of passing typed config objects (`MaxCalibConfig`,
`AWQLiteCalibConfig`, etc.) via `quant_config['algorithm']`.

The fix pre-converts a `QuantizeAlgorithmConfig` instance to its
`model_dump()` dict at function entry, so the existing dict path handles
it unchanged. Two-line change; no new branch needed.

Verification: added a unit test in
`tests/unit/torch/quantization/test_mode.py` that builds a
`MaxCalibConfig`, calls `get_modelike_from_algo_cfg` on both the object
and its equivalent dict, and asserts the two paths produce the same
tuple. Also covers the list-of-object path.

Opened by OnCallBot on behalf of realAsma. Please review the diff before
merging.

cc Chenjie Luo (module owner for torch.quantization)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* `get_modelike_from_algo_cfg` now accepts configuration objects
directly alongside existing input formats.

* **Tests**
* Added regression test to verify configuration object handling works
correctly.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/NVIDIA/Model-Optimizer/pull/1528?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: realAsma <akuriparambi@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_modelike_from_algo_cfg doesn't accept QuantizeAlgorithmConfig, but it's typing says it should

2 participants