Skip to content

chore(looper): remove dead helpers and share verify_calibration_dataset - #6422

Merged
Qubitium merged 1 commit into
mainfrom
refactor/looper-dead-helpers
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
refactor/looper-dead-helpers

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Behavior-preserving debloat of gptqmodel/looper/ (debloat map R8, "dead helpers"). It deletes three helpers that do nothing in production and folds eight copy-pasted verify_calibration_dataset bodies into one LoopProcessor method driven by a declared class attribute.

Net diff: 18 files changed, 111 insertions(+), 258 deletions(-) (production code under gptqmodel/: +19 / -195).

No numerics, checkpoint-format or public-API change. Every processor's error text stays the same (see the follow-up in Notes).

What Changed

  • MODULE_CONVERTER_MAP and its model_type dispatch. The map has been {} since Defuser took over fused-expert conversion (nn_modules/converter.py:21-24 at the parent revision), so if model_type in MODULE_CONVERTER_MAP in stage_layer.py:815-818 and weight_only_looper.py:1316-1319 never ran. This PR deletes the dispatch, the whole nn_modules/converter.py module (whose _resolve_text_decoder_config also had no callers), and the four not in MODULE_CONVERTER_MAP asserts in tests/test_qwen_moe_converter.py. Those tests still check the Defuser conversion itself.
  • ModuleLooper.register_layer_callback (module_looper.py:693). It had no callers in gptqmodel/, tests/, scripts/ or docs/. _layer_callback is still set from model.layer_callback in __init__, and _resolve_layer_callback is unchanged.
  • ModuleLooper._run_forward_batches_single / _run_forward_batches_parallel (module_looper.py:1681-1776). These were pure pass-throughs to ForwardExecutor.run_single / run_parallel, and only tests/test_calibration_data_device.py and tests/test_compute_device_filter.py called them. Production code uses _run_forward_batches → ForwardExecutor.run, which is unchanged. The tests now call looper._forward_executor.run_single/run_parallel directly and pass their fakes through the executor's existing clone_module_for_devices_fn= / forward_batch_worker_fn= arguments, instead of monkeypatching module_looper globals that only the wrapper read. Because nothing else used them, the clone_module_for_devices and forward_batch_worker imports in module_looper.py are gone too.
  • verify_calibration_dataset.
    • Eight processors each had the same body: raise if calibration_dataset is None, else return True. They now declare calibration_dataset_owner = "<name>".
    • LoopProcessor.verify_calibration_dataset raises f"{calibration_dataset_owner}'s calibration_dataset must be provided." or returns True. With no owner it returns None, as the old pass did, and does not read the dataset.
    • The owner is the exact string each copy used: GPTQ, AWQ and QQQ use "GPTQProcessor", and G2PTQ inherits it as before. The other five are Native, EXL3, Macaq, VPTQ and Paro.
    • EoRA (index-dependent reuse), Dequantize and ModulePreProcessor keep their own overrides.
    • In awq_processor.py, only the verify_calibration_dataset copy changed.
  • Docs. I added a short section, a Mermaid diagram, a before/after row and a failure row to docs/quantization-lifecycle-contracts.md, which docs/README.md already links.

The following are intentionally out of scope; see Notes for each:

  • the _resolve_layer_callback legacy fallbacks;
  • ModuleLooper._is_attention_module_name;
  • GPTQProcessor._release_host_buffers;
  • ParoProcessor._build_group_adamw;
  • fixing the AWQ/QQQ message text.

Tests

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

New tests in tests/test_quantization_lifecycle_contracts.py:

  • test_calibrated_processors_keep_their_missing_dataset_error[*] has 18 cases: 9 processor classes × processor_index 0/1. Each checks the exact error text against a hard-coded table of the old strings, and that [] and a non-empty dataset return True.
  • test_processors_without_calibration_owner_do_not_check_the_dataset[*] has 3 cases: LoopProcessor, WeightOnlyProcessor and SharedInputCaptureProcessor return None without the attribute.

These 21 tests pass on both origin/main and this branch. As a red check, I swapped the message for type(self).__name__ (the map's original suggestion), and 6 cases failed: AWQ, QQQ and G2PTQ at both indexes.

export HF_HOME=/root/.cache/huggingface CUDA_VISIBLE_DEVICES="" CUDA_DEVICE_ORDER=PCI_BUS_ID
PYTHONPATH=$PWD python -P -m pytest -p no:cacheprovider -rs -q \
  tests/test_calibration_data_device.py tests/test_compute_device_filter.py tests/test_subset_plan.py \
  tests/test_qwen_moe_converter.py tests/module_tree/test_subset.py tests/test_stage_modules.py \
  tests/test_quantization_lifecycle_contracts.py tests/test_model.py tests/test_module_looper_disk_probe.py \
  tests/test_failed_run_fence_4595.py tests/test_weight_only_looper.py tests/test_weight_only.py \
  tests/test_cancelled_quantize_layer_cleanup_4546.py tests/test_cancelled_quantize_disk_offload_4807.py \
  tests/test_cancelled_quantize_default_offload_4860.py tests/test_weight_only_failed_run_device_5011.py \
  tests/test_module_looper_quant_log_4321.py
# branch rebased on 6b25d2c69: 268 passed, 52 skipped (2721.95s)
# origin/main 6b25d2c69:       247 passed, 52 skipped (2528.16s)   (the +21 are the new tests)
# same 52 skips on both sides (only line numbers shift)

# rebased on 407298ad2 (#6399 touched exllamav3_processor.py), same list plus
#   tests/test_exl3_generic_geometry.py tests/test_exl3_cancelled_run_5083.py:
# 276 passed, 59 skipped (2241.83s): the 52 above + 7 "EXL3 quantization needs an NVIDIA CUDA device"

# head adc5fe911, rebased on a4471c53b (#6413 shifted exllamav3_processor.py again): same list + test_docs_contract_refs.py, -n 8.
# 510 passed, 59 skipped in 1064.44s (= 276 + 234 docs; same 59 skips as the 407298ad2 run)
# verify_ab.py IDENTICAL and format/check.sh passes at this head.

PYTHONPATH=$PWD python -P -m pytest -p no:cacheprovider -q tests/test_docs_contract_refs.py
# 234 passed in 229.69s

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

Skips: the same 52 on both sides, all for hardware or optional dependencies. The final run adds 7 test_exl3_cancelled_run_5083.py skips (CUDA EXL3 quantize).

  • tests/test_calibration_data_device.py, 6 tests, "Requires at least 2 CUDA devices". Three of these are the rewritten callers of the deleted wrappers: test_balanced_mode_assigns_batches_to_input_devices, test_balanced_mode_fallback_when_input_device_not_in_forward_devices and test_output_moved_to_input_device_in_parallel_mode. I did not execute these after the rewrite. The same rewrite, a direct run_parallel call with *_fn fakes, runs on CPU in test_compute_device_filter.py::test_compute_device_filter_applies_to_forward_devices and ::test_parallel_forward_writes_shared_kv_cache_when_model_requests_it, and both pass. The CPU single-path rewrite, test_output_moved_to_input_device_in_single_mode, also passes.
  • tests/test_weight_only.py, 40 tests, CUDA-only GGUF/RTN microbench.
  • tests/test_weight_only_failed_run_device_5011.py, 4 tests, "needs an accelerator".
  • tests/test_model.py, 2 tests: compressed_tensors is not installed, and one test is ROCm-only.

The test suites ran with CUDA hidden. The GPU A/B below covers the live quantize path on GPU.

Structural A/B: verify_calibration_dataset across every processor class

The script verify_ab.py imports every gptqmodel.looper.* module and walks all 15 LoopProcessor subclasses. For each class it calls verify_calibration_dataset with dataset None, [], non-empty, and attribute-unset, at index 0 and 1. It records the return value or the exception type and message.

PYTHONPATH=<origin/main tree> python -P verify_ab.py base.json
PYTHONPATH=<branch tree>      python -P verify_ab.py branch.json
cmp base.json branch.json   # IDENTICAL: 105 rows, 15 classes (rerun at each of the three bases)

GPU A/B: live quantize path (stage_layer, weight_only_looper, processor verify)

  • Model: Qwen2.5-0.5B-Instruct on one GPU.
  • Calibration: 32 seeded synthetic samples, batch_size=4, same seed on both sides.
  • Two runs per tree: GPTQConfig(bits=4, group_size=128) through ModuleLooper, and RTNConfig(bits=4, group_size=128) through WeightOnlyLooper.
  • Each run saved a checkpoint. I compared every safetensors tensor bit-for-bit (dtype, shape, bytes) and every JSON file between the two trees.
gptq files: 8 tensors compared: 794
rtn files: 8 tensors compared: 794
BIT-IDENTICAL

I ran this three times, at parent 1615accf9, 6b25d2c69 and 407298ad2 (origin/main at the final head). All three runs were bit-identical. All JSON files (config, quantize_config, tokenizer, generation) are equal.

Measured Impact

Not applicable: this is dead-code removal and consolidation with no claimed performance, VRAM or accuracy effect. Saved checkpoints are bit-identical.

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, alias, definition, module plan or fusion change.

Model test node IDs and results: not applicable.

AWQ onboarding safety

Not applicable: no AWQ grouping, search, replay or fold change. In awq_processor.py, the only change is that the verify_calibration_dataset copy became calibration_dataset_owner = "GPTQProcessor", which keeps the same message.

Logic Flow Documentation

  • This change does not alter a major logic flow, or the required diagrams and docs page are included below.
  • New-flow Mermaid diagram(s) describe the shipped code using real symbol names.
  • The removed/replaced mechanism is shown or tabulated with file:line evidence.
  • Failure and ambiguity paths are marked and visually distinct from success.
  • A reference page under docs/ repeats the diagrams, titled for the mechanism, and is linked from README.md. It is docs/quantization-lifecycle-contracts.md, linked from docs/README.md.

Diagram summary: eight per-processor method copies are replaced by declared metadata (calibration_dataset_owner). The decision and its outcomes are unchanged.

flowchart TD
    L["ModuleLooper loop start<br/>module_looper.py:2136"] --> A["processor.verify_calibration_dataset(p_index)"]
    A --> O{"override?<br/>EoRA / Dequantize / ModulePreProcessor"}
    O -->|yes| X["processor's own rule<br/>unchanged"]
    O -->|no| B{"calibration_dataset_owner<br/>is None?"}
    B -->|yes| N["return None<br/>adopt_previous_calibration"]
    B -->|no| C{"calibration_dataset<br/>is None?"}
    C -->|no| T["return True<br/>capture inputs"]
    C -->|yes| E["raise ValueError<br/>owner's calibration_dataset must be provided."]
    classDef fail fill:#fdd,stroke:#c00
    class E fail
Loading
Processor Before (origin/main a4471c53b) After
GPTQ (+ G2PTQ by inheritance) gptq_processor.py:1416 copy, "GPTQProcessor's ..." calibration_dataset_owner = "GPTQProcessor"
AWQ awq_processor.py:7591 copy, "GPTQProcessor's ..." calibration_dataset_owner = "GPTQProcessor"
QQQ qqq_processor.py:462 copy, "GPTQProcessor's ..." calibration_dataset_owner = "GPTQProcessor"
Native native_processor.py:308 copy calibration_dataset_owner = "NativeProcessor"
EXL3 exllamav3_processor.py:3239 copy calibration_dataset_owner = "EXL3Processor"
MaCAQ macaq_processor.py:386 copy calibration_dataset_owner = "MacaqProcessor"
VPTQ vptq_processor.py:324 copy calibration_dataset_owner = "VPTQProcessor"
Paro paro_processor.py:3112 copy calibration_dataset_owner = "ParoProcessor"
Base / WeightOnly / SharedInputCapture loop_processor.py:1807 pass → None owner None → return None
EoRA, Dequantize, ModulePreProcessor own overrides unchanged
Removed dead path Evidence it never ran (origin/main)
MODULE_CONVERTER_MAP[model_type] dispatch Map is {} (nn_modules/converter.py:21-24). Dispatch sites: stage_layer.py:815-818, weight_only_looper.py:1316-1319
register_layer_callback module_looper.py:693, 0 references repo-wide
_run_forward_batches_single/_parallel module_looper.py:1681-1776. Referenced only by the two test files above

Review Requirements

I or an AI agent (such as Codex or Claude) have:

  • 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. The tests now inject fakes through ForwardExecutor's existing *_fn arguments instead of patching module globals.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

  • Not applicable: no kernel, packer or dispatch change.
  • Not applicable: no fusion support change.
  • Not applicable: no kernel inventory change.

Notes

  • Follow-up, not done here because it would change behavior. AWQProcessor and QQQProcessor raise "GPTQProcessor's calibration_dataset must be provided.", which names the wrong processor. With this PR, fixing it is a one-string change: calibration_dataset_owner = "AWQProcessor" / "QQQProcessor", plus the expected-text table in test_quantization_lifecycle_contracts.py. I kept the current text because callers or tests may match on it. G2PTQ also says "GPTQProcessor" through inheritance, which is arguably correct.
  • Left for a separate change:
    • _resolve_layer_callback's legacy gptq_model.callbackup / gptq_model.callback fallbacks (module_looper.py) need a maintainer decision on the public callback contract.
    • ModuleLooper._is_attention_module_name, GPTQProcessor._release_host_buffers and ParoProcessor._build_group_adamw (all test-only) were not in this PR's assigned scope.
  • Rebase. I rebased on refactor(looper): declare processor capabilities instead of isinstance branches #6406 (processor capabilities). The conflicts were textual only: adjacent class attributes in loop_processor.py, and in stage_layer.py the imports that refactor(looper): declare processor capabilities instead of isinstance branches #6406 and this PR each removed. I then rebased on refactor(exl3): drop the unwired completed-checkpoint-tree restore API #6399 without conflicts. After each rebase I reran the A/Bs and suites above.

🤖 Generated with Claude Code

Remove looper code that has no production effect, and fold eight
copy-pasted verify_calibration_dataset bodies into one base method.

- Delete gptqmodel/nn_modules/converter.py. MODULE_CONVERTER_MAP has been
  empty since Defuser took over the fused-expert conversion, so the
  model_type dispatch in StageLayer and WeightOnlyLooper never ran. The
  unused _resolve_text_decoder_config helper in the same module goes too.
- Delete ModuleLooper.register_layer_callback (no callers).
- Delete ModuleLooper._run_forward_batches_single/_parallel, pure
  pass-throughs to ForwardExecutor.run_single/run_parallel that only tests
  called. The tests now call the executor directly and pass their fakes
  through the existing clone_module_for_devices_fn/forward_batch_worker_fn
  arguments instead of patching module_looper globals.
- LoopProcessor.verify_calibration_dataset now raises
  "<calibration_dataset_owner>'s calibration_dataset must be provided."
  when a processor declares calibration_dataset_owner and has no dataset.
  GPTQ, Native, QQQ, EXL3, Macaq, AWQ, VPTQ and Paro declare the owner
  string their copy used, so every error text is unchanged (AWQ and QQQ
  still say "GPTQProcessor"). Processors without an owner keep the old
  None return; EoRA, Dequantize and ModulePreProcessor keep their own
  overrides.

No numerics, checkpoint-format or public-API change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium

Copy link
Copy Markdown
Collaborator Author

One test this refactor misses

Cross-checking this PR against the other open PRs, I ran #6422 alone on main = a4471c53b and it fails a node that main passes (133 passed on main, 1 failed with this PR):

tests/test_looper_processor_capabilities.py::test_gptq_never_inherits_previous_calibration
AttributeError: 'types.SimpleNamespace' object has no attribute 'calibration_dataset_owner'
  gptqmodel/looper/loop_processor.py:1815

Cause: consolidating the 12 per-processor verify_calibration_dataset overrides onto LoopProcessor means the base implementation now reads self.calibration_dataset_owner, but this test calls it unbound with a bare SimpleNamespace(calibration_dataset=None). You updated 4 other test files for the same refactor; this one was missed.

Fix (behaviour-preserving — the fake receiver just needs the attribute the base class now reads):

receiver = types.SimpleNamespace(
    calibration_dataset=None,
    calibration_dataset_owner="GPTQ",
)

There are two such receivers in that test; both need it.

How I found it, for context

I built five combined trees of this debloat series against the open feature PRs to check for semantic conflicts (a debloat that deletes a symbol another PR adds). No debloat PR removes a symbol any open PR depends on — 20 raw name matches, all of them prose in comments/docstrings, zero code references. Deleted modules (utils.exl3_error_ledger, nn_modules.converter) are never imported by the open PRs, and no debloat PR deletes a file they touch.

The only textual conflicts between the two sets are two additive hunks in docs/backend-selection.md (#6060 × this series' #6427 and #6436), resolvable by keeping all three sections.

So this is the one thing worth fixing before the series lands. Everything else is independent, and landing the series first makes the older feature PRs strictly easier to merge (8 of them are behind main).

@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 20:15
@Qubitium
Qubitium merged commit 908923a into main Nov 29, 2026
8 checks passed
@Qubitium
Qubitium deleted the refactor/looper-dead-helpers branch November 29, 2026 20:16
Qubitium added a commit that referenced this pull request Nov 30, 2026
…6406/#6422 follow-up) (#6466)

#6422 moved verify_calibration_dataset to LoopProcessor, where it reads
calibration_dataset_owner; the #6406 test still called it on a bare
SimpleNamespace and failed with AttributeError on main.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant