Skip to content

fix(config): reject fraction asymmetric percentiles and validate dynamic smoothers (#5005) - #5017

Merged
Qubitium merged 2 commits into
mainfrom
root/smooth-asym-bounds-5005
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
root/smooth-asym-bounds-5005

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5005. Two related gaps left by #4970 (fix of #4953):

  1. SmoothPercentileAsymmetric was never given the fraction rule.
    It reads the same 0-100 scale as SmoothPercentile through
    fallback_smooth._quantile, but only 0 <= low < high <= 100 was checked, so
    low=0.005, high=0.995 (meant 0.5% / 99.5%) constructed cleanly. With
    high <= 1 the upper bound lands next to the row minimum and
    _clamp_block pins almost every weight to the bottom tail — the model is
    destroyed with no error and no warning.

    C.SmoothPercentileAsymmetric(low=0.005, high=0.995)  # accepted
    C.SmoothPercentileAsymmetric(low=0.5,   high=0.99)   # accepted
    C.SmoothPercentile(percentile=0.99)                  # rejected by #4970
    
  2. Smoothers inside per-module dynamic overrides were not validated at
    construction.
    A rule is merged into a per-module config only when the
    module is first matched, so
    dynamic={"+:.*q_proj.*": {"fallback": {"smooth": {"type": "mad", "k": 0}}}}
    constructed cleanly and then raised from normalize_fallback in the middle of
    quantize(), after the model had already been mutated, with no module name
    in the message. Same for the
    {"preprocessors": [{"code": "smoother", "smooth": {...}}]} form.

What Changed

  • gptqmodel/quantization/config.py
    • new _validate_asymmetric_percentile_bounds(owner, low, high), called from
      SmoothPercentileAsymmetric.__init__:
      • high <= 1 -> ValueError naming the 0-100 scale (destructive: clamps
        almost every weight to the row minimum);
      • 0 < low < 0.1 -> ValueError naming the 0-100 scale (clips nothing at
        any realistic group size, so it is a fraction typo or dead config; 0
        stays the explicit "no lower clip").
        low cannot reuse the symmetric rule because the documented default is
        0.5 (the 0.5th percentile). The dict/JSON and SmootherConfig /
        Fallback(smooth=...) paths all go through this constructor, so they fail
        too.
    • new _validate_dynamic_smoothers(owner, layer_name, layer_dict): for every
      smoother-bearing key of one dynamic rule (fallback, preprocessors,
      smoother, smooth) it runs the same normalizer the runtime uses
      (_normalize_fallback, _normalize_preprocessors,
      _normalize_smoother_config) and re-raises with the offending module
      pattern named. It does not mutate the rule, so serialization and runtime
      normalization are unchanged.
    • wired into all four dynamic loops: BaseQuantizeConfig, FP8Config,
      BitsAndBytesConfig, EXL3Config.
  • tests/test_smooth_percentile_bounds_5005.py (new, 16 nodes), added to the
    AWQ CPU unit suite.

No change to SmoothPercentile / SmoothLog (their #4970 rule is re-asserted
by the new tests), no change to smooth_block/_quantile numerics, and no
change to any legal configuration.

Tests

tests/test_smooth_percentile_bounds_5005.py on unmodified origin/main
(24a46e337, test copied into a separate worktree): 7 failed, 9 passed.

failing node on main why
test_asymmetric_fraction_bounds_are_rejected[both-fractions] DID NOT RAISE for low=0.005, high=0.995
test_asymmetric_fraction_bounds_are_rejected[fraction-high] DID NOT RAISE for high=0.99
test_asymmetric_fraction_bounds_are_rejected[fraction-low] DID NOT RAISE for low=0.005
test_dict_and_wrapper_paths_reject_the_same_asymmetric_bounds SmootherConfig / Fallback accepted the fraction
test_dynamic_fallback_smoother_is_validated_at_construction dynamic rule with mad k=0 constructed
test_dynamic_preprocessor_smoother_is_validated_at_construction dynamic rule with a bad preprocessors smoother constructed
test_dynamic_smoother_field_is_validated_at_construction dynamic rule with a fraction smoother constructed

The 9 nodes that already pass are the legal-boundary cases, the unchanged
#4970 rules, and the numeric mechanism node (a 0.99 "percentile" clamps >90% of
a 128-wide block, 99.5 clamps <2%).

On this branch: 16 passed.

Neighbouring suites (config/fallback/smoother + AWQ scale-search safety + docs
contract), identical command on both trees:

tree result
origin/main 266 passed, 2 skipped
this branch 282 passed, 2 skipped (+16 = the new file)

tests/test_smoother_parameter_validation_4953.py (the #4970 guard) is part of
that run and stays green: low=0.0, high=100.0 and percentile=1.5 are still
legal. ruff check clean on both changed Python files.

Model Support / Module Plan

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

AWQ onboarding safety

Not applicable: no model onboarding, grouping, search, replay, or fold change.
The new test file is only wired into the AWQ CPU unit lane because that is the
CPU suite PRs actually run.

Logic Flow Documentation

Not applicable: the only control-flow change is a fail-closed rejection at
config construction (before a model is loaded), documented in the two new
function docstrings and pinned by the tests. No runtime decision order, data
lifecycle, or tensor flow changes.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions (reuses the runtime normalizers instead of duplicating the rules).
  • Avoided unnecessary monkeypatching; no test-only hooks were added to product code.
  • Minimized and compacted the impacted code surface (one helper per gap, four one-line call sites).
  • Considered and eliminated potential regressions: the full config/fallback/smoother suite is unchanged apart from the new file.

Kernel Accuracy Requirements

Not applicable: no kernel or fusion change.

Notes

  • Migration risk (deliberate). A checkpoint or script that carries
    SmoothPercentileAsymmetric(high<=1) or a non-zero low<0.1, or an invalid
    smoother inside a dynamic rule, now fails at construction/load with a
    field-named error instead of silently destroying the model or failing
    mid-quantize(). low=0 and low>=0.1 are unaffected, so the documented
    default 0.5 / 99.5 and 0 / 100 still work.
  • low uses a different threshold than high on purpose: low below 1 is
    legitimate (0.5 is the default), so the rule targets the values that clip
    nothing rather than the values that clip everything.

…mic smoothers (#5005)

`SmoothPercentileAsymmetric` reads the same 0-100 scale as
`SmoothPercentile` through `fallback_smooth._quantile`, but only the symmetric
smoothers were guarded. `low=0.005, high=0.995` (meant 0.5% / 99.5%)
constructed cleanly, and with `high <= 1` the upper bound lands next to the row
minimum, so `_clamp_block` pins almost every weight to the bottom tail: the
model is destroyed with no error or warning (#4953 was the same defect on
`SmoothPercentile`).

New `_validate_asymmetric_percentile_bounds` rejects `high <= 1` (destructive)
and a non-zero `low` below 0.1 (clips nothing, so it is a fraction typo or dead
configuration; `0` stays the explicit "no lower clip"). `low` legitimately sits
below 1 -- the documented default is 0.5 -- so it cannot reuse the symmetric
rule. The dict/JSON and `SmootherConfig`/`Fallback` paths go through the same
constructor and now fail too.

Second half: a smoother inside a per-module `dynamic` override is merged only
when the module is first matched, so `{"fallback": {"smooth": {"type": "mad",
"k": 0}}}` raised from the middle of `quantize()` -- after the model had been
mutated -- with no module name in the message. New
`_validate_dynamic_smoothers` runs the runtime normalizers (`_normalize_fallback`,
`_normalize_preprocessors`, `_normalize_smoother_config`) for every smoother
bearing key of a rule at construction, without mutating the rule, and names the
offending pattern. It is wired into all four `dynamic` loops (base, FP8,
bitsandbytes, EXL3).

Tests: `tests/test_smooth_percentile_bounds_5005.py` (16 nodes), added to the
AWQ CPU `unit` suite. On unmodified `origin/main` 7 of them fail (the three
fraction bounds, the dict/wrapper path, and all three `dynamic` forms); with the
fix 16 pass. The numeric node documents the mechanism: a 0.99 "percentile"
clamps >90% of a 128-wide block while 99.5 clamps <2%.
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