Skip to content

fix(config): reject non-finite calibration options at construction (#5307) - #5316

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

Qubitium merged 1 commit into
mainfrom
fix/config-numeric-validation-5307

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5307.

The calibration-option dataclasses validated only the type of their numeric
fields. NaN/inf/negative values constructed, round-tripped through
quantize_config.json, and then either silently disabled the feature or failed
deep inside the first layer:

  • MSEConfig(norm=nan|-1.0) silently disabled the MSE grid (bit-identical to
    no MSE).
  • FOEMConfig(alpha=nan) raised KeyError: 'native_inp' during quantization.
  • GPTAQConfig(alpha=nan|-5.0) and FOEMConfig(beta=nan) failed later with a
    NaN-loss error.
  • HessianConfig(sink_row_cap_median_multiple=nan) was accepted.
  • HessianConfig(chunk_size=True) / chunk_bytes=True were accepted as 1.

NaN comparisons are always false, so each range check now validates the
normalized float and rejects non-finite values explicitly.

What Changed

  • gptqmodel/quantization/config.py: new _validate_finite_float(owner, field, value, minimum=...) helper.
    • MSEConfig.norm: finite and >= 0.
    • GPTAQConfig.alpha: finite and >= 0.
    • FOEMConfig.alpha / beta: finite and >= 0.
    • HessianConfig.sink_row_cap_median_multiple: finite and >= 0.
    • HessianConfig.chunk_size / chunk_bytes: reject bool as well as
      non-int values.
  • tests/test_calibration_option_validation_5307.py: 15 invalid cases
    (nan, inf, negative, bool) and 10 legal boundary cases, plus the
    QuantizeConfig.from_quant_config(...) dict path.

Tests

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

PYTHONPATH=$PWD GPTQ_BYPASS_SAFETY_CHECKS=1 \
  /root/gptqmodel-test-venv/bin/python -m pytest \
  tests/test_config_serialization_roundtrip_4201.py \
  tests/test_config_per_module_validation_4200.py \
  tests/test_calibration_config.py tests/test_quant_bits_validation.py \
  tests/test_moe_config.py tests/test_norm_config.py -q
# 315 passed; 4 errors in test_moe_config.py from a missing hard-coded
# /monster/data/model/Qwen3-30B-A3B-layers-1 fixture (pre-existing on this host)

ruff check gptqmodel/quantization/config.py \
  tests/test_calibration_option_validation_5307.py
# All checks passed!

The 15 invalid cases fail on the parent commit; the legal boundary cases pass
both before and after.

Model Support / Module Plan

Not applicable: no model, alias, or module-plan change.

Logic Flow Documentation

Not applicable: construction-time validation only; no runtime flow changes.

Kernel Accuracy Requirements

Not applicable: no kernel or quantization math change.

Notes

MSEConfig(norm=0) remains the documented "disable the search" value.
ExpertsRoutingBypass.batch_size is unchanged: it intentionally coerces
numeric strings and already rejects zero/negative values.

…5307)

MSEConfig.norm accepted NaN/negative and silently disabled the MSE search; FOEMConfig.alpha=NaN crashed later with KeyError: native_inp; GPTAQ alpha and Hessian sink caps accepted NaN or negative values. Validate these fields with a shared finite/range helper, and reject bool for Hessian chunk_size/chunk_bytes.
@Qubitium
Qubitium marked this pull request as ready for review November 19, 2026 01:09
@Qubitium
Qubitium merged commit 7574568 into main Nov 19, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/config-numeric-validation-5307 branch November 19, 2026 01:09
Qubitium added a commit that referenced this pull request Nov 19, 2026
…5444)

* test(paro): make the prewarm gating test independent of session state (#5430)

`test_paro_prewarm_rotation_extension_skips_unsupported_configs` patched
`_PARO_ROTATION_EXTENSION.load` and expected one call. The product never
reaches that attribute once the extension is loaded: `prewarm_*` calls
`_load_rotation_extension()`, which returns True immediately from the module
global `_ROTATION_EXTENSION_READY` and otherwise asks
`_extension_api().is_available("paro")`.

So the test only passed when it was the first thing in the process to touch
the extension. Any earlier test that runs a real fused rotation set the flag
and the assertion became `assert [] == ['load']`.

Patch the seam the product actually calls, `_load_rotation_extension`, which
is already how the neighbouring tests in this file spy on the same helper,
and add a test that pins the "already loaded" state the old test tripped on:
a prewarm there must return True without probing or rebuilding.

Verified on main 8618744:
  pytest tests/test_paro_rotation_inference_cache_5317.py \
         tests/test_paro.py::test_paro_prewarm_rotation_extension_skips_unsupported_configs
  before: 1 failed, 3 passed  (assert [] == ['load'])
  after:  4 passed
  pytest tests/kernels/test_paro_triton_cudagraph_5225.py <same test>
  before: 1 failed, 5 passed
  after:  6 passed
  pytest tests/test_paro.py: 245 passed

* fix(config): reject NaN/inf in every numeric quantize option (#5437)

#5316 added `_validate_finite_float` for MSEConfig/FOEMConfig/GPTAQConfig/
HessianConfig only. Every other config still accepted NaN/inf, and NaN
compares false against every bound, so the option was silently ignored or
silently replaced:

  MacaqConfig(ridge=nan)             -> flip refinement off (applies only if ridge > 0)
  ParoConfig(opt_rotation_lr=nan)    -> +13.8% wikitext-2 PPL, no warning
  VPTQConfig(npercent=nan)           -> outlier codebook silently disabled
  <any>Config(group_size=nan|inf)    -> per-channel fallback / NaN divisor
  MacaqConfig(bits=nan)              -> silently rewritten to 4

Changes:
- `_validate_group_size` rejects non-finite and non-integral group_size and
  normalizes integral floats; called from `BaseQuantizeConfig.__post_init__`
  and from `EXL3Config`/`MacaqConfig`, which force the value before the base
  check can see it.
- ParoConfig routes its nine float options (LRs, weight decay, eps, betas,
  SGD momentum/dampening, channel clamp bounds) through `_validate_finite_float`.
- MacaqConfig validates `ridge`, and rejects a non-MXFP4 `bits`/`group_size`
  instead of overwriting it (`-1` stays accepted as the "unset" sentinel).
- VPTQConfig validates `npercent` and type-checks `group_num`, `kmeans_iters`,
  `kmeans_seed`, `block_size`.
- GPTQConfig/QQQConfig/VPTQConfig validate the inherited `damp_auto_increment`.

A new parametrized sweep walks every numeric field of every QuantizeConfig
subclass, so a new field cannot reintroduce the hole.

Red -> green (tests/test_config_numeric_validation_5437.py):
  main @ 8618744: 27 failed, 2 passed
  this branch:      29 passed

No regressions: tests/test_paro.py + tests/test_macaq.py 344 passed,
tests/test_vptq.py + tests/test_vptq_outlier_bounds.py 329 passed,
config serialization/validation suites 203 passed. ruff clean.
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