Skip to content

[BUG] Config validation still silently accepts bad input (#4052 incomplete): 20+ bool fields take "False" as True (mock_quantization="False" runs the mock solver), and typo'd keys in dynamic overrides are ignored and persisted #4668

Closed

Description

@Qubitium

Found on main @ 12c1273, CPU (x86-64).

This is a follow-up on #4052 / #4057 ("reject silent kwarg drops", "bool fields reject strings"). The fix covers top-level kwargs and 8 base bool fields. Two parallel paths still accept bad input and silently change, or silently do not change, what gets quantized.

1. Most bool fields still accept "False" (and become True)

BaseQuantizeConfig._validate_bool_fields (gptqmodel/quantization/config.py:5197) checks only sym, true_sequential, lm_head, compile, offload_to_disk, keep_processor_logs, auto_forward_data_parallel, wait_for_submodule_finalizers. Every other bool field is either coerced with bool(x) (bool("False") is True) or stored as the string, which is truthy. Results of passing the string "False" to every bool field of every concrete config:

static_groups                     -> 'False'  (GPTQConfig, QQQConfig, VPTQConfig)
mock_quantization                 -> 'False'  (GPTQConfig, QQQConfig, VPTQConfig)
scale_search_chunked_activations  -> 'False'  (AWQConfig)
enable_norm / enable_perm         -> 'False'  (VPTQConfig)
act_group_aware                   -> True     (GPTQConfig, QQQConfig)
compress_statistics               -> True     (BitsAndBytesConfig)
sym, do_flip, fast_flip, compile_flip, exp_screen -> True (MacaqConfig)
opt_amsgrad, opt_fused_rotation, opt_stage_cudagraph, opt_train_on_noisy_inputs -> True (ParoConfig)

By contrast, GPTQConfig(exclude_attention_sinks="False") and GPTQConfig(sym="False") correctly raise TypeError.

This has a real effect. GPTQConfig(mock_quantization="False") turns on the "skip heavy computations" mock solver (quantization/gptq.py:1663,2446). Qwen2.5-0.5B-Instruct truncated to 2 layers, GPTQ 4-bit g128, 16 C4 rows, CPU:

mock_quantization=False    in-session nll 16.193  reload 16.195
mock_quantization="False"  in-session nll 16.394  reload 16.391

static_groups="False" silently enables static groups in the same way.

2. Typo'd keys in dynamic overrides are silently ignored and persisted

_normalize_dynamic_layer_config (config.py:5120, plus the per-class overrides at 6791/7202/7317/7503/7640/7932) checks only the bits and group_size values. It does not check that the keys are known fields. A misspelled override is accepted, has no effect, and is written into the checkpoint:

cfg = GPTQConfig(bits=4, group_size=128, dynamic={r".*down_proj": {"bit": 8, "group_sise": 32}})
m = GPTQModel.load(qwen_2_layers, cfg, dtype=torch.bfloat16, device="cpu"); m.quantize(calib); m.save(out)
model.layers.0.mlp.down_proj.qweight I32 [608, 896]   # 4864*4/32 -> still 4-bit
model.layers.0.mlp.down_proj.scales  F16 [38, 896]    # 4864/128  -> still group 128
quantize_config.json dynamic: {'.*down_proj': {'bit': 8, 'group_sise': 32}}
nll 16.193 (identical to the run without `dynamic`); no warning logged

The same call with a top-level typo (GPTQConfig(bit=8)) raises TypeError with a close-match hint since #4057. Bad regexes (dynamic={"+:[": {...}}) are also accepted at construction and fail only later, when the pattern is first matched.

Suggested fix

  • Derive the bool set from the dataclass annotations (every field typed bool / Optional[bool]) and run _validate_bool_fields over all of them, in every concrete __post_init__, including EXL3/MACaQ/Paro, which override it.
  • In _normalize_dynamic_layer_config, reject keys that are not init fields of the target config class. Reuse the difflib close-match hint from _validate_quantize_config_factory_kwargs. Also re.compile each pattern (after stripping +:/-:) at construction. from_quant_config can stay lenient for legacy checkpoints, as it does for top-level keys.

Tests that should have caught it

tests/qcfg/test_config_serialization.py ("bool fields reject strings and ints") enumerates a fixed field list instead of every bool field. No test covers unknown keys inside dynamic.

Severity

Medium. Configs built from YAML, CLI or JSON strings silently quantize with a different algorithm. Misspelled per-module overrides silently produce a different mixed-precision layout than the one requested.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. Both paths: derive the bool set from the dataclass annotations so every bool field rejects strings (including EXL3/MACaQ/Paro overrides), and reject unknown keys in dynamic overrides with the same difflib close-match hint as top-level kwargs. Fix PR to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions