Repository navigation
fix(config): normalize EXL3 serialization and reject silent kwarg drops (#4052) - #4057
Merged
Merged
Conversation
…ps (#4052) - Run the base serialization normalization for EXL3Config so auto_dtype_cast, telemetry, and mse survive to_dict/from_quant_config round trips. - Validate QuantizeConfig factory kwargs: unknown keys raise with a suggestion, known fields for another method warn instead of vanishing, and from_quant_config stays lenient for legacy checkpoints. - Accept Mapping calibration examples such as BatchEncoding. - Honor HF device_map string shorthand and reject device/device_map conflicts. - Reload static_groups from checkpoint meta and reject non-bool bool fields. - Document the flow in docs/config-serialization.md and link it from README.
This was referenced Nov 14, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
#4693) Two config paths still accepted input that silently changed, or failed to change, what got quantized. #4052/#4057 covered the top-level kwargs and eight base bool fields; both gaps below are the remainder. **Bool fields.** `_validate_bool_fields` checked a hand-maintained list of eight names. Every other bool field was coerced with `bool(...)` (so `"False"` became `True`) or stored as a truthy string. Derive the set from the dataclass annotations instead, so a field cannot be added without being validated. `Optional[bool]` keeps `None` as the documented "use the default" value. `MacaqConfig` forces `sym=True` before `super().__post_init__()`, so it now validates the caller's input first; otherwise the forced value is all the validator ever saw. **`dynamic` rules.** `_normalize_dynamic_layer_config` checked only the `bits` and `group_size` values, never that the keys were known. A misspelled override (`{"bit": 8, "group_sise": 32}`) was accepted, had no effect, and was written into the checkpoint, so the saved mixed-precision layout differed from the one requested. Reject unknown keys against the union of every known config class's fields plus the legacy aliases (`fmt`, and the opaque `nested` passthrough), so a checkpoint carrying another backend's field still loads. Reuse the difflib close-match hint from the top-level kwargs check. Also compile each pattern at construction: a bad regex used to survive until the first module match. Closes #4668.
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
) (#4698) `BaseQModel.save(..., **kwargs)` forwarded `**kwargs` only on the non-quantized branch. For a quantized model — the normal case — every extra keyword was discarded without an error or a log line, so a typo of a real parameter and an HF option such as `push_to_hub=True` both reported success and did nothing. Raise `TypeError` for any leftover keyword on the quantized branch, with the same difflib close-match hint `QuantizeConfig` uses for unknown kwargs (#4057): `max_shard_sise` now points at `max_shard_size`. The module-replacement writer (`save_quantized_embeddings`) also dropped two of `save()`'s own named parameters. It writes a weight-only replacement checkpoint and has no adapter or split support, so `eora_path`/`split_by` are now rejected there explicitly instead of being ignored. This is the save-side counterpart of #4052/#4057. Closes #4686.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4052
TL;DR
Config construction and checkpoint reload now fail closed where they used to
drop user settings, and every concrete config class normalises the fields
to_dict()assumes are alreadyEnum/dataclass instances. The net change is6 files under
gptqmodel/, 3 test files, 1 new reference page, and the READMElink.
EXL3Config(auto_dtype_cast="off")quantizes and saves end to end onCUDA and ROCm; the same run crashed in
writer.pybefore this change.1. The problem
EXL3Config.__post_init__bypassedBaseQuantizeConfig.__post_init__(
gptqmodel/quantization/config.py:6303before this change), soauto_dtype_caststayed astr,telemetrystayed adict, andmsestayed a number.
to_dict()then assumed normalised types(
config.py:4925self.auto_dtype_cast.value,config.py:4897asdict(self.telemetry)).The factory path had the opposite failure mode:
QuantizeConfig(...)filtered kwargs down to the dispatched class's init fields with no error or
log (
_filter_quantize_config_payload_for_target_cls), so typos andmethod-incompatible fields vanished.
Old flow:
flowchart TD A["QuantizeConfig kwargs"] --> B["_resolve_quantize_config_class"] B --> C["_filter_quantize_config_payload_for_target_cls"] C -->|"unknown or foreign key"| D["silently dropped"] D --> E["concrete config __post_init__"] E -->|"EXL3 bypasses base"| F["raw str and dict fields"] F --> G["to_dict"] G -->|"EXL3"| H["AttributeError or TypeError"] classDef fail fill:#ffd6d6,stroke:#c00000,color:#000 class D,H failBefore/after mechanisms:
_filter_quantize_config_payload_for_target_clsdropped unknown and foreign keys silently_validate_quantize_config_factory_kwargsraises for unknown keys and warns for foreign known fields (config.py:4012)EXL3Config.__post_init__bypassed base normalisation_normalize_serialization_fields(config.py:6401)BaseQuantizeConfig.__post_init__config.py:4429)bool()accepted the string"False"asTrue_validate_bool_fieldsraisesTypeError(config.py:4452)isinstance(example, dict)rejectedBatchEncoding(calibration.py:352)isinstance(example, Mapping)(calibration.py:356)devicereplaced bydevice_mapwithout a check (loader.py:1735)_normalize_requested_device_map(loader.py:569) checks agreement and maps HF stringsstatic_groupsmeta, absent from the reload mapfrom_quant_config(config.py:4831)2. The new flow
flowchart TD A["QuantizeConfig kwargs"] --> B["_normalize_quantize_config_constructor_kwargs"] B --> C["_resolve_quantize_config_class"] C --> D["_validate_quantize_config_factory_kwargs"] D -->|"unknown key"| E["TypeError with close-match hint"] D -->|"known field not accepted by target"| F["WARN and drop"] D -->|"accepted"| G["_prepare_target_quantize_config_kwargs"] G --> H["concrete config __post_init__"] H --> I["_normalize_serialization_fields"] I --> J["to_dict"] classDef fail fill:#ffd6d6,stroke:#c00000,color:#000 class E failfrom_quant_configis unchanged and stays lenient: it still logs and ignoresunknown keys so old checkpoints load. The strict check lives only on the
QuantizeConfig(...)factory andGPTQModel.load(..., quantize_config=dict).EXL3 now runs the shared normalisation directly:
flowchart LR A["EXL3Config __post_init__"] --> B["_normalize_preprocessor_state"] B --> C["_normalize_serialization_fields"] C --> D["AutoDtypeCast"] C --> E["TelemetryConfig"] C --> F["MSEConfig"] D --> G["to_dict"] E --> G F --> GDevice and
device_map:flowchart TD A["from_quantized device and device_map"] --> B["_normalize_requested_device_map"] B -->|"device_map is cpu or cuda:N string"| C["map to empty-key device map"] B -->|"accelerate keyword"| D["keep keyword string"] B --> E{"device also set?"} E -->|"yes"| F["_validate_device_and_device_map_agree"] F -->|"family mismatch"| G["ValueError"] F -->|"families agree"| H["use device_map"] E -->|"no"| H classDef fail fill:#ffd6d6,stroke:#c00000,color:#000 class G failThe reference page with the same diagrams and the failure contract is
docs/config-serialization.md, linked fromREADME.mdnext to the concreteconfig classes.
3. Before/after repro
Config items (CPU,
PYTHONPATH=$PWD):End-to-end EXL3 (
bits=2,auto_dtype_cast="off", tiny Llama with128-wide projections):
4. Tests and validation
New/updated tests:
tests/qcfg/test_config_serialization.py— every concrete config normalisesauto_dtype_cast/telemetry/mse; EXL3 round-trip;static_groupsreload;bool fields reject strings and ints.
tests/qcfg/test_config_dispatch.py— unknown factory kwarg raises with asuggestion; foreign known fields warn;
from_quant_configstays lenient.tests/test_calibration_mapping_input.py—BatchEncodingcalibration rows.tests/test_loader.py— HFdevice_mapstrings, invalid/offload strings,and device/device_map agreement and conflict.
Exact commands and measured results:
Hardware:
GPU-1ece7ec2-d88d-9284-93c8-d2578d90ad7e,torch 2.16.0.dev+cu130, Py3.14t.
HIP_VISIBLE_DEVICES=1,torch 2.16.0.dev+rocm10.1, Py3.14t.
nvidia-smi --query-compute-appsshowed theassigned 4090 free before the timing/GPU runs.
5. Risk and limitations
QuantizeConfig(**config.to_dict())is preserved for every concrete configtested; RTN
to_dictstill dispatches toGPTQConfigbecause RTN is aweight-only mode without a top-level method marker. That predates this PR and
is not changed here.
QuantizeConfig(method='gptq', format='gemm')still auto-selects AWQ with awarning, and
GPTQModel.load(quantized_path, quantize_config=X)stillignores
X; both are separate dispatch contracts listed as follow-up in thedocs page.
from_quant_config, so legacy checkpoint JSON with unknown keys keepsloading.