Skip to content

fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) - #5032

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-5010
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-5010

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5010

Root cause

Since #4856 the first AVX512 CPU forward of QQQTorchLinear drops the checkpoint B/s_group/s_channel buffers once the packed cache can rebuild them (_maybe_drop_checkpoint_tensors, which sets self._buffers[name] = None). Only QQQTorchLinear._save_to_state_dict knew how to rebuild them, and GPTQModel.save() does not call state_dict(): get_state_dict_for_save walks named_buffers(recurse=False) and PyTorch skips a None buffer. _restore_checkpoint_layout_for_export only restored _fused_train_state snapshots.

So the ordinary quantize → evaluate/generate → save flow silently wrote a QQQ checkpoint with no quantized weights: 54 keys → 12 on a 2-layer model, and layer0.q_proj kept only bias. The reload then crashed with CUDA error: an illegal memory access (native QQQ) or returned all-NaN logits (QQQ_TORCH).

Changes

  1. Publish the buffers before collecting the manifest. New no-op hook BaseQuantLinear.materialize_checkpoint_layout_for_export(), overridden by QQQLinear to restore B/s_group/s_channel from the packed cache (_materialize_dropped_checkpoint). _restore_checkpoint_layout_for_export() — already called first by get_state_dict_for_save() — invokes it, so the export manifest sees the tensors. The packed cache is kept, so the next forward neither rebuilds nor changes output.
  2. Fail closed on load. validate_checkpoint_qweights() now takes the required payload from the kernel rather than a format allow-list: new BaseQuantLinear.CHECKPOINT_REQUIRED_BUFFERS is ("qweight",) for the GPTQ/AWQ/Marlin/BitBLAS family (declared once on PackedGroupedQuantLinear, which only those two classes inherit) and ("B", "s_group", "s_channel") for QQQ. A checkpoint missing any of them raises Missing required quantized weights ... instead of loading uninitialized buffers. Every other format still declares () and keeps its previous skip, so GGUF/EXL3/FP8/NF12 behaviour is unchanged.

Verification

New tests/test_qqq_save_after_forward_5010.py (6 tests):

  • guard: _packed_weight_for_cpu() (what the AVX512 forward calls) drops B/s_channel;
  • _restore_checkpoint_layout_for_export publishes all three buffers and clears the dropped marker;
  • get_state_dict_for_save contains layer.B, layer.s_group, layer.s_channel;
  • a forward after the export is bit-identical to the forward before it;
  • a truncated QQQ checkpoint raises ValueError naming layer.B;
  • a complete QQQ checkpoint still validates.

Red on parent (git checkout origin/main -- gptqmodel/utils/model.py gptqmodel/nn_modules/qlinear/__init__.py gptqmodel/nn_modules/qlinear/qqq.py, then restored): 3 failed, 3 passed — export, manifest and fail-closed. The other three pass on the parent by design (fixture guard, forward parity, complete-checkpoint validation).

Green: 6 passed; tests/test_hf_gptqmodel_load_bridge.py tests/test_qqq_cpu_residency_4805.py tests/test_qqq_cpu_cold_build_concurrency_4942.py tests/test_qqq_runtime_state_4940.py tests/test_load_state_assertions.py → 70 passed after merging current main (47 in the post-merge re-run). ruff check gptqmodel tests clean.

Residual risk

  • This host is ARM64 with no AVX512 packed kernel, so a plain forward takes the generic matmul path and never drops the buffers; the test reaches the post-forward state by calling _packed_weight_for_cpu() directly (the same call the AVX512 forward makes). The real quantize → generate → save → reload flow on an AVX512 host was not executed here.
  • After an export the checkpoint buffers stay resident (the cache is kept, and _packed_weight_for_cpu returns early without re-dropping), so a save costs the checkpoint copy until the cache is invalidated. That is no worse than a freshly loaded model, but it is a small RSS step that a later forward no longer undoes.
  • The validation rewrite keeps the previous behaviour for every format except QQQ, but it is now declaration-driven: a future kernel that inherits PackedGroupedQuantLinear without a qweight payload would be rejected until it overrides the declaration.

…l closed on load (#5010)

Since #4856 the first AVX512 CPU forward of `QQQTorchLinear` drops the
checkpoint `B`/`s_group`/`s_channel` buffers once the packed cache can rebuild
them. `GPTQModel.save()` does not call `state_dict()`; it walks
`named_buffers(recurse=False)` and PyTorch skips a `None` buffer, so the
ordinary quantize -> generate -> save flow wrote a checkpoint with no
quantized weights at all (54 keys -> 12 on a 2-layer model). The reload then
crashed the CUDA context with an illegal memory access, or returned all-NaN
logits on `QQQ_TORCH`.

Two changes:

1. `BaseQuantLinear.materialize_checkpoint_layout_for_export()` is a new
   no-op hook, overridden by `QQQLinear` to restore the dropped buffers from
   the cache. `_restore_checkpoint_layout_for_export()` -- which
   `get_state_dict_for_save()` already runs -- calls it, so the export
   manifest sees the tensors. The packed cache is kept, so the next forward
   neither rebuilds nor changes output.

2. `validate_checkpoint_qweights()` now takes the required payload from the
   kernel instead of a format allow-list: `BaseQuantLinear.CHECKPOINT_REQUIRED_BUFFERS`
   is `("qweight",)` for the GPTQ/AWQ/Marlin/BitBLAS family (inherited from
   `PackedGroupedQuantLinear`) and `("B", "s_group", "s_channel")` for QQQ.
   A checkpoint missing any of them raises instead of loading uninitialized
   buffers. Every other format keeps its previous skip.

Fixes #5010
@Qubitium
Qubitium merged commit f5b1b9e into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-5010 branch November 17, 2026 23:02
Qubitium added a commit that referenced this pull request Nov 18, 2026
… (#5186)

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