Repository navigation
refactor(processors): share the stat row, quant-module build and publish tail - #6429
Merged
Merged
Conversation
…ish tail GPTQ (and GPTAQ/FOEM through it), QQQ, VPTQ, MACaQ, Paro and the weight-only processors each carried their own copy of three blocks: - the per-module log row: identity columns, loss/samples/damp/time/fwd_time, optional extras and the `dynamic` column, the locked durations/avg_losses/ module_names/log appends, and `log_new_row`; - the 15-keyword `create_quant_module(..., register_buffers=False, install=False)` call derived from the processor's config, wrapped in the `create_quant_module` timing block; - the #5089 publish tail: `install_quant_module` under the parent module lock, then `unregister_parameter("weight")`. LoopProcessor now owns `record_stat_row`, `build_quant_module` and `publish_quant_module`. Each call site passes only what varies today: its damp string, extra columns (GPTQ's memory and workspace columns, Paro's memory column), `dynamic=False` for Paro, `backend`/`init_kwargs`/`dtype`, MACaQ's raw `format`, Paro's resolved `format` and per-module `init_kwargs`, and the weight-only processor's active config. Key order, and therefore the console table and quant_log column order, is unchanged. The `result_pop(module.full_name)` calls in the GPTQ, QQQ, VPTQ and MACaQ publish tails are dropped: those processors never call `result_save`, so the pops always missed (only EoRA stores results). EXL3 (journal lock, deferred inline-candidate stats, open #6413 rewrites this block), EoRA (no loss columns), the weight-only stat row (untracked, no dynamic column) and AWQ (different columns and config source) keep their own code. No numerics, checkpoint-format or public-API change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 29, 2026 20:11
11 tasks done
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…nly and exl3 (#6677) PR #6429 added `LoopProcessor.record_stat_row`, `build_quant_module` and `publish_quant_module` and moved GPTQ (GPTAQ/FOEM), QQQ, VPTQ, MACaQ, Paro, NVFP4, TETRA and TWLA onto them. It left four stat-row copies behind: EoRA (no loss columns), the weight-only processor (untracked rows, no dynamic column), EXL3 (private stats lock, extra workspace columns) and AWQ (different columns and config source; out of scope). Finish the three non-AWQ copies: - `record_stat_row` gains `include_loss=False` (EoRA rows describe adapter fitting and have no loss/samples/damp columns) and `track=False` (weight-only rows are published without appending to durations, avg_losses or module_names), and returns the row it published (EXL3 returns its stat). - EoRA passes the measured `(v)ram` as `extra` with `include_loss=False`. - Weight-only passes `(v)ram`/`lifecycle` as `extra` with `track=False` and `dynamic=False`. - EXL3 builds its `(v)ram`, `loss_kind`, `exl3_*` and optional workspace columns into one ordered `extra` dict and appends the row under the shared `self.lock` instead of `_stats_lock`; every other reader and writer of the row state already uses `self.lock`. The two `__new__` test fixtures that call `process` get a lock. The map's EXL3 `defer_stats` branch no longer exists (removed by #6413), so there is no deferred path to keep. Key order, row values (except time and the live memory measurement), `durations` length, `module_names` and the installed/saved state are unchanged. The CPU A/B covers weight-only RTN, EoRA plus the GPTQ control and an EXL3 stubbed-quantizer run; the GPU 4 A/B on Llama-3.2-1B GPTQ, QQQ and MACaQ is bit-identical and quant_log.csv is identical except the time column. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Debloat refactor (R4 in the looper map). GPTQ, QQQ, VPTQ, MACaQ, Paro and the weight-only processors each had their own copy of three blocks: the per-module stat row, the 15-keyword
create_quant_module(..., install=False)call, and the #5089 publish tail.LoopProcessornow owns one plain implementation of each (record_stat_row,build_quant_module,publish_quant_module), and each call site passes only what actually varies. Behavior does not change. A GPU A/B on Qwen2.5-0.5B-Instruct is bit-identical for all 8 quantization paths it covers (saved tensors, config jsons,quant_log.csv, in-memory quant_log rows including key order,create_quant_modulekwargs, and the console stat table).git diff --shortstat origin/main:9 files changed, 279 insertions(+), 435 deletions(-). Production code (gptqmodel/) is158+/417-, net -259.gptqmodel/looper/loop_processor.py(the 3 helpers)gptqmodel/looper/gptq_processor.py(GPTQ, GPTAQ, FOEM, ...)gptqmodel/looper/qqq_processor.pygptqmodel/looper/vptq_processor.pygptqmodel/looper/macaq_processor.pygptqmodel/looper/paro_processor.pygptqmodel/looper/weight_only_processor.py(RTN, GGUF, NF12, CPTC, BnB)tests/test_quant_log_coverage_4321.py(new helper tests)tests/test_benchmark_submodule_finalize.py(patch target moved)What Changed
LoopProcessor.record_stat_row(module, *, loss, nsamples, damp, duration, extra=None, dynamic=True)builds the row in the existing key order: identity columns, then loss, samples, damp, time and fwd_time, thenextra, thendynamic. It appends todurations/avg_losses/module_names/logunderself.lockand callslog_new_row. The loss text uses the GPTQ/QQQ rule: a string is shown as-is, a number as.10f(and tracked inavg_losses), anything else asunknown.(v)ramplus the workspace columns), QQQ, VPTQ, MACaQ, and Paro (extra:(v)ram;dynamic=Falsebecause Paro never wrote that column).LoopProcessor.build_quant_module(module, model, linear_cls, *, qcfg=None, **overrides)makes thecreate_quant_modulecall that every site derived from its config:register_buffers=False,install=False,format=resolve_quant_format(...)andresolved_module_config=get_resolved_module_config(module), inside the existingcreate_quant_modulelog_time_block. Each site passes exactly the extra keywords it passed before:backend,init_kwargs,dtype.backend.format=self.qcfg.format, plusbackend,init_kwargs,dtype.format=self.formatand its per-moduleinit_kwargs.qcfg=active_qcfgandinit_kwargs.GPTQ, Paro and weight-only still hold
parent_module_lockaround the call.LoopProcessor.publish_quant_module(module, model, qmodule)runsinstall_quant_moduleunderparent_module_lock(module.full_name), thenunregister_parameter("weight"). It replaces the tails in GPTQ, QQQ, VPTQ, MACaQ and both weight-only paths (direct pack andpack_module). Paro keeps its own install because it never unregistered the weight.The
result_pop(module.full_name)calls in the GPTQ/QQQ/VPTQ/MACaQ tails are dropped. Nothing ever stores a result on those processors:result_saveis only called by EoRA (eora_processor.py:426), so these pops always missed.Unused imports are removed: the log-column constants,
create_quant_module,install_quant_module,resolve_quant_format,get_resolved_module_configandparent_module_lockwhere they are no longer used.No numerics, checkpoint-format or public-API change.
Timing and locking details that are not output-visible, listed for review:
create_quant_module[time]log block (it only prints when time logging is enabled) now sits inside the parent lock rather than around it. As a result it no longer counts lock wait time. Thequant_region_timersubmodule_finalize_createrecord is unchanged.durations/avg_losses/module_namesappend moved into the row's lock. Nothing executable ran between the two places. VPTQ and MACaQ write theirmodule.stateresults in their own locked block just before the row, instead of in the same block.module_names/logappends were outsideself.lock; they are now inside it.unknownfor a string loss. Their quantizers return floats (quantization/vptq.py:838,quantization/macaq.py:921), and Paro'sval_lossis always a float (quantization/paro/optimization.py:2319,_evaluate_group_layer*). So the shared formatter produces the same text for all of them.Left alone on purpose (no shared helper fits without extra knobs, or the code is owned by other work):
_stats_lock(serialized with the error-journal append), it has the deferred inline-candidate path, and chore(exl3): delete remote workers and inline mixed tiers #6413 just rewrote that block.fwd_time/damp/dynamic, and is not tracked indurations. The create call uses_module_bits(...)andself.gptq_model. It is not the same pattern, and the AWQ lifecycle work owns that file.durations/module_names, the processor has noavg_losses, and it has nodynamiccolumn. Converting it would need two knobs for one site.durations,avg_lossesandmodule_nameshave no production reader (AWQ only checkpointsavg_losses). Removing them is a separate cleanup.Tests
New tests in
tests/test_quant_log_coverage_4321.py(8 nodes). They pin what callers rely on, with literal expected values:test_record_stat_row_columns_and_tracking[float|int|string|missing]: the exact ordered(key, value)list of the row, the loss text rule, and thedurations/avg_losses/module_namestracking.test_record_stat_row_dynamic_column_is_last_and_optional[True|False]test_build_quant_module_derives_kwargs_from_the_given_config: the exact kwargs dict for the default config, and for an override config withformat/backend/dtype.test_publish_quant_module_installs_then_drops_the_float_weightMutation evidence: each of these one-line mutations of the helpers makes at least one of these tests fail:
extraafterdynamic;unknownfor string losses;unregister_parameter;qcfgoverride;durationsonly for numeric losses.The tests cannot be run against
origin/mainbecause the helpers do not exist there. Old-vs-new equivalence is shown by the A/B runs below.tests/test_benchmark_submodule_finalize.pypatchedgptqmodel.looper.gptq_processor.create_quant_module, which no longer exists. It now patchesloop_processor.create_quant_moduleand no longer wraps the removedresult_pop. It passes on GPU on both trees:3 passedon origin/main,3 passedon this branch.CPU suite, run on
origin/main(a4471c5) and this branch, compared per node through junit XML:The 2 failures are pre-existing and identical on
origin/main:tests/test_processor_finalize_4747.py::test_awq_pack_module_drops_the_dense_fake_quantized_weightand::test_gptaq_quantize_clears_the_native_caches_before_returning. Their tiny fixture tokenizer is rejected by the unusable-tokenizer guard, which is unrelated to this change.The 324 skips are all accelerator-gated, because this was a CPU-only run. The largest groups:
These leave the kernel paths in those files unverified on CPU. The quantize → pack → publish path of each converted processor is covered on GPU by the A/B below.
The same suite was also run before the rebase (base 407298a), with the same per-node result.
bash format/check.sh:ruff 0.14.2,All checks passed!(the script'spip installwas stubbed; the venv already has ruff 0.14.2).GPU A/B (Qwen2.5-0.5B-Instruct, one GPU)
The out-of-tree driver runs
quant_ab.pyper tree (PYTHONPATH=<tree> python -P,gptqmodel.__file__printed). Both trees use the same config,torch/numpy/randomseed 0, 64 fixed synthetic calibration rows andbatch_size=1. For each run, the comparison checks:quant_log.csv, sorted with thetimecolumn dropped;model.quant_logrows as ordered(key, value)lists, with time/fwd_time/(v)ram blanked;create_quant_modulecall, recorded by a spy installed wherever the looper modules bind that name;dynamic={"+:.*down_proj.*": {"bits": 8}}dynamic), build, publish...,(v)ram,dynamicgptaq=GPTAQConfig()QQQConfig(4, 128)MacaqConfig()dynamic=False), build...,(v)ramRTNConfig(4, 128)pack_modulepublishGGUFConfig("q4_k_m")All 8 rows were run on the pre-rebase base (407298a). GPTQ and Paro were rerun after rebasing onto a4471c5 and are bit-identical again.
Not run on GPU (same
GPTQProcessor,WeightOnlyProcessorand helper code as the rows above): FOEM, JointQ, G2PTQ, NF12, CPTC and BnB. VPTQ and Paro used reduced optimizer/codebook settings to keep the runs short; with the defaults they are too slow for a quick A/B.Measured Impact
Not applicable: this is a behavior-preserving debloat with no claimed issue. Saved tensors are bit-identical.
Model Support / Module Plan
Not applicable: no model, alias, definition or module-plan change.
AWQ onboarding safety
Not applicable: AWQ is untouched (see "Left alone on purpose").
Logic Flow Documentation
Not applicable: the same calls run in the same order. Each processor's copy moves into one
LoopProcessormethod, and no decision mechanism is replaced. Old site → new helper (main line numbers):gptq_processor.py:1089-1093,1117-1162,qqq_processor.py:302-330,vptq_processor.py:210-241,macaq_processor.py:277-306,paro_processor.py:650-671record_stat_rowgptq_processor.py:1275-1298,qqq_processor.py:385-410,vptq_processor.py:265-291,macaq_processor.py:333-354,paro_processor.py:2997-3030,weight_only_processor.py:278-298build_quant_modulegptq_processor.py:1357-1367,qqq_processor.py:441-450,vptq_processor.py:304-313,macaq_processor.py:364-372,weight_only_processor.py:371-374,406-409publish_quant_moduleReview Requirements
Kernel Accuracy Requirements
Not applicable: no kernel change. Packed outputs are bit-identical (see the GPU A/B).
Notes
verify_calibration_datasetin the same files). That was checked with a local trial merge.🤖 Generated with Claude Code