Repository navigation
fix(qqq): publish dropped checkpoint buffers before an export and fail closed on load (#5010) - #5032
Merged
Merged
Conversation
…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
This was referenced Nov 18, 2026
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.
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5010
Root cause
Since #4856 the first AVX512 CPU forward of
QQQTorchLineardrops the checkpointB/s_group/s_channelbuffers once the packed cache can rebuild them (_maybe_drop_checkpoint_tensors, which setsself._buffers[name] = None). OnlyQQQTorchLinear._save_to_state_dictknew how to rebuild them, andGPTQModel.save()does not callstate_dict():get_state_dict_for_savewalksnamed_buffers(recurse=False)and PyTorch skips aNonebuffer._restore_checkpoint_layout_for_exportonly restored_fused_train_statesnapshots.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_projkept onlybias. The reload then crashed withCUDA error: an illegal memory access(native QQQ) or returned all-NaN logits (QQQ_TORCH).Changes
BaseQuantLinear.materialize_checkpoint_layout_for_export(), overridden byQQQLinearto restoreB/s_group/s_channelfrom the packed cache (_materialize_dropped_checkpoint)._restore_checkpoint_layout_for_export()— already called first byget_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.validate_checkpoint_qweights()now takes the required payload from the kernel rather than a format allow-list: newBaseQuantLinear.CHECKPOINT_REQUIRED_BUFFERSis("qweight",)for the GPTQ/AWQ/Marlin/BitBLAS family (declared once onPackedGroupedQuantLinear, which only those two classes inherit) and("B", "s_group", "s_channel")for QQQ. A checkpoint missing any of them raisesMissing 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):_packed_weight_for_cpu()(what the AVX512 forward calls) dropsB/s_channel;_restore_checkpoint_layout_for_exportpublishes all three buffers and clears the dropped marker;get_state_dict_for_savecontainslayer.B,layer.s_group,layer.s_channel;ValueErrornaminglayer.B;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 currentmain(47 in the post-merge re-run).ruff check gptqmodel testsclean.Residual risk
_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._packed_weight_for_cpureturns 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.PackedGroupedQuantLinearwithout aqweightpayload would be rejected until it overrides the declaration.