Skip to content

fix(dynamic): apply every per-module override in Paro, RTN and GPTQ (#5573) - #5638

Merged
Qubitium merged 1 commit into
mainfrom
fix/5573-dynamic-overrides
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5573-dynamic-overrides

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5573.

dynamic accepted, range-checked and serialized every known quantize-config
field, but each processor copied only a hand-written subset into its
per-module config. The remaining keys were silently ignored, so runs with
different rules produced bit-identical checkpoints while
quantize_config.json claimed the overrides were used.

This PR makes the per-module clone the single source of truth: a deep copy
applies the whole resolved rule and re-runs the config's own
__post_init__ (the contract MACaQ already used), and the Paro, RTN and GPTQ
consumers read that clone.

Method Applied per module before Now applied per module
Paro bits, group_size, sym, format every field in module scope; grouped scopes apply the keys they can build per module
RTN bits, sym, group_size, desc_act, smoother plus mse (scalar or {"norm": ...})
GPTQ apply_scalar_module_overrides fields + fallback/hessian/gptaq/foem/gsq plus damp_auto_increment

What Changed

  • gptqmodel/quantization/config.py
    • New apply_module_overrides() and clone_config_for_module(): apply the
      full ResolvedModuleConfig.overrides map to a deep copy, normalize nested
      dataclasses through the top-level normalizers, then re-run
      __post_init__ so validation ranges and aliases still hold.
    • apply_scalar_module_overrides() now copies damp_auto_increment
      (GPTQ reads it while rebuilding the Hessian).
    • clone_weight_only_config_for_module() now copies mse for RTN.
    • ParoConfig rejects two rules it cannot honor instead of silently
      dropping them: opt_scope inside a rule, and shared optimizer-stage keys
      (opt_rotation_epochs, LRs, opt_batch_size, ...) when
      opt_scope is layer/compute_block (those scopes run one optimizer
      over a whole group). Module scope, the default, accepts all of them.
  • gptqmodel/looper/paro_processor.py
    • New per-module config cache and _module_qcfg(); _target_sample_rows().
    • _quantize_one_module, _identity_fallback_result,
      _build_group_optim_linear, _layer_input_features and pack_module
      read the clone instead of self.qcfg.
    • _module_seed, _stage_learning_rates,
      _gradient_checkpointing_enabled and
      _module_scope_stage_cudagraph_enabled accept the per-module config
      (defaulting to self.qcfg, so existing grouped call sites are unchanged).
  • tests/test_dynamic_overrides_applied_5573.py: eight fast CPU tests pinning
    the config -> consumer chain for RTN (real quantization), GPTQ, Paro module
    scope (real optimizer kwargs) and Paro grouped scope, plus the two new
    fail-closed rules.

No public API was removed. The only behavior change for existing configs is
that Paro grouped scopes now raise on per-module optimizer keys they would
otherwise ignore; module scope behavior is unchanged for keys that already
worked.

Tests

python -m pytest tests/test_dynamic_overrides_applied_5573.py -q
# 8 passed

python -m pytest tests/test_config_numeric_validation_5437.py \
  tests/test_config_per_module_validation_4200.py \
  tests/test_config_serialization_roundtrip_4201.py -q
# 196 passed

python -m pytest tests/test_paro.py tests/test_paro_batch_lr_5306.py \
  tests/test_paro_fallback_threshold_5510.py tests/test_mlx_paro_optimize.py -q -ra
# 243 passed, 1 skipped, 23 failed

bash format/check.sh
# ruff 0.14.2
# All checks passed!

The 23 failures are all pre-existing GPU-kernel tests in tests/test_paro.py
(rotation launch config, pair-grad sweep, fused rotation grad). They hard-code
a device assumption that does not hold in this single-GPU worker environment;
test_paro_rotation_launch_config_honors_config_overrides fails identically on
unmodified origin/main at 5fddd3a3e. None of those tests touch the files
changed here, and the same 23 fail before and after the change.

The one skip is tests/test_mlx_paro_optimize.py (MLX optimization requires
macOS).

Red evidence

Run against unmodified origin/main (5fddd3a3e) with the same new test file:

python -m pytest tests/test_dynamic_overrides_applied_5573.py -q --tb=line
# 7 failed, 1 passed
  • RTN: assert 0.0 == 2.0 (clone.mse.norm stayed at the run-level value).
  • GPTQ: assert 0.01 == 0.5 (damp_auto_increment stayed at the run-level value).
  • Paro: AttributeError: 'ParoProcessor' object has no attribute '_module_qcfg'
    (no per-module clone existed), including both grouped-scope tests.
  • Scope rules: Failed: DID NOT RAISE ValueError (both fail-closed cases).

The one passing baseline test is the positive module-scope acceptance case,
which already worked on main.

Model Support / Module Plan

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

AWQ onboarding safety

Not applicable: no AWQ grouping, search, replay or fold change.

Logic Flow Documentation

The change is a local resolution fix that reuses MACaQ's existing
__post_init__ contract; it does not introduce a new user-facing mechanism or
change a kernel/data-placement flow. The shipped resolution path is:

flowchart TD
    A["BaseQuantizeConfig.dynamic"] --> B["resolve_module_config(module_full_name)"]
    B --> C{"ResolvedModuleConfig.excluded"}
    C -->|"yes"| D["clone_config_for_module returns None<br/>module is skipped"]
    C -->|"no"| E["copy.deepcopy(config)"]
    E --> F["apply_module_overrides(clone, resolved_cfg)"]
    F --> G["clone.__post_init__()"]
    G --> H["ParoProcessor._module_qcfg cache"]
    H --> I["_quantize_one_module<br/>_build_group_optim_linear<br/>pack_module"]
    H --> J["_layer_input_features<br/>_module_seed<br/>_stage_learning_rates"]
    G -. "ValueError" .-> K["Paro grouped scope rejects<br/>shared optimizer keys and per-module opt_scope"]
Loading

A separate docs/ page was not added because this is a bug fix to the
existing per-module config resolution, not a new mechanism page; the
fail-closed contract is documented in the ParoConfig docstring and covered
by the new tests. Reviewer can request a dedicated page if desired.

Review Requirements

AI-assisted code is welcome. Opened as a draft.

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel code changed. The 23 pre-existing kernel test
failures above are environment/device-index issues, not accuracy drift from
this PR.

Notes

  • ROCm gap: the issue was filed on ROCm gfx1201, but this worker only has an
    NVIDIA sm_80 device. The change is config/processor-level and device-agnostic
    and adds no device-specific code; ROCm kernel paths were not exercised here.
  • Grouped Paro scopes (layer, compute_block) run one optimizer/epoch loop
    over the whole group, so per-module optimizer-stage values cannot be applied
    there. They now raise a ValueError naming the supported per-module keys
    instead of accepting and ignoring the rule. opt_scope="module" (the
    default) applies every field.
  • pack_module now receives the per-module clone so per-module pack_impl
    and pack-device settings are honored as well.

@Qubitium
Qubitium marked this pull request as ready for review November 20, 2026 03:46
@Qubitium
Qubitium merged commit d56fbc7 into main Nov 20, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5573-dynamic-overrides branch November 20, 2026 03:47
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Post-merge review: #5638

Scope: head 6f00e9f5 vs merge-base 5fddd3a3 (the PR's own 3-file diff, +574/−83). The PR base at merge was 7193189d; the extra files in git diff 7193189d HEAD are unrelated main commits. Merged as d56fbc79.

Verdict: Directionally correct, but incomplete for Paro. The RTN mse and GPTQ damp_auto_increment fixes are real, and the Paro optimizer now reads the per-module clone. However, two accepted per-module Paro keys still do not reach their consumer, and the new tests stop before the pack/finalize boundary, so the highest-impact one is invisible to CI.

High: per-module krot is used by the optimizer but not by the packed ParoLinear

  • gptqmodel/looper/paro_processor.py:2967-2985 constructs the final module with self.qcfg.runtime_bits / desc_act / group_size / sym and init_kwargs=self.qcfg.quant_linear_init_kwargs() (line 2982). ParoConfig.quant_linear_init_kwargs() returns the top-level krot (gptqmodel/quantization/config.py:8319-8323).
  • resolve_module_constructor_config() (gptqmodel/quantization/module_config.py:103-239) has branches for FP8, BitsAndBytes, GGUF and MXFP4, but none for FORMAT.PARO, so a per-module krot in overrides never reaches options. Repro: resolve_module_constructor_config(..., format=FORMAT.PARO, init_kwargs={"krot": 8}, overrides={"krot": 1}).options_dict() returns {"krot": 8}.
  • The optimizer uses the clone: qcfg.krot at paro_processor.py:671, :716, :923 and :932, with the clone built by _module_qcfg() (:468-496). The rotation buffers are shaped by that krot (gptqmodel/utils/paro.py:106-108, gptqmodel/nn_modules/qlinear/paro.py:343-347).
  • paro_processor.py:3024 then copies the optimizer's pairs into the top-level-sized buffer. copy_ broadcasts when the clone krot is smaller: top=8/dynamic=1 silently replicates the single row across all 8 packed stages (theta too), and the reference/fused rotation loops apply the same Givens sweep 8 times instead of once (gptqmodel/utils/paro.py:282-325; gptqmodel_ext/paro/rotation.cu:220-226 dispatches the packed krot). That is not the rotation the optimizer quantized under. When the clone krot is larger, copy_ raises RuntimeError at :3024 after the optimizer work: top=8/dynamic=16, top=1/dynamic=8 and top=8/dynamic=4 were all verified to fail.
  • The quantize_config=self._module_qcfg(module) at paro_processor.py:3016 feeds pack_impl, pack device and format-conversion decisions inside pack_module (gptqmodel/utils/model.py:1381-1383, :1484-1490), but it does not rebuild the constructor's krot buffers. Checkpoint metadata records the packed top-level krot (gptqmodel/looper/checkpoint_modules.py:86 → gptqmodel/quantization/module_config.py:263-275), so the optimizer's krot is not preserved either.
  • PARO_PER_MODULE_DYNAMIC_KEYS advertises krot as applied in every scope (gptqmodel/quantization/config.py:8071-8084), so this is a documented-but-broken path.

Fix direction: pass the module clone's init kwargs into create_quant_module (or add a PARO branch to resolve_module_constructor_config), and add a pack-level test that asserts qmodule.krot and buffer shapes for top=8/dynamic=1 and top=8/dynamic=16.

Medium: per-module fallback is cloned, then ignored by the decision

  • apply_module_overrides normalizes fallback into the clone (gptqmodel/quantization/config.py:4552-4553), but ParoProcessor.preprocess sets self.fallback = normalize_fallback(fallback, self.qcfg.fallback) (paro_processor.py:2835) from the processor-level value the looper passes (gptqmodel/looper/module_looper.py:2075,2551). _module_fallback_requested() (paro_processor.py:508-519) and _log_fallback() (:537-548) read self.fallback, not self._module_qcfg(module).fallback.
  • Repro: top fallback.threshold="0.5%", dynamic {"fallback": {"strategy": "rtn", "threshold": "1.0%"}}, raw_tokens=5, total_calibration_tokens=1000 → clone threshold 1.0% (would fall back), processor threshold 0.5% (does not). This is the same accepted/saved/ignored class the PR is fixing. fallback is not in PARO_GROUPED_SCOPE_SHARED_DYNAMIC_KEYS, so it is accepted in every scope.

Fix direction: resolve resolved_cfg.get("fallback") over the processor default in preprocess (as GPTQ/MACaQ do), or read the clone in _module_fallback_requested/_log_fallback, with a threshold test.

Low: explicit None (inherit) is rejected by the grouped-scope guard

_validate_dynamic_module_scope (gptqmodel/quantization/config.py:8284-8317) rejects a key based on presence, not value. ParoConfig(opt_scope="layer", dynamic={"+:.*": {"opt_rotation_epochs": None}}) raises even though None means "inherit the top-level value" for this config. Verified. Consider skipping None values, or document that explicit None is not allowed.

Minor: other accepted-but-not-consumed Paro keys

PARO_PER_MODULE_DYNAMIC_KEYS is only used in the grouped-scope error text; module scope accepts any key the base validator allows. kernel is a BaseQuantizeConfig field (config.py:6620) and the clone receives it (verified clone.kernel.paro_cache_runtime_dtype=True), but the pack path uses the top-level self.qcfg.quant_linear_init_kwargs() (paro_processor.py:2982), so the packed layer keeps the top-level kernel. damp_percent, static_groups and desc_act are also accepted and cloned; only desc_act reaches the constructor, and the Paro optimizer does not consume any of the three. These are pre-existing acceptance gaps rather than regressions, but the PR's "every field" claim is broader than the actual consumption; either consume the advertised keys or reject the rest explicitly.

Test evidence

  • cd tests && python -m pytest test_dynamic_overrides_applied_5573.py -q → 8 passed at HEAD.
  • Same file against parent 5fddd3a3 in a separate worktree → 7 failed, 1 passed. The failures are the intended red reasons (RTN mse stayed 0.0; GPTQ damp_auto_increment stayed 0.01; Paro missing _module_qcfg; both grouped rejections DID NOT RAISE). Note the Paro red evidence is an AttributeError for the new helper, not a behavioral assertion, so it does not independently prove the old optimizer path dropped these values; the direct repros above do.
  • python -m pytest test_config_numeric_validation_5437.py test_config_per_module_validation_4200.py test_config_serialization_roundtrip_4201.py -q → 196 passed.
  • python -m pytest test_paro.py test_paro_batch_lr_5306.py test_paro_fallback_threshold_5510.py test_mlx_paro_optimize.py -q -ra → 243 passed, 1 skipped, 23 failed. The 23 are native gptqmodel_paro_rotation JIT build failures in this environment (torch.ops JIT compilation failed ... using fallback path, then assert False in test_paro_rotation_launch_config_honors_config_overrides); the representative test fails identically on parent 5fddd3a3. They are not caused by this PR, but leave the fused/native Paro paths unverified here. (The PR description calls these "device assumption" failures; the captured error is a JIT build failure.)
  • bash format/check.sh → ruff 0.14.2, All checks passed!.

Coverage gaps

  • No pack/finalize test for Paro; all Paro tests stop at the optimizer kwargs or the rotation-buffer builder, so the krot mismatch is invisible.
  • GPTQ test asserts config equality only (tests/test_dynamic_overrides_applied_5573.py:88-107); no GPTQ quantization/tensor assertion.
  • RTN test covers scalar mse only (:54-85); not {"norm": 2.0} or a partial-dict merge (grid_budget).
  • No test that quantize_config.json / module_constructor_config matches the applied per-module values.

Unverified

  • ROCm gfx1201 (the issue's environment); this host is NVIDIA sm_80.
  • Native Paro fused rotation/GEMM kernels (JIT build failure above), so the numerical consequence of the krot broadcast was reasoned from the reference/kernel KROT loops, not executed end-to-end.
  • Full PYTHON_GIL=0 multi-thread qualification of the changed paths.

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