Skip to content

fix(config): reject bad bool values and unknown dynamic keys (#4668) - #4693

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4668-config-validation
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4668-config-validation

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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_fields checked a hand-maintained list of
eight names. Every other bool field was coerced with bool(...) — and
bool("False") is True — or stored as a truthy string.

2. dynamic rules. _normalize_dynamic_layer_config checked only the
bits and group_size values, never that the keys were known. A misspelled
override 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 be bool
  • Optional[bool] → bool or None (None is the documented "use the
    default" value, e.g. desc_act, act_group_aware, opt_amp)
  • isinstance(value, bool) rejects 1/0 as well, since bool subclasses
    int

MacaqConfig forces sym=True before super().__post_init__(), so the
shared validator only ever saw the forced value. It now validates the caller's
input at the top of its own __post_init__.

dynamic rules are validated at all four parse sites (base, FP8,
BitsAndBytes, EXL3):

  • unknown keys are rejected against the union of every known config class's
    fields plus the legacy aliases, reusing the difflib close-match hint from
    _validate_quantize_config_factory_kwargs;
  • the allowed set is deliberately the union across backends, not just the
    target class, so a checkpoint carrying another backend's field (e.g.
    compress_statistics on a GPTQ config) still loads — the same leniency
    from_quant_config already gives top-level keys;
  • fmt (legacy alias for format) and nested (opaque passthrough whose
    contents the fingerprint and defensive-copy paths preserve verbatim) are
    accepted as-is;
  • each pattern is re.compiled at construction, so a bad regex fails where it
    was written instead of at the first module match.

Before / after

/tmp/repro4668.py, every field the issue lists:

=== BEFORE (git stash) ===
  GPTQConfig static_groups: ACCEPTED (BAD)
  GPTQConfig mock_quantization: ACCEPTED (BAD)
  GPTQConfig act_group_aware: ACCEPTED (BAD)
  QQQConfig static_groups: ACCEPTED (BAD)
  VPTQConfig enable_norm: ACCEPTED (BAD)
  AWQConfig scale_search_chunked_activations: ACCEPTED (BAD)
  BitsAndBytesConfig compress_statistics: ACCEPTED (BAD)
  MacaqConfig sym: ACCEPTED (BAD)
--- dynamic ---
  bit typo: ACCEPTED
  valid bits: ACCEPTED
  bad regex: ACCEPTED
  legacy fmt: ACCEPTED

=== AFTER ===
  ... all nine bool cases: rejected OK
  bit typo: rejected OK -> GPTQConfig: unknown `dynamic['.*down_proj']` key(s):
                          `bit` (did you mean `bits`?), `group_sise` (did you mean `group_size`?)
  valid bits: ACCEPTED
  bad regex: rejected OK -> `dynamic` key '+:[' is not a valid regular expression: unterminated character set
  legacy fmt: ACCEPTED

Tests

New tests/qcfg/test_config_validation_4668.py (19 tests):

  • test_bool_fields_reject_truthy_strings — parametrized over seven concrete
    configs; enumerates every bool-annotated field from the dataclass rather
    than a fixed list, and asserts both "False"/"True" and 1 raise.
  • test_every_concrete_config_has_bool_fields_to_check — guard-the-guard, so
    the enumeration cannot silently become empty.
  • test_bool_fields_still_accept_real_booleans — re-passes each field its own
    normalised value, so per-backend domain constraints (QQQ rejects
    desc_act=True, MACaQ rejects lm_head) cannot make it a false failure.
  • test_macaq_validates_before_forcing_sym
  • test_dynamic_rejects_unknown_keys_with_a_close_match_hint
  • test_dynamic_accepts_known_and_legacy_keys
  • test_dynamic_rejects_an_uncompilable_pattern_at_construction

Fail-before, with the source change reverted and the tests kept:

$ pytest tests/qcfg/test_config_validation_4668.py -q
10 failed, 9 passed

Pass-after:

$ pytest tests/qcfg/test_config_validation_4668.py -q
19 passed

$ pytest tests/qcfg/ -q
144 passed

$ pytest tests/test_config_only_export.py tests/test_config_per_module_validation_4200.py \
         tests/test_config_serialization_roundtrip_4201.py tests/test_dynamic.py \
         tests/test_dynamic_config_invalidation_4475.py tests/test_dynamic_exclusion_order_4198.py \
         tests/test_quantize_config_offload_tempdir.py tests/test_serialization.py -q
71 passed, 2 skipped, 1 failed, 4 errors

$ ruff check gptqmodel docs/eora tests setup.py
All checks passed!

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_path missing 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 existing
test_dynamic_config.py tests. nested is an opaque passthrough whose contents
the 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

  • Type and key validation only; no change to which algorithm runs for a valid
    config.
  • from_quant_config remains as lenient as it was: the allowed dynamic key set
    is the union across backends specifically so legacy checkpoints keep loading.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant