Skip to content

[3/5] Fold grouped expert weights during fakequant export - #2628

Merged
kinjalpatel27 merged 1 commit into
mainfrom
kinjal/vllm-fq-grouped-export
Oct 14, 2026
Merged

kinjalpatel27 merged 1 commit into
mainfrom
kinjal/vllm-fq-grouped-export

Conversation

@kinjalpatel27

@kinjalpatel27 kinjalpatel27 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Megatron's grouped expert slicer reads module.state_dict(). The ordinary fakequant export path folded a separate weight copy, so the slicer could still export unfolded expert weights. This change uses a temporary state-dict post-hook in the fakequant plugin to supply QDQ-folded grouped weights to that slicer, then removes the hook after export. The shared unified exporter remains unchanged in this PR.

Usage

No API change. Existing export_mcore_gpt_to_hf_vllm_fq(...) calls export folded grouped expert weights.

Testing

  • Focused grouped export tests cover CPU and CUDA paths.
  • Distributed EP=2 export test compares every exported expert projection weight with independently QDQ-folded weights; passed on the current PR 2 base.
  • CI is pending for this draft.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md?: N/A (no new runtime dependency or copied code)
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A (fix to the unreleased fakequant export path)
  • Did you get Claude approval on this PR?: N/A (draft; review not requested yet)

Additional Information

Part of a five-PR stack. Merge in numeric order.

Stack

Merge in this order:

  1. CLI wrapper and app entry point
  2. Megatron quantizer sidecars
  3. Grouped expert weight folding
  4. Automatic fakequant reload
  5. HF source config preservation

Summary by CodeRabbit

  • New Features
    • vLLM exports now apply fake quantization to grouped expert weights, including weights from expert-parallel exports.
    • Grouped expert exports support FP8 on CPU and NVFP4 on CUDA.
  • Bug Fixes
    • Export preserves model state and hooks when quantization fails, so a subsequent export can succeed.
  • Tests
    • Added coverage for grouped expert exports, quantizer behavior, and shared checkpoints across expert-parallel ranks.

@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: cd8c7817-1054-4fd4-ab84-113a831eb6a2
📥 Commits

Reviewing files that changed from the base of the PR and between 30cbb9a and 26197f2.

📒 Files selected for processing: 2
  • modelopt/torch/export/plugins/vllm_fakequant_megatron.py
  • tests/gpu_megatron/torch/export/test_vllm_fakequant_megatron_export.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

📝 Walkthrough

The exporter now fake-quantizes grouped expert weights during state-dict construction and skips ordinary weight fake-quantization for those modules. Tests cover FP8 and NVFP4 export, export cleanup after failure, and expert-parallel checkpoint weights.

Changes: Grouped fake-quant export

Layer / File(s) Summary
Grouped-weight folding
modelopt/torch/export/plugins/vllm_fakequant_megatron.py
Temporary state-dict hooks fake-quantize present grouped weights. A shared helper applies weight fake-quantization with the requested dtype and device. The ordinary weight path skips modules handled by the grouped hook.
Grouped and expert-parallel export validation
tests/gpu_megatron/torch/export/test_vllm_fakequant_megatron_export.py
Tests check folded weights, quantizer metadata and invocation counts, and model state and hook preservation after a failed export and retry. They cover FP8 on CPU, NVFP4 on CUDA, and weights from multiple expert-parallel ranks.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant VllmFqGPTModelExporter
  participant GroupedExpertModule
  participant GroupedQuantizer
  VllmFqGPTModelExporter->>GroupedExpertModule: Register temporary state-dict post-hook
  GroupedExpertModule->>GroupedQuantizer: Fake-quantize each present weight{i}
  GroupedQuantizer-->>GroupedExpertModule: Return quantized weight
  GroupedExpertModule-->>VllmFqGPTModelExporter: Return state dict
  VllmFqGPTModelExporter->>VllmFqGPTModelExporter: Skip ordinary folding for handled module
  VllmFqGPTModelExporter->>GroupedExpertModule: Remove hook after export
Loading
Merge Risk: ⚪ Minimal · up to 26197

No actionable export regression remains identified; the change is mergeable after normal checks.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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: folding grouped expert weights during fakequant export.
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 anti-pattern was introduced. The only new torch.load call uses weights_only=True. The changed exporter adds no torch.load(..., weights_only=False), numpy.load(..., allow_pickle=…
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch from 03466bb to 2bb481f Compare October 1, 2026 22:31
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 757ea3b to 241645e Compare October 1, 2026 22:31
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch from 2bb481f to 23b91d3 Compare October 2, 2026 00:21
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 241645e to f9f1915 Compare October 2, 2026 00:22
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch 3 times, most recently from 22efe43 to 23d2713 Compare October 2, 2026 22:41
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from f9f1915 to ddd571b Compare October 2, 2026 23:27
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch 2 times, most recently from be4f088 to f1c658c Compare October 6, 2026 17:07
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from ddd571b to d9aad19 Compare October 6, 2026 17:09
kinjalpatel27 added a commit that referenced this pull request Oct 6, 2026
### What does this PR do?

Type of change: New feature

Adds an installable `vllm` CLI shim for the fakequant serving example.
It accepts `--modelopt-*` options, carries them to the existing worker
through environment variables, chooses `FakeQuantWorker` only when
quantization or restore settings require it, and delegates other
commands to stock vLLM. It keeps the legacy direct script invocation and
recognizes the vLLM 0.30 `launch` command. The Docker default moves to
vLLM 0.30.0.

### Usage

```bash
pip install -e examples/vllm_serve
vllm serve <model_path> -tp 8 --modelopt-quant-cfg NVFP4_DEFAULT_CFG
```

### Testing

- Updated CLI and worker-selection coverage in
`tests/gpu/torch/quantization/test_vllm_dynamic_modules.py`.
- CLI delegation and `launch` argument handling were checked during
development against vLLM 0.30.0. CI is pending for this draft.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`?: N/A (no new
runtime dependency or copied code)
- Did you write any new necessary tests?: ✅
- Did you update Changelog?: ✅ (CLI feature entry in CHANGELOG.rst)
- Did you get Claude approval on this PR?: N/A (draft; review not
requested yet)

### Additional Information

Part of a six-PR stack. Merge in numeric order.

### Stack

Merge in this order:

1. [1/6 CLI wrapper and app entry
point](#2626)
2. [2/6 Megatron quantizer
sidecars](#2627)
3. [3/6 Grouped expert weight
folding](#2628)
4. [4/6 Automatic fakequant
reload](#2629)
5. [5/6 HF source config
preservation](#2630)
6. [6/6 EP shard writer
ownership](#2625)


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

* **New Features**
* Added ModelOpt options to the vLLM serving command for
fake-quantization settings, recipes, quantizer-state files, and
full-state checkpoint restoration.
* Commands without ModelOpt quantization settings use standard vLLM
behavior; non-serving commands pass through to vLLM, and invocations
without a command default to serving.
* Tracked `hf_ptq.py` runs now save and upload experiment metadata after
export.
* **Documentation**
* Updated serving instructions with CLI options, environment-variable
alternatives, Docker guidance, and tested vLLM releases.
* **Compatibility**
  * The fake-quantization vLLM CLI shim does not support vLLM 0.9.0.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Kinjal Patel <[email protected]>
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch from f1c658c to 8454997 Compare October 6, 2026 18:30
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch 2 times, most recently from 48f5189 to 95091ca Compare October 7, 2026 02:13
@kinjalpatel27 kinjalpatel27 changed the title [3/6] Fold grouped expert weights during fakequant export [3/5] Fold grouped expert weights during fakequant export Oct 7, 2026
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 95091ca to 30cbb9a Compare October 7, 2026 18:04
@kinjalpatel27
kinjalpatel27 marked this pull request as ready for review October 7, 2026 18:30
@kinjalpatel27
kinjalpatel27 requested review from a team as code owners October 7, 2026 18:30
@kinjalpatel27
kinjalpatel27 requested review from shengliangxu and removed request for a team October 7, 2026 18:30

@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 (bedrock-claude-opus-5-5) — DM the bot to share feedback.

Approving: this is a small, correct fix (about 73 lines of core logic) that makes grouped-expert fakequant export write QDQ-folded weights, and the tests cover it well.

No action needed.

No action needed:

  • I checked the change against _grouped_mlp_slicing in unified_export_megatron.py. The slicer calls module.state_dict() before it swaps in each expert's quantizer, so the post-hook sees the full GroupedQuantizer and folds every weight{i} once. Membership in _grouped_fq_modules then stops _get_quantized_state from folding a second time.
  • Missing keys are skipped inside the hook. The slicer's collective missing-key check still runs, so EP ranks can't get out of step.
  • Hooks are removed in finally. The test injects a failure and confirms the hooks are gone and model state is unchanged afterwards.
  • Torch is pinned to >=2.8, so the public register_state_dict_post_hook API is available.
  • Tests cover FP8 on CPU, NVFP4 on CUDA, a disabled last-expert quantizer, a once-per-quantizer QDQ call count, and EP=2 exact-match against independently folded weights. No existing tests were changed.
  • Optional: live-MTP grouped experts go through _get_mtp_state_dict, outside the hooked _get_state_dict, so they stay unfolded. That isn't a regression, and #2627 already limits MTP to BF16.
  • Optional: the refactor dropped the "Disabled weight quantizers can still apply scaling or rotation" comment. The behaviour is unchanged, but the comment explains why the fold runs even when the quantizer is disabled.

Complex PR: 1 existing test file modified or removed. Looping in a human for approval.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.48%. Comparing base (7abb00b) to head (26197f2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...pt/torch/export/plugins/vllm_fakequant_megatron.py 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2628      +/-   ##
==========================================
+ Coverage   71.82%   78.48%   +6.65%     
==========================================
  Files         648      648              
  Lines       71925    71948      +23     
==========================================
+ Hits        51662    56466    +4804     
+ Misses      20263    15482    -4781     
Flag Coverage Δ
examples-diffusers 20.25% <10.00%> (-0.02%) ⬇️
examples-gpt-oss 13.53% <10.00%> (+<0.01%) ⬆️
examples-hf_ptq 23.33% <10.00%> (-0.07%) ⬇️
examples-llm_distill 13.61% <10.00%> (-0.01%) ⬇️
examples-llm_eval 17.30% <10.00%> (-0.01%) ⬇️
examples-llm_qat 17.60% <10.00%> (-0.02%) ⬇️
examples-llm_sparsity 15.85% <10.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.68% <10.00%> (-0.18%) ⬇️
examples-specdec_bench 13.30% <10.00%> (+<0.01%) ⬆️
examples-speculative_decoding 17.60% <10.00%> (-0.08%) ⬇️
examples-torch_onnx 21.63% <10.00%> (-0.03%) ⬇️
examples-torch_trt 15.29% <10.00%> (-0.01%) ⬇️
examples-vllm_serve 14.89% <10.00%> (+0.88%) ⬆️
gpu 59.50% <97.50%> (+25.63%) ⬆️
regression 15.15% <10.00%> (-0.01%) ⬇️
unit 59.83% <10.00%> (-0.01%) ⬇️

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.

@kinjalpatel27
kinjalpatel27 requested a review from cjluo-nv October 7, 2026 21:11
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 30cbb9a to 7425d7a Compare October 8, 2026 01:01

@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 (bedrock-claude-opus-5-5) — DM the bot to share feedback.

LGTM on re-review: the previous review raised nothing blocking, and the folding fix for grouped experts (~73 lines of core logic) is still correct and well tested.

Needs action:

  • Give human sign-off. The complex-PR gate flagged the edit to tests/gpu_megatron/torch/export/test_vllm_fakequant_megatron_export.py, but the edit only adds new grouped and EP=2 export tests. No existing assertions changed.

No action needed:

  • I confirmed both GPTModelExporter._get_state_dict and self.dtype exist in unified_export_megatron.py. The override calls the parent method and removes its post-hooks in finally.
  • The hook only folds keys that are present in the state dict. The slicer still checks for missing keys across all ranks together, so EP ranks stay in sync.
  • _grouped_fq_modules stops _get_quantized_state from folding the same weight twice. The test confirms each quantizer runs QDQ exactly once.
  • From last time (optional): grouped experts in live MTP still export unfolded. This isn't a regression, since #2627 limits MTP to BF16.
  • Last time's optional request is fixed: the "disabled quantizers can still apply scaling or rotation" comment is back in _fakequant_weight.

@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 7425d7a to c303352 Compare October 8, 2026 19:00
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch from ff37553 to e7ce099 Compare October 9, 2026 18:50
@kinjalpatel27
kinjalpatel27 requested a review from a team as a code owner October 9, 2026 18:50
@kinjalpatel27
kinjalpatel27 requested review from sugunav14 and removed request for a team October 9, 2026 18:50
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-megatron-sidecars branch from eed372d to 3e060dd Compare October 9, 2026 21:31
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch 2 times, most recently from 752c114 to 41b1e68 Compare October 9, 2026 22:30

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

LGTM. Folding through the temporary state_dict post-hook is correct: each grouped expert is folded once, and the EP=2 test compares against independently folded weights.

Nit (optional): quantizers[min(i, len(quantizers) - 1)] silently reuses the last expert's quantizer, and so its amax, if a GroupedQuantizer ever has fewer members than num_gemms. Asserting len(quantizers) == module.num_gemms would turn that into an error instead of a wrong scale.

Please rebase onto #2627's latest head (ed5d512) before merging. The trial merge is clean, but CI here ran without it.

@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 41b1e68 to 27dd866 Compare October 14, 2026 17:30
Base automatically changed from kinjal/vllm-fq-megatron-sidecars to main October 14, 2026 20:44
kinjalpatel27 added a commit that referenced this pull request Oct 14, 2026
### What does this PR do?

Type of change: New feature

Megatron fakequant export writes `quant_recipe.yaml` (enabled state,
bits, axis, block sizes, backend settings) and `quantizer_state.pth`
(activation/output and K/V `_amax` tensors at original precision).
Backbone weight quantization and transforms are folded into weights.
vLLM accepts both files directly. Shared reload handles packed module
and flat HF quantizer names, preserves range precision, and disables
only weight quantizers without checkpoint state. PR4 adds automatic
discovery using this loader.

Recipe markers follow the existing HF mapping, including packed experts
mapped to vLLM’s fused `w13`/`w2` quantizers. Packed expert ranges merge
by maximum; their recipes must agree. One shared merge helper requires
replicated recipes/tensors to agree across ranks. Unsupported settings
and incompatible packed recipes are raised on every rank before weight
writes. Config files may already exist, and quantizer-file merge/write
failures occur after weights are saved.

### Why a separate recipe?

`quantizer_state()` and
`TensorQuantizer.get_modelopt_state(properties_only=True)` can be
extended, but describe source modules. Megatron still needs QKV/gate-up
splitting, pipeline/expert routing, and distributed merging. Markers
reuse that mapping; YAML supplies reload configuration separately from
`amax` tensors.

### Current limits

- Active sequential activation quantizers are rejected; sequential
weight quantization remains folded into weights.
- Recipe export follows the existing model mappings. MTP remains BF16;
MTP quantization is rejected.
- Rejects active real quantization, activation rotation/scaling, and
active activation quantizers using integer `unsigned`/`narrow_range`,
bias, or non-MX formats lacking a calibrated/constant range. Active
means `is_enabled and _if_quant`; activation rotation/scaling is
rejected even when quantization is disabled.

### Usage

```python
from modelopt.torch.export import export_mcore_gpt_to_hf_vllm_fq
export_mcore_gpt_to_hf_vllm_fq(model, source_checkpoint, export_dir=export_dir)
```

```bash
python3 examples/vllm_serve/vllm_serve_fakequant.py <export_dir> \
  --modelopt-recipe-path <export_dir>/quant_recipe.yaml \
  --modelopt-quant-file-path <export_dir>/quantizer_state.pth
```

### Testing

- All four Megatron GPU tests and pre-commit passed after adding
sequential activation rejection to the existing distributed test.
Earlier reload validation passed 29 example tests and three vLLM cases
(Llama, Qwen3-MoE, GPT-OSS); both MoE cases passed again with original
Qwen3 settings restored.
- Tiny GPT-OSS packed activation export → direct vLLM 0.30 reload →
generation passed: four FP32 ranges and four reference quantizer probes
matched exactly; every active expert quantizer executed.
- Earlier validation passed 80 serve-example tests and pretrained Qwen3
activation/KV and Nemotron-H BF16 MTP end-to-end flows with original
YAML/tensors, without PR3/PR4.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- 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?: ✅ (extended existing coverage)
- Did you update Changelog?: N/A (unreleased series)
- Did you get Claude approval on this PR?: ❌ (not run)

### Additional Information

[1: CLI](#2626) is merged.
Remaining merge order: [**2: this
PR**](#2627) → [3: grouped
weights](#2628) → [4:
reload](#2629) → [5: HF
config](#2630)

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

* **New Features**
* vLLM fake-quant exports now include quantizer recipes and state files
alongside the model.
* vLLM can use exported quantizer recipes or PTQ recipe files and
restore quantizer state when loading.
  * Exported recipes can be uploaded to experiment tracking.
* **Bug Fixes**
* Exports preserve quantizer settings and calibration values, and report
unsupported settings, MTP quantization, and conflicting distributed
data.
* Weight-quantizer transforms are folded into model weights; MTP weights
remain unquantized.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Kinjal Patel <[email protected]>
@kinjalpatel27
kinjalpatel27 force-pushed the kinjal/vllm-fq-grouped-export branch from 27dd866 to 26197f2 Compare October 14, 2026 20:46
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-14 21:58 UTC

@kinjalpatel27
kinjalpatel27 merged commit d9b8772 into main Oct 14, 2026
55 checks passed
@kinjalpatel27
kinjalpatel27 deleted the kinjal/vllm-fq-grouped-export branch October 14, 2026 21:58
kinjalpatel27 added a commit that referenced this pull request Oct 14, 2026
### What does this PR do?

Type of change: New feature

The fakequant launcher detects sidecars in a local exported checkpoint.
A full ModelOpt state sidecar takes precedence; Megatron exports use
`quantizer_state.pth` and `quant_recipe.yaml`. Explicit ModelOpt options
prevent autodetection. The reload path maps HF and Megatron quantizer
names to vLLM names and rejects `recipe_path` combined with `quant_cfg`
or `kv_quant_cfg`.

The Megatron exporter folds weight quantization into exported weights
and omits weight quantizer tensors. On reload, a weight quantizer is
disabled when its state is absent from the local checkpoint. When state
is present, it remains enabled so the worker can fold it. Missing
non-weight quantizer keys are warned about only if absent across all
ranks.

### Usage

```bash
python3 examples/vllm_serve/vllm_serve_fakequant.py <export_dir> -tp 8
```

The directory may contain `vllm_fq_modelopt_state.pth`, or both
`quantizer_state.pth` and `quant_recipe.yaml`.

### Testing

- 41 tests passed in
`tests/examples/vllm_serve/test_fakequant_example.py`, including recipe
conflicts, invalid YAML, sidecar selection, and selective weight
quantizer disabling.
- `test_tiny_qwen3_moe_quantize` passed in
`tests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py`,
including fused expert quantizer key mapping.
- Pre-commit passed on the changed files.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`?: N/A (no new
runtime dependency or copied code)
- Did you write any new necessary tests?: ✅
- Did you update Changelog?: N/A (the CLI feature is recorded in
[1/5](#2626))
- Did you get Claude approval on this PR?: N/A

### Additional Information

Part of a five-PR stack. Merge in numeric order.

### Stack

1. [CLI wrapper and app entry
point](#2626)
2. [Megatron quantizer
sidecars](#2627)
3. [Grouped expert weight
folding](#2628)
4. [Automatic fakequant
reload](#2629)
5. [HF source config
preservation](#2630)


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

* **New Features**
* The vLLM fake-quant launcher can automatically detect quantization
settings in a model directory and select the appropriate serving worker.
When both supported export formats are present, it prioritizes the full
ModelOpt state.
* Serving documentation now explains option defaults, how explicit
settings affect detection, and which vLLM flags are supported.
* **Bug Fixes**
* Recipe files are validated, and combining a recipe with manual weight
or KV quantization settings is rejected.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Kinjal Patel <[email protected]>
kinjalpatel27 added a commit that referenced this pull request Oct 15, 2026
### What does this PR do?

Type of change: Bug fix

HF fakequant export preserves the original `config.json` bytes when the
in-memory model config still matches the source checkpoint. This keeps
custom config fields and serialization used by remote-code models. If
the config has changed after loading, such as after vocabulary resizing,
the export keeps the config generated by `save_pretrained` so it matches
the exported weights.

### Usage

No API change. Existing `export_hf_vllm_fq_checkpoint(...)` calls apply
the config-preservation check.

### Testing

- Existing tiny-Llama export test checks byte equality for an unchanged
source config.
- Added resized-vocabulary export test checks that the exported config
matches the changed model; it passed in the validation image.
- CI is pending for this draft.

### Before your PR is "*Ready for review*"

- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`?: N/A (no new
runtime dependency or copied code)
- Did you write any new necessary tests?: ✅
- Did you update Changelog?: N/A (fix to the unreleased fakequant export
path)
- Did you get Claude approval on this PR?: N/A (draft; review not
requested yet)

### Additional Information

Part of a five-PR stack. Merge in numeric order.

### Stack

Merge in this order:

1. [CLI wrapper and app entry
point](#2626)
2. [Megatron quantizer
sidecars](#2627)
3. [Grouped expert weight
folding](#2628)
4. [Automatic fakequant
reload](#2629)
5. [HF source config
preservation](#2630)


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

* **New Features**
* vLLM can automatically detect exported fakequant model data, including
quantizer state and recipe files, and use it when reloading a model.
* Fakequant recipes and quantizer state can be used for calibration and
checkpoint reload. Unsupported or conflicting quantization settings are
now reported.
* **Bug Fixes**
* Exported models retain the source configuration when settings are
unchanged; resized vocabularies are reflected in the exported
configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Kinjal Patel <[email protected]>
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.

3 participants