Skip to content

fix(config): validate per-module dynamic numeric overrides (#5503) - #5531

Merged
Qubitium merged 1 commit into
mainfrom
fix/dynamic-numeric-validation-5503
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/dynamic-numeric-validation-5503

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5503. Follow-up to #5444 (#5437).

__post_init__ validates the top-level group_size/damp_percent/damp_auto_increment and the Paro/MACaQ float options, but the dynamic merge copied per-module values verbatim. Every one of those checks was skipped for a dynamic rule:

accepted damp_percent 5.0
accepted damp_percent -1.0
accepted damp_percent inf
accepted damp_auto_increment -0.5
accepted group_size nan
accepted group_size 100

At quantize time damp_percent=nan ran every damp-recovery attempt with nan, was rescued by the Hessian diagonal floor, and was then written as a bare NaN into quantize_config.json (not valid JSON). group_size=nan only failed later inside quantize().

What Changed

  • Added _validate_dynamic_numeric_overrides(owner, layer_name, layer_dict) in gptqmodel/quantization/config.py, called from every _normalize_dynamic_layer_config (base, FP8, NF12, BnB, EXL3, GGUF; VPTQ already rejects all dynamic overrides):
    • group_size goes through _validate_group_size plus the existing supported-set error, so nan/non-integral values fail at construction and -7 keeps its message.
    • damp_percent (0, 1), damp_auto_increment >= 0, Paro's learning rates > 0 / opt_pair_ratio (0, 0.5] / opt_weight_decay/opt_eps/opt_sgd_momentum/opt_sgd_dampening/clamp bounds >= 0, opt_betas as two finite non-negative floats, MACaQ ridge >= 0 and pre_alpha [0, 1] — the same bounds as the top-level fields.
    • Every other int/float-annotated field (bits, mse, …) rejects NaN/inf.
    • Values are validated, not rewritten, so the per-module merge keeps its input types and serialization is unchanged.
  • The redundant group_size branch in the base normalizer is gone; the shared validator owns it.
  • No API change.

Tests

PYTHONPATH=$PWD GPTQ_BYPASS_SAFETY_CHECKS=1 /root/gptqmodel-test-venv/bin/python -m pytest \
  tests/test_config_numeric_validation_5437.py -q
# 55 passed

PYTHONPATH=$PWD GPTQ_BYPASS_SAFETY_CHECKS=1 /root/gptqmodel-test-venv/bin/python -m pytest \
  tests/test_dynamic.py tests/test_awq_dynamic_group_size.py \
  tests/test_dynamic_config_invalidation_4475.py tests/test_config_per_module_validation_4200.py \
  tests/test_gguf_dynamic_format.py tests/test_weight_only_config.py \
  tests/test_awq_dynamic_bits_gate_5408.py tests/test_config_serialization_roundtrip_4201.py \
  tests/test_norm_config.py tests/test_calibration_config.py -q
# 188 passed; the 4 test_dynamic.py errors are offline HF repo lookups, identical on origin/main

bash format/check.sh
# All checks passed!

New coverage in tests/test_config_numeric_validation_5437.py:

  • test_every_numeric_option_rejects_non_finite_values_through_dynamic sweeps every numeric field of every QuantizeConfig subclass through dynamic={"+:.*": {field: nan|inf|-inf}}.

  • test_reported_dynamic_overrides_are_rejected pins the issue's concrete values; 9 of its 10 cases are red on origin/main (the tenth, group_size=-7, was already rejected).

  • test_dynamic_numeric_overrides_keep_valid_values pins that in-range rules still construct and are not rewritten.

  • Unit tests have been executed and passed.

  • I added a new simple/fast unit test for this change.

Model Support / Module Plan

Not applicable: no new MODEL_MAP entry, model-type alias, or definition change.

AWQ onboarding safety

Not applicable: the change only validates numeric dynamic values at config construction; no grouping, search, replay, or fold change.

Logic Flow Documentation

Not applicable: no control flow changes. The per-module rule is validated with the same bounds the top-level fields already use.

Review Requirements

  • Reviewed this PR.
  • Code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching; extends the existing _normalize_dynamic_layer_config hook.
  • Minimized the impacted code surface: one shared validator, one call per normalizer.
  • Considered and eliminated potential regressions: validation is additive and does not rewrite values; group_size=100 is still accepted at construction, matching the top-level field.

Kernel Accuracy Requirements

Not applicable: no kernel math change.

Notes

group_size=100 remains accepted at config construction exactly like the top-level group_size, and still fails in select_quant_linear at quantize time. Rejecting it per-module only would have made the two paths disagree.

The dynamic merge copied its values verbatim, so the numeric checks that
__post_init__ runs on the top-level fields never saw a per-module rule:
damp_percent=nan quantized with every damp-recovery attempt failing and was
then rescued by the Hessian floor, damp_percent=5.0 used 5x the Hessian mean
with no warning, damp_auto_increment=-0.5 was accepted, and group_size=nan only
failed later inside quantize(). A NaN was also serialized into
quantize_config.json, where a bare NaN is not valid JSON.

Run the same bounds on one dynamic rule: group_size through _validate_group_size,
the damp/Paro/MACaQ float options through their top-level ranges, and a
finiteness check for every remaining numeric field. The FP8/NF12/BnB/EXL3/GGUF
overrides, which own their dynamic normalizer, now call the shared validator
too.

Fixes #5503
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