Skip to content

[BUG] Regression from #5032 (fix of #5010): per-channel QQQ quantized with offload_to_disk=False saves an unloadable checkpoint - save de-dups every empty s_group as shared storage (13/14 dropped), new fail-closed loader rejects it #5126

Closed

Description

@Qubitium

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:

  1. Save drops the empty s_group buffers as "shared storage" (pre-existing). For a per-channel layer QQQ registers s_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 on id_tensor_storage(tensor), so all of them collapse into one "shared" group. All but one are deleted with WARN Removed shared tensor {'model.layers.0.mlp.gate_proj.s_group', ...}. On a 2-layer Llama-3.2-1B, 13 of the 14 s_group keys 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))
  2. 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 missing CHECKPOINT_REQUIRED_BUFFERS. For QQQ that is ("B", "s_group", "s_channel") (qqq.py:194), and it applies even when s_group is 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 by id(tensor) when numel() == 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_group when 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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    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 is QQQConfig(bits=4, group_size=128, device=CPU, offload_to_disk=False, gsq=...) on a tiny model where most projections have in_features == 128:

    WARN  Removed shared tensor {'model.layers.0.mlp.up_proj.s_group', 'model.layers.0.mlp.gate_proj.s_group', 'model.layers.0.self_attn.k_proj.s_group', 'model.layers.0.self_attn.v_proj.s_group', 'model.layers.0.self_attn.o_proj.s_group'} while saving.
    E   ValueError: Missing required quantized weights in checkpoint '.../quantized/model.safetensors': model.layers.0.mlp.gate_proj.s_group, ...
    

    It passed at the previous full triage (3867c82af).

    🤖 Generated with Claude Code

  2. self-assigned this
    on Nov 18, 2026
  3. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5126-qqq-sgroup is 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_group buffers as shared storage, so an in-memory QQQ checkpoint round-trips

  4. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released — superseded.

    agent-32d108f07a94 posted 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.

  5. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-4e3a0639ecaf is 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_group buffers as shared storage, so an in-memory QQQ checkpoint round-trips through the fail-closed loader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions