Skip to content

fix(qqq): keep per-channel empty s_group buffers in checkpoints (#5126) - #5186

Merged
Qubitium merged 1 commit into
mainfrom
fix/5126-qqq-sgroup
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5126-qqq-sgroup

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5126.

Problem

A per-channel QQQ layer (QQQConfig(group_size=-1), or any layer whose group_size == in_features) registers s_group = torch.empty(0). Every zero-element tensor reports storage pointer 0:

id_tensor_storage(torch.empty(0, dtype=torch.float16)) == (device(type='cpu'), 0, 0)

get_state_dict_for_save (gptqmodel/utils/model.py) de-duplicates by storage identity, so all per-channel s_group buffers collapse into one "shared" group. All but one are removed with WARN Removed shared tensor {... .s_group ...}; a 2-layer Llama writes 13 of 14 s_group keys. #5032 then made the loader fail closed on CHECKPOINT_REQUIRED_BUFFERS, so the saved checkpoint no longer loads:

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, ...

Only in-memory quantization (offload_to_disk=False) is affected; disk-offload sources are offload references and load-then-resave keeps the keys.

flowchart TD
    A["Per-channel QQQ layer<br/>s_group = torch.empty(0)"] --> B[get_state_dict_for_save]
    B --> C{"storage identity<br/>(device, 0, 0)"}
    C -->|"all empty tensors identical"| D["de-dup as shared storage"]
    D --> E["drops 13/14 s_group keys"]
    E --> F["#5032 fail-closed loader"]
    F --> G["ValueError: Missing required ... s_group"]
Loading

Fix

Two halves, each independently useful:

  1. Writer (get_state_dict_for_save): a zero-element tensor has no data to share, so key it by ("empty", name) instead of storage identity. Every named empty buffer is written.
  2. Loader (validate_checkpoint_qweights): a new CHECKPOINT_OPTIONAL_EMPTY_BUFFERS declaration (("s_group",) on QQQ) accepts a missing entry only when the live module's buffer is actually empty. A non-empty s_group stays required, so fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) #5032's fail-closed guarantee is unchanged. This also unbreaks checkpoints already written by the affected releases.
flowchart TD
    A["Per-channel QQQ layer<br/>s_group = torch.empty(0)"] --> B[get_state_dict_for_save]
    B --> C{"numel == 0?"}
    C -->|yes| D["key = ('empty', name)"]
    D --> E["every s_group key written"]
    E --> F{"loader: buffer empty<br/>in live module?"}
    F -->|yes| G["optional-empty: accept missing key"]
    F -->|no| H["still required (fail closed)"]
    G --> I["GPTQModel.load + generate OK"]
Loading

Before / after

main @ 307b688 this PR
saved s_group keys (2-layer per-channel QQQ) 1 of 14 14 of 14
reload of the in-memory checkpoint ValueError: Missing required quantized weights loads
reload of a legacy file with no s_group keys ValueError loads
generate after reload (CPU QQQTorchLinear, CUDA QQQLinear) n/a (1, 24)

Tests

  • New tests/test_qqq_per_channel_checkpoint_5126.py: 3 passed (writer keys + reload, legacy missing-empty acceptance, CUDA round-trip).
  • Red on main with the new test: 2 failed at the intended assertions (len(keys) == 14 and the loader ValueError).
  • test_qqq_per_channel_checkpoint_5126.py test_gsq_method_adapters.py test_checkpoint_modules.py test_checkpoint_quant_buffer_dtypes_4458.py test_awq_qqq_pack_shape_4567.py tests/qcfg: 313 passed.
  • uvx [email protected] check gptqmodel tests setup.py: All checks passed.

Unverified

  • ROCm: the save path and loader are device-agnostic, but no ROCm host was available; the CUDA (QQQLinear) and CPU (QQQTorchLinear) paths are covered.
  • Real Qwen/Llama checkpoints were not re-quantized; the tiny 2-layer fixture reaches the same group_size == in_features code path.

A per-channel QQQ layer (group_size == in_features) registers
s_group = torch.empty(0). Every zero-element tensor reports storage
pointer 0, so get_state_dict_for_save de-duplicated all of them as
shared storage and dropped all but one. The fail-closed loader from
#5032 then rejected the checkpoint for every missing s_group.

Keep each named empty buffer in the save map (there is no data to
share), and let the loader accept a missing entry for a buffer the live
module legitimately holds empty, while a non-empty s_group stays
required. The second half also unbreaks checkpoints written by the
affected releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant