Repository navigation
chore(looper): remove dead helpers and share verify_calibration_dataset - #6422
Conversation
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]>
One test this refactor missesCross-checking this PR against the other open PRs, I ran Cause: consolidating the 12 per-processor 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 contextI 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 ( The only textual conflicts between the two sets are two additive hunks in 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 |
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-pastedverify_calibration_datasetbodies into oneLoopProcessormethod driven by a declared class attribute.Net diff:
18 files changed, 111 insertions(+), 258 deletions(-)(production code undergptqmodel/:+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_MAPand itsmodel_typedispatch. The map has been{}since Defuser took over fused-expert conversion (nn_modules/converter.py:21-24at the parent revision), soif model_type in MODULE_CONVERTER_MAPinstage_layer.py:815-818andweight_only_looper.py:1316-1319never ran. This PR deletes the dispatch, the wholenn_modules/converter.pymodule (whose_resolve_text_decoder_configalso had no callers), and the fournot in MODULE_CONVERTER_MAPasserts intests/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 ingptqmodel/,tests/,scripts/ordocs/._layer_callbackis still set frommodel.layer_callbackin__init__, and_resolve_layer_callbackis unchanged.ModuleLooper._run_forward_batches_single/_run_forward_batches_parallel(module_looper.py:1681-1776). These were pure pass-throughs toForwardExecutor.run_single/run_parallel, and onlytests/test_calibration_data_device.pyandtests/test_compute_device_filter.pycalled them. Production code uses_run_forward_batches→ForwardExecutor.run, which is unchanged. The tests now calllooper._forward_executor.run_single/run_paralleldirectly and pass their fakes through the executor's existingclone_module_for_devices_fn=/forward_batch_worker_fn=arguments, instead of monkeypatchingmodule_looperglobals that only the wrapper read. Because nothing else used them, theclone_module_for_devicesandforward_batch_workerimports inmodule_looper.pyare gone too.verify_calibration_dataset.calibration_dataset is None, else returnTrue. They now declarecalibration_dataset_owner = "<name>".LoopProcessor.verify_calibration_datasetraisesf"{calibration_dataset_owner}'s calibration_dataset must be provided."or returnsTrue. With no owner it returnsNone, as the oldpassdid, and does not read the dataset."GPTQProcessor", and G2PTQ inherits it as before. The other five are Native, EXL3, Macaq, VPTQ and Paro.awq_processor.py, only theverify_calibration_datasetcopy changed.docs/quantization-lifecycle-contracts.md, whichdocs/README.mdalready links.The following are intentionally out of scope; see Notes for each:
_resolve_layer_callbacklegacy fallbacks;ModuleLooper._is_attention_module_name;GPTQProcessor._release_host_buffers;ParoProcessor._build_group_adamw;Tests
New tests in
tests/test_quantization_lifecycle_contracts.py:test_calibrated_processors_keep_their_missing_dataset_error[*]has 18 cases: 9 processor classes ×processor_index0/1. Each checks the exact error text against a hard-coded table of the old strings, and that[]and a non-empty dataset returnTrue.test_processors_without_calibration_owner_do_not_check_the_dataset[*]has 3 cases:LoopProcessor,WeightOnlyProcessorandSharedInputCaptureProcessorreturnNonewithout the attribute.These 21 tests pass on both
origin/mainand this branch. As a red check, I swapped the message fortype(self).__name__(the map's original suggestion), and 6 cases failed: AWQ, QQQ and G2PTQ at both indexes.Skips: the same 52 on both sides, all for hardware or optional dependencies. The final run adds 7
test_exl3_cancelled_run_5083.pyskips (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_devicesandtest_output_moved_to_input_device_in_parallel_mode. I did not execute these after the rewrite. The same rewrite, a directrun_parallelcall with*_fnfakes, runs on CPU intest_compute_device_filter.py::test_compute_device_filter_applies_to_forward_devicesand::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_tensorsis 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_datasetacross every processor classThe script
verify_ab.pyimports everygptqmodel.looper.*module and walks all 15LoopProcessorsubclasses. For each class it callsverify_calibration_datasetwith datasetNone,[], non-empty, and attribute-unset, at index 0 and 1. It records the return value or the exception type and message.GPU A/B: live quantize path (
stage_layer,weight_only_looper, processor verify)batch_size=4, same seed on both sides.GPTQConfig(bits=4, group_size=128)throughModuleLooper, andRTNConfig(bits=4, group_size=128)throughWeightOnlyLooper.I ran this three times, at parent
1615accf9,6b25d2c69and407298ad2(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_MAPentry, 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 theverify_calibration_datasetcopy becamecalibration_dataset_owner = "GPTQProcessor", which keeps the same message.Logic Flow Documentation
file:lineevidence.docs/repeats the diagrams, titled for the mechanism, and is linked fromREADME.md. It isdocs/quantization-lifecycle-contracts.md, linked fromdocs/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 faila4471c53b)gptq_processor.py:1416copy, "GPTQProcessor's ..."calibration_dataset_owner = "GPTQProcessor"awq_processor.py:7591copy, "GPTQProcessor's ..."calibration_dataset_owner = "GPTQProcessor"qqq_processor.py:462copy, "GPTQProcessor's ..."calibration_dataset_owner = "GPTQProcessor"native_processor.py:308copycalibration_dataset_owner = "NativeProcessor"exllamav3_processor.py:3239copycalibration_dataset_owner = "EXL3Processor"macaq_processor.py:386copycalibration_dataset_owner = "MacaqProcessor"vptq_processor.py:324copycalibration_dataset_owner = "VPTQProcessor"paro_processor.py:3112copycalibration_dataset_owner = "ParoProcessor"loop_processor.py:1807pass→NoneNone→return NoneMODULE_CONVERTER_MAP[model_type]dispatch{}(nn_modules/converter.py:21-24). Dispatch sites:stage_layer.py:815-818,weight_only_looper.py:1316-1319register_layer_callbackmodule_looper.py:693, 0 references repo-wide_run_forward_batches_single/_parallelmodule_looper.py:1681-1776. Referenced only by the two test files aboveReview Requirements
I or an AI agent (such as Codex or Claude) have:
ForwardExecutor's existing*_fnarguments instead of patching module globals.Kernel Accuracy Requirements
Notes
AWQProcessorandQQQProcessorraise"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 intest_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._resolve_layer_callback's legacygptq_model.callbackup/gptq_model.callbackfallbacks (module_looper.py) need a maintainer decision on the public callback contract.ModuleLooper._is_attention_module_name,GPTQProcessor._release_host_buffersandParoProcessor._build_group_adamw(all test-only) were not in this PR's assigned scope.loop_processor.py, and instage_layer.pythe 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