Commit d6e1973
fix: layerwise calibration backward-compat, recipe split, batch-size guard (#1310)
## Summary
Follow-up to #1251 (which renamed `use_sequential` → `layerwise`). Three
related fixes bundled:
1. **Backward-compatible config loading.** PTQ checkpoints saved before
#1251 store the
legacy `use_sequential` key in the calibration-algorithm config, so
loading them now
raises `ValidationError: Extra inputs are not permitted
(use_sequential)` because
`QuantizeAlgorithmConfig` uses `extra='forbid'`. Accept `use_sequential`
as an alias
for `layerwise` via `AliasChoices`. The field still serializes as
`layerwise`, so
round-trips through the current schema are clean.
2. **Recipe split.** `nvfp4_experts_only-fp8_kv` previously enabled
layerwise calibration
by default, which changes the calibration flow materially. Split into
two recipes:
- `nvfp4_experts_only-fp8_kv.yaml` — default (no layerwise)
- `nvfp4_experts_only-fp8_kv_layerwise.yaml` — layerwise variant
3. **`hf_ptq` batch-size guard.** Auto batch-size detection is not
supported together
with layerwise calibration. Default to `batch_size=1` when layerwise is
enabled and
the user hasn't set a batch size explicitly.
Originally reported by Jenny Chen while resuming a PTQ checkpoint via
`restore_sharded_modelopt_state`:
```
pydantic_core._pydantic_core.ValidationError: 1 validation error for MaxCalibConfig
use_sequential
Extra inputs are not permitted [type=extra_forbidden, input_value=False, input_type=bool]
```
## Test plan
- [x] `tests/unit/torch/quantization/test_config_validation.py` — legacy
alias accepted, current name accepted, dump serializes under current
name, `extra='forbid'` still rejects unknown keys.
- [x] `pre-commit run` — clean.
### Before your PR is *Ready for review*
- Is this change backward compatible?: ✅ (restores compatibility for
pre-#1251 checkpoints)
- New PIP dependency: N/A
- New necessary tests: ✅
- Changelog update: N/A (bug fix)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Release Notes
* **New Features**
* Added new PTQ recipe for efficient layerwise calibration of large
models.
* Automatic batch size optimization for layerwise calibration recipes.
* Backward compatibility support for legacy input naming conventions.
* **Documentation**
* Updated recipe guides and changelog with new layerwise calibration
recipe.
* **Tests**
* Added validation tests for configuration compatibility.
[](https://app.coderabbit.ai/change-stack/NVIDIA/Model-Optimizer/pull/1310)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: realAsma <akuriparambi@nvidia.com>1 parent c3b1f5a commit d6e1973
8 files changed
Lines changed: 111 additions & 9 deletions
File tree
- docs/source/guides
- examples/llm_ptq
- modelopt_recipes/general/ptq
- modelopt/torch/quantization
- tests/unit
- recipe
- torch/quantization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
498 | 500 | | |
499 | 501 | | |
500 | 502 | | |
| |||
657 | 659 | | |
658 | 660 | | |
659 | 661 | | |
| 662 | + | |
660 | 663 | | |
661 | 664 | | |
662 | 665 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
988 | 988 | | |
989 | 989 | | |
990 | 990 | | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
991 | 1010 | | |
992 | 1011 | | |
993 | 1012 | | |
| |||
1001 | 1020 | | |
1002 | 1021 | | |
1003 | 1022 | | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
1004 | 1028 | | |
1005 | 1029 | | |
1006 | 1030 | | |
| |||
1064 | 1088 | | |
1065 | 1089 | | |
1066 | 1090 | | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
| 1091 | + | |
1073 | 1092 | | |
1074 | 1093 | | |
1075 | 1094 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| 591 | + | |
591 | 592 | | |
592 | 593 | | |
593 | 594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
525 | 526 | | |
526 | 527 | | |
527 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
0 commit comments