Repository navigation
fix(qqq): replace the CPU checkpoint layout with the packed cache (#4805) - #4856
Merged
Merged
Conversation
) QQQTorchLinear's first CPU forward built the AVX512 INT4 cache while the checkpoint B/s_group/s_channel stayed resident, so the packed weight was stored twice and the group scales were widened to FP32. The cache now rebuilds the checkpoint tensors bit for bit, verifies them, and only then replaces the checkpoint layout; state_dict/save/load/move rebuild them on demand. Any verification mismatch keeps both layouts.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…tate (#4940, #4942) (#4951) * fix(qqq): make the class-swapped CPU kernel independent of __init__ state (#4940, #4942) Two regressions from #4856: * `rehome_quantized_kernel` reinterprets a packed `QQQLinear` as `QQQTorchLinear` by assigning `__class__`, which never runs the target's `__init__`. The runtime attributes #4856 added (`_torch_packed_cache`, `_torch_packed_cache_key`, `_torch_dropped_checkpoint`) therefore did not exist, and the following `clear_weight_cache()` raised `AttributeError: 'QQQTorchLinear' object has no attribute '_torch_dropped_checkpoint'` at the end of every QQQ `quantize()` (#4940). Install that state through a `_init_runtime_state` hook the swap calls, keep class-level defaults for the reads, and create the `_int_mm` failure memo on demand instead of sharing a class-level `set`. * The cold path of `_packed_weight_for_cpu` read `B`/`s_channel`/`s_group` without `_cpu_transform_lock`, so a second thread that passed the cache check while the first was still building could read the buffers after `_maybe_drop_checkpoint_tensors` had dropped them (#4942). The whole build now runs under the lock, like the other CPU int4 kernels' `_ensure_cpu_layout`. * test(qqq): pass the stand-in kernel class instead of a wrapping lambda Addresses the Code Quality review notes: `_FakePackedKernel` is already the callable `_qqq_cpu_kernel()` needs, so the lambda wrapper is unnecessary.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…l closed on load (#5010) (#5032) 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
sLaffey
pushed a commit
to sLaffey/GPTQModel
that referenced
this pull request
Nov 18, 2026
…lCloud#4978) Seven tests went red because their doubles/oracles predate library changes that behave as intended. This is test-only; no product code changes. - test_fusion_kernel_backends: gc.collect() before the weakref check; ModelCloud#4871 leaves transient Dynamo trace garbage that keeps the pre-fusion weight alive. The refs are still asserted dead afterwards. - test_failed_run_fence_4595: del qmodel + gc.collect() so ModelCloud#4829's finalizer runs before the no-leak assertion; a late finalizer must not recreate the released run dir. - test_exl3_projection_resume: add _release_deferred_hessian_sources() to the _Capture double (ModelCloud#4837). - test_kernel_audit_regressions: stub _needs_torch_fallback=lambda: False on the SimpleNamespace self (ModelCloud#4835). - test_moe_resave_preserves_experts_4589: accept the earlier RuntimeError "does not provide tensors" refusal (ModelCloud#4810); still assert no safetensors. - test_positional_mask_capture_4660: build the native oracle with the same mask-derived position_ids the capture uses (ModelCloud#4930). - test_qqq_kernel_memory_4387: snapshot the oracle weight/s_channel before the first forward, which may drop the checkpoint layout (ModelCloud#4856).
5 tasks done
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 #4805.
Change
QQQTorchLinear's first CPU forward builds an INT4 cache for the AVX512qqq_int4kernel while the checkpointB/s_group/s_channelstayed resident, so the packed weight was stored twice and the group scales were widened to FP32._torch_dropped_checkpoint). Any mismatch keeps both layouts (fail closed).state_dict(), save, load and_apply/.to()rebuild the checkpoint tensors on demand; the dequantized fallback rebuilds them transiently.Tests
tests/test_qqq_cpu_residency_4805.py: 9 passed (cache replaces layout, state_dict bit-identical, load/move restore, fallback rebuild, fail-closed inverse)tests/test_qqq_cpu.py+test_qqq_kernel_memory_4387.py: all pass;test_qqq_jit.py2 failures are the pre-existing native JIT build failure on this box (sm_121 build ofqqq_gemm.cu), identical on parentruff check gptqmodel tests: cleanResidual risks