Skip to content

fix(config): validate smoother parameters at construction (#4953) - #4970

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4953
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4953

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4953.

What was unvalidated

All seven smoother descriptors accepted any numeric value; the same for SmootherConfig, Fallback(smooth=...) and the dict/JSON parser:

descriptor field old behaviour
SmoothPercentile percentile 0-100 scale; <=0 clamps to the row min, >=100 is a no-op, 0.99 clamps almost everything to the min
SmoothPercentileAsymmetric low, high low > high produced a meaningless clamp
SmoothMAD k k=0 clamps every row to its median; k<0 gives lo > hi
SmoothMSE steps, maxshrink steps<=0 / maxshrink outside (0,1] silently clamped
SmoothOutlier pct pct>=100 clamps to the smallest |w| (destructive)
SmoothSoftNorm k k<=0 collapses every z-score
SmoothLog percentile, mu same percentile scale; mu<=0 silently became eps
SmoothRowCol axis any typo silently meant "row"
all group_size_threshold non-int/negative accepted

Bounds chosen

  • SmoothMAD.k > 0, SmoothSoftNorm.k > 0, SmoothLog.mu > 0 (finite positive; zero/negative collapse the block). The issue's "k must be an int" cannot be literal — the default is 2.75.
  • SmoothPercentile.percentile / SmoothLog.percentile: 1 < value <= 100. Confirmed from _quantile: it divides by 100, so the field is a percent, not a fraction; <=0 clamps to the min and >=100 is the max. 0.99 gets a dedicated fraction-vs-percent message.
  • SmoothPercentileAsymmetric: 0 <= low < high <= 100.
  • SmoothMSE.steps int >= 1; maxshrink in (0, 1].
  • SmoothOutlier.pct in [0, 100); SmoothRowCol.axis in {"row", "col"} (normalized to lowercase); group_size_threshold int >= 0.
  • Fallback.__post_init__ now parses/validates a directly supplied smooth payload, so Fallback(smooth={"type":"mad","k":0}) fails at construction.
  • Every message names the owner class, field, offending value and range, e.g. SmoothMAD: k must be > 0, got 0.0.

Evidence

Destructive behaviour on parent (direct smooth_block, torch.randn(4,128)): MAD k=0 -> row_std=[0,0,0,0] (rel_change 1.000); pct 0.99 -> rel_change 0.975; k=2.75/pct 99 -> 0.076/0.085.

  • New tests/test_smoother_parameter_validation_4953.py on origin/main: 25 failed, 13 passed (DID NOT RAISE for SmoothMAD(k=0), SmoothPercentile(0.99), and the rest); fixed: 38 passed.
  • tests/qcfg + test_quant_formats.py + test_fallback.py + test_weight_only*.py + test_config_serialization_roundtrip_4201.py + test_module_preprocessor.py + test_mlx_rtn_quantization.py + kernels/test_fallback.py: 443 passed, 13 skipped, 1 environment error (test_quantize_0_gptq cannot find c4-train.00000-of-01024.json.gz at fixture setup).
  • ruff check gptqmodel tests: clean.

Residual risk

  • Configs using SmoothPercentile(percentile<=1), SmoothOutlier(pct>=100) or a non-int group_size_threshold now fail loudly at construction. Those values were destructive or silently clamped.
  • SmoothPercentileAsymmetric does not apply the fraction heuristic (its default low=0.5 is itself sub-1), so low=0.5, high=0.99 remains legal.
  • Dict/JSON numeric values are still float()/int()-coerced before the constructor, so a non-numeric string there raises a generic conversion error rather than the field-named one.
  • SmoothMSE.steps=1 is accepted although the internal search clamps to >=3.

Codex and others added 2 commits November 17, 2026 19:59
None of the Smooth* descriptors validated their numeric fields. SmoothMAD(k=0)
clamped every row to its median and SmoothPercentile(percentile=0.99) read a
fraction as the 0.99th percentile, destroying the model with no error or
warning (measured NLL 15 -> 61/87).

Add semantic validation to every smoother constructor, which is the public
config surface reached by direct construction, SmootherConfig, Fallback and
the dict/JSON parser:

- MAD/SoftNorm k > 0 (finite)
- percentile on the 0-100 scale with 1 < value <= 100 (rejects the
  0.99 fraction case; 100 is the documented max)
- asymmetric 0 <= low < high <= 100
- MSE steps >= 1 (int) and 0 < maxshrink <= 1
- outlier 0 <= pct < 100
- log mu > 0 and the same percentile rule
- rowcol axis in {row, col}
- group_size_threshold an int >= 0

Fallback now parses its smoother payload in __post_init__, so a directly
constructed Fallback(smooth={...}) is validated too. Error messages name the
field, offending value and valid range.
@Qubitium
Qubitium merged commit 55f9d9f into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4953 branch November 17, 2026 20:16
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
…ntized loads (ModelCloud#4945) (ModelCloud#4972)

`ModelLoader.from_quantized` popped the options it knew and let every other
keyword reach `QuantizeConfig.from_pretrained`, which ignored it. A typo of a
real option (`dtpye=`, `attn_implmentation=`, `devcie_map=`) or an option that
does not apply (`bits=`) therefore "succeeded" and changed nothing, while the
unquantized path raises from the HF constructor. A passed `quantize_config`
was dropped the same way: the checkpoint's config won without a word.

Wrap the keyword dict in `_TrackedKwargs`, which records every key consumed by
`pop`, and raise `TypeError` for whatever is left after the internal keys are
normalised. The accepted set is derived from `inspect.signature(cls.from_quantized)`,
the recorded pops, and `inspect.signature(snapshot_download)` (the Hub staging
options), so a newly added parameter or pop is accepted without editing a
literal list. The message reuses the difflib close-match style of ModelCloud#4686:
`dtpye` now points at `dtype`. VLLM/SGLang keep their explicit passthrough
runtime options.

`GPTQModel.load(quantized, quantize_config=...)` now raises `ValueError`
instead of ignoring the argument: a quantized checkpoint's
bits/group_size/method/format come from the checkpoint, and forwarding a
different config was not provably safe.

Two loader tests passed `quantize_config=` to `from_quantized`, relying on the
silent drop; they now call it without that argument.

Closes ModelCloud#4945.

Also switch the `extract_adapter_rank_patterns` citation in
docs/adapter-rank-pattern-matching.md to the symbol form
(`config.py::extract_adapter_rank_patterns`). ModelCloud#4970 added ~137 lines above that
definition, so the old `config.py:5595` citation fails
`tests/test_docs_contract_refs.py` on pristine main and blocks the required
AWQ CPU (unit) check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Smoother parameters are never validated: SmoothMAD(k=0) / SmoothPercentile(percentile=0.99) silently destroy the model (RTN nll 15 -> 61 / 86)

1 participant