Repository navigation
Description
Found on main @ c2b0bf6, RTX 5090 (sm_120), torch 2.15 / CUDA 13.2, transformers 5.22.
What is wrong
Since #4856 (fix of #4805), the first CPU forward of QQQTorchLinear drops the checkpoint buffers after it builds the AVX512 packed cache. _maybe_drop_checkpoint_tensors sets self._buffers["B"|"s_group"|"s_channel"] = None (gptqmodel/nn_modules/qlinear/qqq.py:1003-1005). Only QQQTorchLinear._save_to_state_dict (qqq.py:1090-1097) knows how to rebuild them.
GPTQModel.save() does not call state_dict(). get_state_dict_for_save walks module.named_buffers(recurse=False) (gptqmodel/utils/model.py:2898-2918, and the offload variant at :2777-2811). PyTorch skips None buffers there, so the three dropped buffers are not in the save manifest at all. _restore_checkpoint_layout_for_export (model.py:2816-2836) only restores modules that have a _fused_train_state snapshot. It never calls QQQTorchLinear._materialize_dropped_checkpoint().
After quantize(), the in-session model is on the CPU with QQQTorchLinear (with or without offload_to_disk). So the ordinary flow quantize → evaluate/generate → save writes a QQQ checkpoint that contains no quantized weights: only embeddings, norms and biases. save() raises nothing and logs no warning.
Loading does not catch it either. validate_checkpoint_qweights (model.py:3064-3108) checks only GPTQ/AWQ-family formats and the qweight key. A QQQ checkpoint with no B/s_group/s_channel therefore loads with uninitialized buffers:
- On
main,QQQLinear(CUDA) hitsCUDA error: an illegal memory access. QQQ_TORCH, and the commits before fix(qqq): make the class-swapped CPU kernel independent of __init__ state (#4940, #4942) #4951, return all-NaN logits.
Repro
Qwen2.5-0.5B-Instruct (2-layer copy; the full model behaves the same).
import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import QQQConfig
from gptqmodel.quantization.config import CalibrationConfig
from safetensors import safe_open
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", QQQConfig(bits=4, group_size=128), dtype=torch.float16)
m.quantize(CalibrationConfig(dataset=calib_32_c4_rows))
ids = m.tokenizer("The capital of France is Paris.", return_tensors="pt").input_ids
with torch.inference_mode():
m.model(ids) # any in-session forward / generate / evaluation
m.save("qqq_out")
print(len(safe_open("qqq_out/model.safetensors", "pt").keys()))
r = GPTQModel.load("qqq_out", dtype=torch.float16)
r.model(ids.cuda())Output (2-layer model):
saved keys layer0 q_proj keys reload forward
no forward before save 54 B, bias, s_channel, s_group finite logits
forward before save 12 bias CUDA error: an illegal memory access was encountered
Bisect, with the same script and a forward before save:
07f8b8aa1(parent of fix(qqq): replace the CPU checkpoint layout with the packed cache (#4805) #4856): 54 keys, and the reload is fine.57a605583(fix(qqq): replace the CPU checkpoint layout with the packed cache (#4805) #4856): 12 keys.main: 12 keys.
With offload_to_disk=False the result is identical: 12 keys, and the reload crashes. Loading the 12-key checkpoint with backend=BACKEND.QQQ_TORCH gives all-NaN logits, not an error.
Suggested fix
- Materialize the QQQ checkpoint layout before collecting tensors. Either have
_restore_checkpoint_layout_for_exportcall_materialize_dropped_checkpoint()on every module that has_torch_dropped_checkpoint, or give quantized kernels a generic "export my checkpoint tensors" hook thatget_state_dict_for_saveuses instead of the rawnamed_bufferswalk. The next CPU forward drops the buffers again, so this costs nothing at steady state. - Make the load fail closed.
validate_checkpoint_qweightsshould check every quantized kernel's required checkpoint tensors (QQQB/s_group/s_channel, and similar keys for FP8, EXL3, GGUF, NF12 and so on), not justqweightfor GPTQ/AWQ. A truncated checkpoint should raise, not crash the CUDA context or return NaN.
Tests that should have caught it
tests/test_qqq_cpu_residency_4805.py checks state_dict() after the drop, but not GPTQModel.save(). Add an end-to-end test: QQQ quantize → one in-session forward → save() → assert that every B/s_group/s_channel key is present → reload and compare logits. The existing "forward before save is bytewise identical to save without forward" check should include QQQ.
Severity
High. A common, documented flow (quantize, sanity-check generate, save) silently produces a QQQ checkpoint with every quantized weight missing. The data loss shows up only at load time, as a CUDA illegal-address fault or NaN output.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-5011is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #5032
QQQ save() after an in-session forward must still publish B/s_group/s_channel
Qubitium commentedon Nov 18, 2026
Agent release:
agent-root-5011stood down on this issue.While I was implementing it, #5032 (
f5b1b9e21, "publish dropped checkpoint buffers before an export and fail closed on load") landed onmainand covers the same defect, including a test file of the same name. I verified atorigin/main@236f31b07that a QQQ checkpoint saved after the runtime buffer drop now containsB/s_group/s_channeland that a weights-less QQQ checkpoint is refused at load, so there is nothing left for me to change. My duplicate work was dropped; no separate PR.fix(qqq): publish dropped checkpoint buffers before an export and fai…