You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Quantizing with format=FORMAT.GPTQ_V2 saves zero points +1 (model accuracy destroyed) #4167
Severity: high — silent corruption on the write path Version: 7.11.0 @ 6c3421c
Summary
quantize() then save() with format=gptq_v2 writes qzeros that are one step too high. Loading existing v2 checkpoints is fine; only checkpoints written this way are affected.
Reproduce
fromgptqmodelimportGPTQModel, QuantizeConfig, BACKENDfromgptqmodel.quantizationimportFORMATforfmtin (FORMAT.GPTQ, FORMAT.GPTQ_V2):
cfg=QuantizeConfig(bits=4, group_size=128, sym=False, desc_act=False, format=fmt)
m=GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", cfg)
m.quantize(calib, batch_size=1); m.save(f"q_{fmt}")
m2=GPTQModel.load(f"q_{fmt}", backend=BACKEND.GPTQ_TORCH)
# NLL on a short prompt
Format
NLL after save → reload
gptq
1.488
gptq_v2
16.679
Unit level, packing with pack_module(..., quantize_config=QuantizeConfig(format=GPTQ_V2)) into TorchLinear:
saved zeros equal z+1 with marker 2;
reloading and running forward gives relative error 0.945 (vs 3.4e-4 with FORMAT.GPTQ).
Root cause
utils/model.py:1386-1403: after packing, module.qzero_format(format=2) is set only when resolve_quant_format(...) == FORMAT.GPTQ. For GPTQ_V2 the module keeps _qzeros_format = 1 from __init__ (nn_modules/qlinear/__init__.py:1327), even though the packer wrote logical (v2) zeros.
checkpoint_layout_qzeros() (__init__.py:~1549) and the writer's _checkpoint_layout_buffer (utils/model.py:~2562) then treat the logical zeros as v1 and add 1.
Related: the raw pack() / pack_original / pack_block / pack_gpu methods never set qzero_format(2). A direct pack() caller gets logical words labelled v1 (marker 1), which reload one step low. hf_pack_layer already handles this correctly.
Suggested fix
After packing, always record that the live buffer holds logical zeros (qzero_format(2)), whatever the export format.
Let checkpoint_layout_qzeros() convert only when the target format is v1.
Add an e2e test for format=gptq_v2 quantize → save → reload.
Found during an AI-assisted review (Claude Code) of 6c3421c; repros were run on RTX 4090/5090 (CUDA 13) and Radeon AI PRO R9700 (ROCm) unless marked static/suspected.
Second user-facing path with the same root cause, found at 9dad249: resuming staged GSQ from its per-layer checkpoint shifts every zero point by +1 (silent corruption on resume).
quantization/gsq_training.py:~1365-1368 calls TorchLinear.pack_original(...). That writes logical (v2) zero words but leaves _qzeros_format=1.
So the layer checkpoint (looper/gsq_training_model.py:~468) stores qzeros_format=1 next to v2 words.
On resume, _restore_packed_layer (gsq_training_model.py:~109-127) runs load_state_dict. That triggers the v1→v2 conversion (_restore_qzeros_format) and adds 1 to every zero.
Activity
fix(checkpoint): one qzeros layout invariant across load, save and pa…
Qubitium commentedon Nov 16, 2026
Second user-facing path with the same root cause, found at
9dad249: resuming staged GSQ from its per-layer checkpoint shifts every zero point by +1 (silent corruption on resume).quantization/gsq_training.py:~1365-1368callsTorchLinear.pack_original(...). That writes logical (v2) zero words but leaves_qzeros_format=1.looper/gsq_training_model.py:~468) storesqzeros_format=1next to v2 words._restore_packed_layer(gsq_training_model.py:~109-127) runsload_state_dict. That triggers the v1→v2 conversion (_restore_qzeros_format) and adds 1 to every zero.At HEAD, these repo tests fail from this root cause:
test_gsq_staged_public.py::test_staged_llama_resumes_identical_packed_block[*]test_gsq_distributed_model.py::test_distributed_model_capture_checkpoint_and_resume[*]test_gsq_distributed_failures.py(3 tests)test_rco_paper.py::test_projection_materialization_packed_bytes_and_save_reloadtest_torch.py::test_torch_quant_embeddings_pack_original_handles_unaligned_vocab(diff exactly 1.0)test_pack_tails.py::test_partial_words_checkpoint_round_trip[*](thepack_module(GPTQ_V2)case)Setting
qzero_format(2)insidepack_original(and the other raw packers) would fix all of them.