Repository navigation
fix(config): reject bad bool values and unknown dynamic keys (#4668) - #4693
Merged
Merged
Conversation
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.
This was referenced Nov 17, 2026
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 #4668
Root cause
Two config paths still accepted input that silently changed, or silently failed
to change, what got quantized. #4052/#4057 covered the top-level kwargs and
eight base bool fields; these are the remainder.
1. Bool fields.
_validate_bool_fieldschecked a hand-maintained list ofeight names. Every other bool field was coerced with
bool(...)— andbool("False") is True— or stored as a truthy string.2.
dynamicrules._normalize_dynamic_layer_configchecked only thebitsandgroup_sizevalues, never that the keys were known. A misspelledoverride was accepted, had no effect, and was serialized into the checkpoint.
Fix
Bool fields are now derived from the dataclass annotations rather than a
list, so a newly added field cannot escape validation:
bool→ must beboolOptional[bool]→boolorNone(Noneis the documented "use thedefault" value, e.g.
desc_act,act_group_aware,opt_amp)isinstance(value, bool)rejects1/0as well, sinceboolsubclassesintMacaqConfigforcessym=Truebeforesuper().__post_init__(), so theshared validator only ever saw the forced value. It now validates the caller's
input at the top of its own
__post_init__.dynamicrules are validated at all four parse sites (base, FP8,BitsAndBytes, EXL3):
fields plus the legacy aliases, reusing the difflib close-match hint from
_validate_quantize_config_factory_kwargs;target class, so a checkpoint carrying another backend's field (e.g.
compress_statisticson a GPTQ config) still loads — the same leniencyfrom_quant_configalready gives top-level keys;fmt(legacy alias forformat) andnested(opaque passthrough whosecontents the fingerprint and defensive-copy paths preserve verbatim) are
accepted as-is;
re.compiled at construction, so a bad regex fails where itwas written instead of at the first module match.
Before / after
/tmp/repro4668.py, every field the issue lists:Tests
New
tests/qcfg/test_config_validation_4668.py(19 tests):test_bool_fields_reject_truthy_strings— parametrized over seven concreteconfigs; enumerates every bool-annotated field from the dataclass rather
than a fixed list, and asserts both
"False"/"True"and1raise.test_every_concrete_config_has_bool_fields_to_check— guard-the-guard, sothe enumeration cannot silently become empty.
test_bool_fields_still_accept_real_booleans— re-passes each field its ownnormalised value, so per-backend domain constraints (QQQ rejects
desc_act=True, MACaQ rejectslm_head) cannot make it a false failure.test_macaq_validates_before_forcing_symtest_dynamic_rejects_unknown_keys_with_a_close_match_hinttest_dynamic_accepts_known_and_legacy_keystest_dynamic_rejects_an_uncompilable_pattern_at_constructionFail-before, with the source change reverted and the tests kept:
Pass-after:
The 1 failure and 4 errors above are pre-existing on pristine
origin/main(verified by stash + rerun) and unrelated:
test_serialization.py::test_quantize_config_meta_only_fields_serialization—
offload_to_disk_pathmissing from the meta dict.test_dynamic.py—RuntimeError: Neither pandas nor pyarrow is available to load calibration parquet.Regression found and fixed during review
The first version rejected
nested, which broke two existingtest_dynamic_config.pytests.nestedis an opaque passthrough whose contentsthe dynamic fingerprint and defensive-copy paths preserve verbatim, so it is now
allowed as-is (its contents are not inspected). Caught by running the full
tests/qcfg/suite, not just the new file.Scope / limits
config.
from_quant_configremains as lenient as it was: the alloweddynamickey setis the union across backends specifically so legacy checkpoints keep loading.