Repository navigation
Description
Found on main @ c2b0bf6, RTX 4090.
What is wrong
#4979 (fix of #4947) added rehome_failed_run_kernels() to the failure branch of WeightOnlyLooper.loop() (gptqmodel/looper/weight_only_looper.py:~997) with the comment "leave the finished layers runnable". After a failed weight-only quantize() (RTN, GGUF, FP8), the in-session model still cannot run a forward:
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
(transformers/models/qwen2/modeling_qwen2.py:244, Qwen2RMSNorm.forward)
Kernel selection is not the cause; the finished layers are already TorchLinear/GGUFTorchLinear/TorchFP8Linear. The cause is the in-flight layer. WeightOnlyLooper moves the layer it is quantizing to the quant device (_prepare_named_module_for_quantization). Its failure branch never moves that layer back, so every parameter of that layer, including the RMSNorm weights and the unquantized projections, stays on cuda:0 while the rest of the model is on CPU. ModuleLooper fixed this exact problem for #4546 with _track_inflight_layer() / _restore_inflight_layer() (#4580, module_looper.py:~1991-2030). WeightOnlyLooper has no equivalent. The result is the same with offload_to_disk=True (default) and False, so the cancelled-run contract of #4546/#4860/#4947 still does not hold for any weight-only method.
The failure is the same before #4979 (33d1aa7d5^), so this is not a regression. #4979 is still incomplete for the weight-only path it claims to cover.
Repro
Qwen2.5-0.5B-Instruct truncated to 4 layers, fp16. The failure is injected in layer 2, standing in for an OOM, a cancel or a bad module:
import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import config as C
import gptqmodel.looper.weight_only_processor as WP
for qc in (C.RTNConfig(bits=4, group_size=128), C.GGUFConfig(bits=4), C.GGUFConfig(bits=4, format="q_k_m"), C.FP8Config(),
C.RTNConfig(bits=4, group_size=128, offload_to_disk=False)):
m = GPTQModel.load(MODEL_4L, qc, dtype=torch.float16)
orig = WP.WeightOnlyProcessor.quantize_module
def boom(self, module, *a, **k):
if ".layers.2." in module.full_name: raise RuntimeError("injected")
return orig(self, module, *a, **k)
WP.WeightOnlyProcessor.quantize_module = boom
try: m.quantize(None)
except RuntimeError: pass
WP.WeightOnlyProcessor.quantize_module = orig
print([n for n, t in list(m.model.named_parameters()) if t.device.type == "cuda"])
x = m.tokenizer("Hello world", return_tensors="pt").input_ids
m.model(x.to(m.model.get_input_embeddings().weight.device))Output (identical for RTN, GGUF q4_0, GGUF q4_k_m, FP8, RTN without disk offload):
['model.layers.2.self_attn.q_proj.weight', 'model.layers.2.self_attn.q_proj.bias', ..., 'model.layers.2.mlp.down_proj.weight',
'model.layers.2.input_layernorm.weight', 'model.layers.2.post_attention_layernorm.weight']
q_proj kernels by layer: ['GGUFTorchLinear', 'GGUFTorchLinear', 'Linear', 'Linear']
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
For comparison, ModuleLooper methods with the same failure (StopMainLoop at layer 2, or RuntimeError at layer 1) all give a finite in-session forward on this commit: GPTQ, AWQ (including a stop at the last layer), QQQ, EXL3, Paro and MACaQ.
Suggested fix
Port #4580 to WeightOnlyLooper. Record the layer and its home device before _prepare_named_module_for_quantization moves it, and move it back in the failure branch (strict=False, before rehome_failed_run_kernels). Alternatively, move every non-meta parameter or buffer that is not on the model's resolved device back to that device in rehome_failed_run_kernels.
Test that should have caught it
tests/test_cancelled_quantize_kernel_rehome_4947.py covers AWQ/QQQ through ModuleLooper only, and the earlier cancel tests (#4546/#4807/#4860) use GPTQ only. Add an RTN/GGUF case that fails mid-loop and asserts a finite in-session forward.
Severity
Medium. Every failed or cancelled weight-only quantize (RTN, GGUF, FP8) leaves the in-session model unusable. This is the guarantee #4546/#4947 established for the calibrated methods.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-5011is working on this issue now.Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-53ba17eb4d83is no longer working on this issue.The issue is free to claim.
merged by another agent as #5049
Qubitium commentedon Nov 18, 2026
Agent claim:
agent-root-5011is working on this issue now.Pull request: #5049
Scope:
WeightOnlyLooper's failure branch now restores the in-flight layer to its pre-run device (the tracker moves out ofModuleLooperintogptqmodel/looper/inflight_layer.pyand both loopers use it). Verified red on unmodifiedorigin/main(236f31b07): the 5 end-to-end nodes leave all 12 tensors ofmodel.layers.2oncuda:0; 8 passed with the fix.fix(weight-only): return the in-flight layer to its home device on fa…
Qubitium commentedon Nov 18, 2026
Agent release:
agent-root-5011finished this issue. Fix: #5049, squash-merged asaf2ab180a.WeightOnlyLooper's failure branch now restores the in-flight layer to its pre-run device. The tracker (_track_inflight_layer/_clear_inflight_layer/_restore_inflight_layer+_clear_layer_capture_hooks) moved out ofModuleLooperintogptqmodel/looper/inflight_layer.py, and both loopers inherit it, so there is one implementation instead of a copy. The weight-only loop tracks the layer before/afterpre_quantizeand after the model-specific converter, clears it afterpost_quantize, and restores it first on failure.Verification:
tests/test_weight_only_failed_run_device_5011.pyis 8 failed on unmodifiedorigin/main@236f31b07— the five end-to-end nodes (RTN, RTN without disk offload, GGUF, GGUFq_k_m, FP8) leave all 12 tensors ofmodel.layers.2oncuda:0— and 8 passed on the merged commitaf2ab180a(re-verified after merge). The neighbouring 18-suite batch has an identical failure set on main and on the branch (11 failed / 181 passed / 59 skipped, diffed).Stand-downs recorded for the three issues I also held claims on, all fixed on main by other PRs while I worked: #5010 (#5032), #5023 (#5039), #5027 (#5041).
refactor(looper): give both quantization loops one run-exit recovery …
fix(looper): leave a cancelled quantize() with a runnable model (Mode…