Repository navigation
[4/5] Reload vLLM fakequant checkpoints automatically - #2629
Conversation
|
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. |
757ea3b to
241645e
Compare
f3e55f8 to
6785d2a
Compare
241645e to
f9f1915
Compare
6785d2a to
4780621
Compare
ddd571b to
d9aad19
Compare
4780621 to
2e50bbd
Compare
### 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]>
d9aad19 to
48f5189
Compare
2e50bbd to
d0f9a87
Compare
48f5189 to
95091ca
Compare
d0f9a87 to
adf4c87
Compare
95091ca to
30cbb9a
Compare
adf4c87 to
97a1179
Compare
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Nudge: the sidecar auto-detection and fused-expert key mapping look correct and fit the size budget, but two behaviour changes have no tests and the PR is still a draft.
Needs action:
- Add a test for
load_state_dict_from_pathinvllm_reload_utils.py. It now disables every weight quantizer, includingSequentialQuantizerweight_quantizer.0children and fusedw13_/w2_ones, instead of only those missing from the checkpoint. A test should also confirm that missing non-weight keys still only warn. - Add a test for the new
recipe_pathvsquant_cfg/kv_quant_cfgValueErrorinvllm_ptq_utils.get_quant_config. Also point to (or add) the empty, malformed and non-mapping YAML cases the PR body mentions. They aren't in this diff. - Extend the
_convert_key_for_vllmcase intest_vllm_dynamic_modules.pyto coverexperts.gate_up_proj_*and a fused*_weight_quantizerkey. Right now onlyup_proj/down_projinput quantizers are tested. - Mark the PR ready and fix the body. The Changelog line says "[1/6]", but this is a five-PR stack.
No action needed:
- Disabling all weight quantizers is consistent with
VllmFqGPTModelExporter, which never exports weight-quantizer amax. Weights are always folded. _autodetect_fakequant_pathsis a safe no-op for hub IDs andunknown-model. Explicit settings take precedence, and that is tested.- No existing tests were modified, only added to.
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Approve: all four concerns from the last review are fixed in this diff, and the reworked weight-quantizer disable logic is now correct and tested.
No action needed.
No action needed:
- ✔️ Resolved since the last review: tests now cover selective weight-quantizer disabling in
load_state_dict_from_path, therecipe_pathconflict and invalid-YAMLValueErrors, and the fusedgate_up/up/down_convert_key_for_vllmmappings. The PR body now uses the correct five-PR stack numbering. - Behaviour change, now tested:
load_state_dict_from_pathonly disables weight quantizers with no local checkpoint state. Those still in the checkpoint stay enabled so the worker can fold them. - I checked the test against the code.
is_weight_quantizer_state_keymatches bothweight_quantizer.0andexperts.w13_weight_quantizer.SequentialQuantizercontainers are skipped, and only theirTensorQuantizerchildren get disabled. - The test changes only add cases. The GPU test gains entries in its key-mapping tuple; no existing assertions were changed.
- About 80 added lines of core logic, well under budget. No licensing changes.
- This targets
kinjal/vllm-fq-grouped-export, so merge it after #2628. I couldn't see whether the PR is still a draft.
30cbb9a to
7425d7a
Compare
c67459a to
e947b22
Compare
7425d7a to
c303352
Compare
e947b22 to
d4bc033
Compare
c303352 to
752c114
Compare
f055084 to
aa8282c
Compare
752c114 to
41b1e68
Compare
aa8282c to
aa5df15
Compare
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Approve: every concern from the earlier reviews is still fixed, and the sidecar auto-detection and recipe-conflict checks are correct and tested.
No action needed.
No action needed:
- ✔️ Resolved since the last review: tests for the
recipe_pathconflict and invalid YAML, the fused-key mapping tests, and the stack numbering in the PR body. The selective weight-quantizer disabling logic and its test now sit in the base branch;test_quantizer_state_disables_only_missing_weight_quantizersappears here as unchanged context. - I traced the invalid-YAML cases against
load_recipe. Empty and non-mapping YAML both raiseValueErrorbecause the recipe kind can't be resolved. Malformed YAML raisesyaml.YAMLErrordirectly fromget_quant_config. _autodetect_fakequant_pathsdoes nothing for Hub IDs,unknown-model, or any explicit setting (all five settings tested). If both sidecar types are present, the full-state file wins (tested).CHANGELOG.rstextends the single entry from #2626 to cover the Megatronquant_recipe.yamlexport and automatic reload, which delivers the item deferred from #2627.- Tests are only added, not modified. About 50 lines of core logic and no licensing changes. I read the tests but didn't run them. Merge after #2628 and before #2630.
kevalmorabia97
left a comment
There was a problem hiding this comment.
LGTM. Auto-detection is conservative: any explicit ModelOpt setting disables it, and the full-state file takes precedence over the Megatron files. Rejecting recipe_path together with quant_cfg or kv_quant_cfg is also good.
Nits (non-blocking):
- Consider logging which files were auto-detected. Serving a directory that happens to contain stale sidecars would otherwise switch to fake-quant without any visible sign.
- README Known Problems item 2 ("KV cache quantization export and reload is not supported in MCore yet") looks stale now that #2627 exports K/V ranges.
FYI, for NVIDIA-NeMo/Megatron-Bridge#4804: we'll have the Megatron-Bridge export write quantizer_state.pth + quant_recipe.yaml instead of modelopt_weights.pt, so its checkpoints get this auto-detection too.
41b1e68 to
27dd866
Compare
aa5df15 to
dc7c581
Compare
### 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]>
27dd866 to
26197f2
Compare
### 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](#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 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
Signed-off-by: Kinjal Patel <[email protected]>
dc7c581 to
3e3f4b2
Compare
|
### 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]>
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.pthandquant_recipe.yaml. Explicit ModelOpt options prevent autodetection. The reload path maps HF and Megatron quantizer names to vLLM names and rejectsrecipe_pathcombined withquant_cfgorkv_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
The directory may contain
vllm_fq_modelopt_state.pth, or bothquantizer_state.pthandquant_recipe.yaml.Testing
tests/examples/vllm_serve/test_fakequant_example.py, including recipe conflicts, invalid YAML, sidecar selection, and selective weight quantizer disabling.test_tiny_qwen3_moe_quantizepassed intests/gpu_vllm/torch/quantization/test_vllm_dynamic_modules.py, including fused expert quantizer key mapping.Before your PR is "Ready for review"
CONTRIBUTING.md?: N/A (no new runtime dependency or copied code)Additional Information
Part of a five-PR stack. Merge in numeric order.
Stack
Summary by CodeRabbit