Skip to content

Add module-specific AutoQuant search spaces#1949

Open
meenchen wants to merge 5 commits into
mainfrom
weimingc/autoquant-module-search-space
Open

Add module-specific AutoQuant search spaces#1949
meenchen wants to merge 5 commits into
mainfrom
weimingc/autoquant-module-search-space

Conversation

@meenchen

@meenchen meenchen commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Type of change

New feature.

Details

  • Add ordered module-name search-space rules with per-family candidate formats.
  • Allow BF16/no-quant to remain an internal scoring baseline while excluding it from LP selection.
  • Support truly fixed one-format groups, including routed experts that remain costed by active-MoE accounting.
  • Add a Qwen3.6 recipe with routed experts fixed to W4A16 NVFP4 and shared/self/linear attention searched over W4A16 NVFP4 and FP8.
  • Reject rules that partially split an existing runtime-fused AutoQuant group.

Qwen3.6 search-space comparison

Compared the default W4A16 NVFP4/FP8 search space against the module-specific recipe that fixes routed experts to W4A16 NVFP4 while shared experts, linear attention, and self attention search W4A16 NVFP4 versus FP8.

Both lanes use local raw gradient scoring, active-MoE cost accounting, batch size 1, code32k calibration, full parser-on LiveCodeBench (8 repeats), and full SciCode. Active GiB/token includes scale storage.

Target bits Active GiB/token, default -> W4 routed Attention BF16+FP8, default -> W4 routed LCB, default -> W4 routed SciCode, default -> W4 routed
5.8 2.1289 -> 2.0135 49.2% -> 80.0% 70.8150 -> 72.4945 (+1.6795 pp) 40.0518 -> 40.4216 (+0.3698 pp)
6.1 2.2342 -> 2.1070 61.5% -> 93.8% 72.5220 -> 73.5683 (+1.0463 pp) 39.1642 -> 39.3861 (+0.2219 pp)
6.4 2.3387 -> 2.2181 67.7% -> 79.2% 72.0540 -> 73.9813 (+1.9273 pp) 38.2027 -> 39.9038 (+1.7011 pp)
6.7 2.4392 -> 2.3173 72.3% -> 93.8% 72.5220 -> 73.4581 (+0.9361 pp) 38.7944 -> 39.6820 (+0.8876 pp)

BF16 references are 74.3667 LCB and 40.7914 SciCode, giving 1.0 percentage-point acceptance floors of 73.3667 and 39.7914. The W4-routed search space passes both benchmarks only at target 6.4; the default lane has no joint pass. Targets 6.1 and 6.7 pass LCB but miss the SciCode floor. Fixing the inexpensive routed-expert decision to W4 redirects the active-MoE budget toward always-active attention/shared-expert modules, improving accuracy while reducing active cost by about 0.12 GiB/token at the same nominal targets.

This is an end-to-end recipe comparison rather than an isolated one-factor solver ablation: the historical default lane used full linear/self-attention family decision grouping, while the module-specific lane used runtime-required grouping.

Testing

  • 282 focused AutoQuant, recipe-loader, and HF PTQ tests passed.
  • Pre-commit passed Ruff, mypy, Bandit, YAML formatting, and recipe validation.
  • Completed the four-target Qwen3.6 PTQ sweep and full parser-on LCB/SciCode evaluation summarized above.

Summary by CodeRabbit

  • New Features

    • Added module-specific search spaces for AutoQuantize, allowing different quantization candidates and no-quantation settings for selected module groups.
    • Added a Qwen3.6 MoE recipe with tailored quantization options for routed experts, shared experts, and attention modules.
    • Added checkpoint validation to ensure module-specific configurations are restored consistently.
  • Documentation

    • Updated AutoQuantize and Hugging Face PTQ documentation with module-specific configuration, baseline-format, and cost-accounting guidance.
  • Bug Fixes

    • Improved calibration isolation and validation for grouped module configurations.

Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 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 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

AutoQuantize module search spaces

Layer / File(s) Summary
Public module-space contract
modelopt/recipe/config.py, modelopt/torch/quantization/model_quant.py
Adds per-module search-space configuration and validates patterns, candidate formats, and allow_no_quant before passing normalized entries to the searcher.
Searcher and calibration execution
modelopt/torch/quantization/algorithms.py
Matches rules to runtime groups, controls no-quant solver choices, preserves cost denominators, isolates calibration changes, and validates checkpoint signatures.
Recipe and HF export wiring
modelopt_recipes/.../w4a16_nvfp4_fp8_module_spaces_at_6p0bits-active_moe.yaml, examples/hf_ptq/*, CHANGELOG.rst
Adds a Qwen module-space recipe and maps global and per-module candidate formats into Hugging Face export inputs and documentation.
Configuration and runtime validation
tests/examples/hf_ptq/*, tests/unit/recipe/*, tests/unit/torch/quantization/test_autoquant.py
Tests recipe loading, export mapping, canonical signatures, fixed module behavior, runtime-group validation, calibration isolation, and checkpoint replay.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AutoQuantize
  participant Searcher
  participant ModuleGroup
  participant QuantizerState
  AutoQuantize->>Searcher: submit module_search_spaces
  Searcher->>ModuleGroup: match patterns to runtime groups
  Searcher->>QuantizerState: apply calibration recipe
  QuantizerState-->>Searcher: restore active quantizers
  Searcher-->>AutoQuantize: resolve candidate configuration
Loading

Suggested reviewers: shengliangxu, realasma, juhi10071998, kevalmorabia97

🚥 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 summarizes the main change: adding module-specific AutoQuant search spaces.
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 No prohibited security patterns were added: scans found no torch.load(weights_only=False), numpy.load(allow_pickle=True), eval/exec, #nosec, or hardcoded trust_remote_code=True.
✨ 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 weimingc/autoquant-module-search-space

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

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-1949/

Built to branch gh-pages at 2026-07-09 23:58 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.85294% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.95%. Comparing base (66633d8) to head (4a25092).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
modelopt/torch/quantization/model_quant.py 83.33% 5 Missing ⚠️
modelopt/torch/quantization/algorithms.py 97.80% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1949       +/-   ##
===========================================
- Coverage   77.79%   56.95%   -20.85%     
===========================================
  Files         519      518        -1     
  Lines       57926    58413      +487     
===========================================
- Hits        45064    33267    -11797     
- Misses      12862    25146    +12284     
Flag Coverage Δ
unit 55.36% <94.85%> (+0.13%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
@meenchen meenchen self-assigned this Jul 9, 2026
meenchen added 2 commits July 9, 2026 16:17
Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
@meenchen meenchen marked this pull request as ready for review July 14, 2026 20:05
@meenchen meenchen requested review from a team as code owners July 14, 2026 20:05

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review (gpt-5.6-sol) — DM the bot to share feedback.

The implementation looks cohesive and well tested, and I did not find a concrete correctness regression in the module-specific candidate selection, fixed-group cost accounting, calibration isolation, fused-group validation, or checkpoint signature handling. The added YAML header follows the short SPDX style, but it does not match the complete canonical text in root LICENSE_HEADER, so this GitHub PR still needs human licensing sign-off under the review policy.

Design review: the problem is to let existing AutoQuantize runtime decision groups use family-specific candidate sets, including truly fixed quantized groups, without losing sensitivity baselines or active-MoE accounting. Plausible alternatives are (1) extending the repository's existing NAS SearchSpace/wildcard-rule machinery (modelopt/torch/nas/search_space.py), (2) expressing family overrides through the existing ordered QuantizeConfig.quant_cfg/last-match-wins mechanism plus pre-partitioned AutoQuant runs, or (3) keeping one global AutoQuant search and applying a fixed PTQ config to routed experts before/after it. Already-imported Pydantic/OmegaConf can model the declarative schema, while PuLP remains the existing solver; no dependency offers the AutoQuant-specific grouped scoring directly. The PR correctly extends the existing AutoQuant/Pydantic/PuLP path rather than creating a separate solver, and its Qwen3.6 evaluation provides strong motivation, but the PR body does not explicitly compare or reject the obvious in-repo NAS/wildcard and staged-PTQ alternatives. Because design review was required, please have the owner sign off or add that rationale to the PR body.

@kevalmorabia97 kevalmorabia97 requested review from shengliangxu and removed request for kevalmorabia97 July 14, 2026 20:10

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 3

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

Inline comments:
In `@modelopt/torch/quantization/algorithms.py`:
- Around line 911-943: Extend the checkpoint compatibility logic around
module_search_space_signature to also record and compare a signature for
config["quantization_formats"] whenever quantizer_states or candidate_stats are
restored. Reject mismatched current formats before reusing checkpoint state, and
explicitly define the behavior for legacy checkpoints that lack the stored
format signature, consistent with the existing module-search-space handling.

In `@modelopt/torch/quantization/model_quant.py`:
- Around line 522-550: Update the public validation in the quantization entry
point before calls to _process_quantization_formats: require global and
per-module quantization_formats inputs to be valid non-empty candidate
collections, rejecting strings, mappings, and empty lists explicitly. Replace
the optimization-removable assert on processed global formats with an explicit
validation error, and apply equivalent validation to each module_search_spaces
entry before normalization.

In `@tests/unit/torch/quantization/test_autoquant.py`:
- Around line 369-370: Move the model_quant import from inside
test_auto_quantize_fixed_module_isolated_from_unrelated_calibration to the
module-level imports at the top of the test file. Remove the function-local
import while preserving the test’s existing module reference and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4a55fb6d-15fa-4af8-b9d1-86163a14b061

📥 Commits

Reviewing files that changed from the base of the PR and between 66633d8 and 4a25092.

📒 Files selected for processing (10)
  • CHANGELOG.rst
  • examples/hf_ptq/README.md
  • examples/hf_ptq/hf_ptq.py
  • modelopt/recipe/config.py
  • modelopt/torch/quantization/algorithms.py
  • modelopt/torch/quantization/model_quant.py
  • modelopt_recipes/huggingface/qwen3_6_moe/auto_quantize/w4a16_nvfp4_fp8_module_spaces_at_6p0bits-active_moe.yaml
  • tests/examples/hf_ptq/test_hf_ptq_args.py
  • tests/unit/recipe/test_loader.py
  • tests/unit/torch/quantization/test_autoquant.py

Comment thread modelopt/torch/quantization/algorithms.py
Comment thread modelopt/torch/quantization/model_quant.py Outdated
Comment thread tests/unit/torch/quantization/test_autoquant.py Outdated
Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.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.

2 participants