Skip to content

refactor(processors): share the stat row, quant-module build and publish tail - #6429

Merged
Qubitium merged 1 commit into
mainfrom
refactor/looper-shared-stat-and-install
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
refactor/looper-shared-stat-and-install

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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. LoopProcessor now 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_module kwargs, and the console stat table).

git diff --shortstat origin/main: 9 files changed, 279 insertions(+), 435 deletions(-). Production code (gptqmodel/) is 158+/417-, net -259.

File + -
gptqmodel/looper/loop_processor.py (the 3 helpers) 81 2
gptqmodel/looper/gptq_processor.py (GPTQ, GPTAQ, FOEM, ...) 15 89
gptqmodel/looper/qqq_processor.py 4 81
gptqmodel/looper/vptq_processor.py 14 78
gptqmodel/looper/macaq_processor.py 12 70
gptqmodel/looper/paro_processor.py 25 67
gptqmodel/looper/weight_only_processor.py (RTN, GGUF, NF12, CPTC, BnB) 7 30
tests/test_quant_log_coverage_4321.py (new helper tests) 116 0
tests/test_benchmark_submodule_finalize.py (patch target moved) 5 18

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, then extra, then dynamic. It appends to durations/avg_losses/module_names/log under self.lock and calls log_new_row. The loss text uses the GPTQ/QQQ rule: a string is shown as-is, a number as .10f (and tracked in avg_losses), anything else as unknown.

    • Used by GPTQ (extra: (v)ram plus the workspace columns), QQQ, VPTQ, MACaQ, and Paro (extra: (v)ram; dynamic=False because Paro never wrote that column).
  • LoopProcessor.build_quant_module(module, model, linear_cls, *, qcfg=None, **overrides) makes the create_quant_module call that every site derived from its config: register_buffers=False, install=False, format=resolve_quant_format(...) and resolved_module_config=get_resolved_module_config(module), inside the existing create_quant_module log_time_block. Each site passes exactly the extra keywords it passed before:

    • VPTQ: backend, init_kwargs, dtype.
    • QQQ: backend.
    • MACaQ: its raw format=self.qcfg.format, plus backend, init_kwargs, dtype.
    • Paro: format=self.format and its per-module init_kwargs.
    • Weight-only: qcfg=active_qcfg and init_kwargs.
    • GPTQ: nothing extra.

    GPTQ, Paro and weight-only still hold parent_module_lock around the call.

  • LoopProcessor.publish_quant_module(module, model, qmodule) runs install_quant_module under parent_module_lock(module.full_name), then unregister_parameter("weight"). It replaces the tails in GPTQ, QQQ, VPTQ, MACaQ and both weight-only paths (direct pack and pack_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_save is 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_config and parent_module_lock where 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:

  • For GPTQ, Paro and weight-only, the 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. The quant_region_timer submodule_finalize_create record is unchanged.
  • GPTQ's early durations/avg_losses/module_names append moved into the row's lock. Nothing executable ran between the two places. VPTQ and MACaQ write their module.state results in their own locked block just before the row, instead of in the same block.
  • Paro's module_names/log appends were outside self.lock; they are now inside it.
  • VPTQ and MACaQ used to show unknown for a string loss. Their quantizers return floats (quantization/vptq.py:838, quantization/macaq.py:921), and Paro's val_loss is 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):

  • EXL3: its row is built under _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.
  • AWQ: the row has activation/scale columns, no fwd_time/damp/dynamic, and is not tracked in durations. The create call uses _module_bits(...) and self.gptq_model. It is not the same pattern, and the AWQ lifecycle work owns that file.
  • EoRA: the row has no loss/samples/damp columns.
  • Weight-only stat row: it records no durations/module_names, the processor has no avg_losses, and it has no dynamic column. Converting it would need two knobs for one site.
  • Out of scope: durations, avg_losses and module_names have no production reader (AWQ only checkpoints avg_losses). Removing them is a separate cleanup.

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_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 the durations/avg_losses/module_names tracking.
  • 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 with format/backend/dtype.
  • test_publish_quant_module_installs_then_drops_the_float_weight

Mutation evidence: each of these one-line mutations of the helpers makes at least one of these tests fail:

  • writing extra after dynamic;
  • VPTQ-style unknown for string losses;
  • dropping unregister_parameter;
  • ignoring the qcfg override;
  • tracking durations only for numeric losses.

The tests cannot be run against origin/main because the helpers do not exist there. Old-vs-new equivalence is shown by the A/B runs below.

tests/test_benchmark_submodule_finalize.py patched gptqmodel.looper.gptq_processor.create_quant_module, which no longer exists. It now patches loop_processor.create_quant_module and no longer wraps the removed result_pop. It passes on GPU on both trees: 3 passed on origin/main, 3 passed on this branch.

CPU suite, run on origin/main (a4471c5) and this branch, compared per node through junit XML:

export HF_HOME=/root/.cache/huggingface CUDA_VISIBLE_DEVICES="" PYTHONPATH=$PWD   # gptqmodel.__file__ -> this clone
python -P -m pytest -q -p no:cacheprovider -rs \
 tests/test_quant_telemetry.py tests/test_awq_qqq_pack_shape_4567.py tests/test_vptq.py tests/test_vptq_codebook_sum_5609.py tests/test_vptq_memory_4391.py \
 tests/test_checkpoint_resume_nf12_macaq_4792.py tests/test_run_exit_recovery_contract_5060.py tests/test_shared_input_hessian_dedup_methods.py \
 tests/test_shared_input_hessian_dedup.py tests/test_accelerator_memory_stats.py tests/test_finalize_module_lookup.py tests/test_gptq_bf16_pack_codes_5721.py \
 tests/test_gptaq_foem_bf16_pack_codes_5819.py tests/test_gptq_prepare_pack_owner_5960.py tests/test_weight_only_direct_pack_timing_5748.py tests/test_weight_only.py \
 tests/test_weight_only_looper.py tests/test_weight_only_processor_error.py tests/test_paro.py tests/test_paro_fallback_threshold_5510.py tests/test_paro_dynamic_overrides_5659.py \
 tests/test_paro_conv1d_orientation_5856.py tests/test_qqq_cpu.py tests/test_qqq_conv1d_pack_5604.py tests/test_qqq_per_channel_checkpoint_5126.py tests/test_macaq.py \
 tests/test_macaq_weight_narrow_5631.py tests/test_processor_finalize_4747.py tests/test_quant_log_coverage_4321.py tests/test_module_looper_quant_log_4321.py \
 tests/test_writer_quant_log.py tests/test_looper_concurrency.py tests/test_fallback.py tests/test_auto_dtype_cast.py tests/test_failed_run_fence_4595.py \
 tests/test_rtn_narrowed_endpoint.py tests/test_rtn_fallback_hessian_release_5778.py tests/test_g2ptq_processor.py tests/test_specialized_eora_lifecycle.py \
 tests/test_static_bugfix_regressions.py tests/test_cptc.py tests/test_looper_processor_capabilities.py tests/test_qqq_mock_rtn_5839.py tests/test_macaq_wide_bias_5632.py \
 tests/test_paro_rotation_lifecycle.py tests/test_weight_only_tied_lm_head_5027.py tests/test_gptq_workspace_release.py tests/test_checkpoint_telemetry.py
# origin/main: 2 failed, 1428 passed, 324 skipped
# branch:      2 failed, 1436 passed, 324 skipped
# 1754 shared nodes: 0 differ. The only new nodes are the 8 helper tests above (all pass).
  • 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_weight and ::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:

    • VPTQ CUDA kernels: 78 + 6 + 3 + ...
    • CPTC native kernels: 31 + 5
    • MACaQ Triton: 27
    • G2PTQ accelerator/e2e: 22 + 7
    • Paro CUDA: 15 + 9 + 6 + ...
    • weight-only CUDA microbench and GGUF Triton: 14 + 13 + ...
    • two-device tests

    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's pip install was 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.py per tree (PYTHONPATH=<tree> python -P, gptqmodel.__file__ printed). Both trees use the same config, torch/numpy/random seed 0, 64 fixed synthetic calibration rows and batch_size=1. For each run, the comparison checks:

  • every saved safetensors tensor, byte for byte;
  • every config json;
  • quant_log.csv, sorted with the time column dropped;
  • the in-memory model.quant_log rows as ordered (key, value) lists, with time/fwd_time/(v)ram blanked;
  • the kwargs of every create_quant_module call, recorded by a spy installed wherever the looper modules bind that name;
  • the console per-module stat table (header and rows, ANSI stripped, time/fwd_time/(v)ram cells masked).
Method Config Path covered Tensors quant_log rows / key order create_quant_module calls Console table lines Result
GPTQ 4-bit g128, dynamic={"+:.*down_proj.*": {"bits": 8}} row (+memory, dynamic), build, publish 794 168, ...,(v)ram,dynamic 168 192 bit-identical
GPTAQ 4-bit g128, gptaq=GPTAQConfig() GPTQProcessor path 794 168 168 192 bit-identical
QQQ QQQConfig(4, 128) row, build, publish 626 168 168 192 bit-identical
MACaQ MacaqConfig() row, build (raw format), publish 794 168 168 192 bit-identical
VPTQ small codebooks row, build, publish 1130 168 168 192 bit-identical
Paro 4-bit g128, 1+1 epochs, 16/8 samples row (dynamic=False), build 1130 168, ...,(v)ram 168 192 bit-identical
RTN RTNConfig(4, 128) weight-only build + pack_module publish 794 168 168 177 bit-identical
GGUF GGUFConfig("q4_k_m") weight-only build + direct-pack publish 290 168 168 177 bit-identical

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, WeightOnlyProcessor and 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

  • This change does not alter a major logic flow, or the required diagrams and docs page are included below.

Not applicable: the same calls run in the same order. Each processor's copy moves into one LoopProcessor method, and no decision mechanism is replaced. Old site → new helper (main line numbers):

Old copy (origin/main) New
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-671 record_stat_row
gptq_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-298 build_quant_module
gptq_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-409 publish_quant_module

Review Requirements

  • 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 change. Packed outputs are bit-identical (see the GPU A/B).

Notes

🤖 Generated with Claude Code

…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
Qubitium marked this pull request as ready for review November 29, 2026 20:11
@Qubitium
Qubitium merged commit b0bf62d into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the refactor/looper-shared-stat-and-install branch November 29, 2026 20:12
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]>
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