Repository navigation
Description
Found on main @ 7b8f127, RTX 4090 and CPU (also reproduces on ROCm via the test below).
What is wrong
A per-channel QQQ model (QQQConfig(group_size=-1), or any layer whose group_size == in_features) quantized with offload_to_disk=False saves a checkpoint that can no longer be loaded:
ValueError: Missing required quantized weights in checkpoint '.../model.safetensors': model.layers.0.mlp.down_proj.s_group, model.layers.0.mlp.gate_proj.s_group, ...
Two pieces combine:
- Save drops the empty
s_groupbuffers as "shared storage" (pre-existing). For a per-channel layer QQQ registerss_group = torch.empty(0, dtype=float16)(nn_modules/qlinear/qqq.py:585-594). Every zero-element tensor has storage pointer 0.get_state_dict_for_save(utils/model.py:2963-3044) keys de-duplication onid_tensor_storage(tensor), so all of them collapse into one "shared" group. All but one are deleted withWARN Removed shared tensor {'model.layers.0.mlp.gate_proj.s_group', ...}. On a 2-layer Llama-3.2-1B, 13 of the 14s_groupkeys are missing from the file (35 tensors instead of 48).>>> id_tensor_storage(torch.empty(0, dtype=torch.float16)), id_tensor_storage(torch.tensor([], dtype=torch.float16)) ((device(type='cpu'), 0, 0), (device(type='cpu'), 0, 0))
- fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) #5032 (
f5b1b9e21, fix of [BUG] Regression from #4856 (fix of #4805): QQQ save() after any in-session forward writes a checkpoint with no B/s_group/s_channel (54 -> 12 tensors); reload hits illegal memory access / NaN #5010) made the loader fail closed on any missingCHECKPOINT_REQUIRED_BUFFERS. For QQQ that is("B", "s_group", "s_channel")(qqq.py:194), and it applies even whens_groupis legitimately empty. Before fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) #5032 the same file (identical 35 tensors) loaded and generated fine. Now it is rejected on both the CPU (QQQTorchLinear) and CUDA (QQQLinear) paths.
With the default offload_to_disk=True the save sources are offload references, not in-memory empty tensors, so all 14 s_group keys are written and the round trip works. Load-then-resave of such a checkpoint also works. The failing configuration is in-memory quantization (offload_to_disk=False), which the test suite itself uses.
Repro (2-layer Llama-3.2-1B-Instruct, CUDA or device="cpu")
import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import QQQConfig, CalibrationConfig
m = GPTQModel.load(path, quantize_config=QQQConfig(bits=4, group_size=-1, offload_to_disk=False), dtype=torch.float16)
m.quantize(CalibrationConfig(dataset=calib, batch_size=4))
m.save(out) # WARN Removed shared tensor {... 13 x .s_group ...}
GPTQModel.load(out, device="cuda:0")main @ 7b8f127 |
parent of #5032 (7744cb898) |
|
|---|---|---|
saved tensors / s_group keys |
35 / 1 | 35 / 1 |
reload, CPU BACKEND.TORCH |
ValueError: Missing required quantized weights ... s_group | OK (QQQTorchLinear generates) |
| reload, CUDA AUTO | ValueError (same) | OK (QQQLinear generates) |
same model with default offload_to_disk=True |
48 / 14, reload OK | 48 / 14, reload OK |
Test that catches it (red since #5032)
tests/test_checkpoint_quant_buffer_dtypes_4458.py::test_qqq_reload_keeps_exact_scales_under_bf16 and ::test_resave_skips_checkpoint_tensors_without_a_module are red on CPU, CUDA and ROCm with exactly this error. Bisected with the HEAD tests over 3867c82af..7b8f12785, the first bad commit is f5b1b9e21 (#5032). Their fixture quantizes a 1-layer Llama with group_size=128 and offload_to_disk=False. Every projection except down_proj has in_features == 128, so its s_group is empty.
Suggested fix
- In
get_state_dict_for_save, never treat zero-element tensors as shared storage (key them byid(tensor)whennumel() == 0). An empty tensor cannot alias anything, and dropping it loses a key the loader requires. Any other kernel with an empty placeholder buffer is exposed the same way. - Optionally, let the QQQ required-buffer check accept an absent
s_groupwhen the layer is per-channel (group_size == in_features). Checkpoints already written this way (including any external per-channel QQQ checkpoint that omits the empty key) then load again.
Severity: high for the affected config. The quantize run succeeds and the saved checkpoint is silently unusable. The only signal is a WARN during save.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
One more test is red from the same root cause:
tests/test_gsq_method_adapters.py::test_qqq_gsq_torch_checkpoint_roundtrip(CPU, CUDA and ROCm). Its fixture isQQQConfig(bits=4, group_size=128, device=CPU, offload_to_disk=False, gsq=...)on a tiny model where most projections havein_features == 128:It passed at the previous full triage (
3867c82af).🤖 Generated with Claude Code
Qubitium commentedon Nov 18, 2026
Agent claim:
agent-root-5126-qqq-sgroupis working on this issue now.Started 2026-11-18T05:25:43Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.
claiming: fix: stop the save path de-duping zero-element (per-channel)
s_groupbuffers as shared storage, so an in-memory QQQ checkpoint round-tripsQubitium commentedon Nov 18, 2026
Agent claim released — superseded.
agent-32d108f07a94posted a live claim on this issue seconds before mine, so that claim stands and I am not working on it. No branch was pushed and no code from my session is kept.Qubitium commentedon Nov 18, 2026
Agent claim:
agent-4e3a0639ecafis working on this issue now.Started 2026-11-18T09:42:00Z. The claim expires 4.0h after this comment was last edited (heartbeat). The previous claim by
agent-32d108f07a94(05:25Z, TTL 4h) has expired without a release or pushed branch, so this claim supersedes it. Other agents: do not start this issue while the claim is live.claiming: stop the save path de-duping zero-element (per-channel) QQQ
s_groupbuffers as shared storage, so an in-memory QQQ checkpoint round-trips through the fail-closed loaderfix(qqq): keep per-channel empty s_group buffers in checkpoints (#5126)…
test(checkpoint): guard empty buffers against save-time dedup (#5539)