Repository navigation
Description
Found on main @ c2b0bf6, RTX 4090 (default offload_to_disk=True).
What is wrong
WeightOnlyLooper.loop() (gptqmodel/looper/weight_only_looper.py:984-1033) guards only self._loop_impl(...) with the except BaseException failure cleanup (#4546/#4860/#4947/#4813/#4807). The post-loop tail that turns the lazy offloaded shell back into a usable in-session model runs after that try, unguarded:
try:
result = self._loop_impl(**kwargs)
except BaseException:
...cleanup...
raise
self._restore_offloaded_base_modules(strict=True) # unguarded
self._restore_disk_offloaded_modules() # unguarded: reads every quantized layer back from disk
self._materialize_meta_base_modules(strict=True) # unguarded: embed_tokens / norm / rotary_emb
self._materialize_remaining_meta_modules() # unguarded
ensure_version_counters(self.gptq_model.model)
return resultIf a Ctrl-C, an OOM or an I/O error lands in this tail, quantize() raises but none of the failure cleanup runs. model.embed_tokens, model.norm and rotary_emb are left on meta (also the quantized layers, when the interrupt lands in _restore_disk_offloaded_modules). Every later in-session forward then fails with a meta-tensor error. The window is not small. For RTN on a 4-layer model it is about 15% of the run, and on a large model _restore_disk_offloaded_modules reads every quantized layer back from disk.
This is not the same as #5011 (the in-flight layer left on cuda, failure branch). Here _loop_impl has already returned.
Repro 1: a real Ctrl-C at a random time (no patching)
threading.Timer(t, _thread.interrupt_main) around m.quantize(...) with RTNConfig(bits=4, group_size=128), Qwen2.5-0.5B-Instruct truncated to 4 layers. 11 cancel times swept, full run 0.6 s:
cancel_at 0.432 -> KeyboardInterrupt; meta: ['model.norm.weight', 'model.rotary_emb.inv_freq', 'model.rotary_emb.original_inv_freq']
next forward: NotImplementedError: Cannot copy out of meta tensor; no data!
cancel_at 0.468 -> same
Main-thread stack when the interrupt was delivered:
weight_only_looper.py:1028 loop -> self._materialize_meta_base_modules(strict=True)
weight_only_looper.py:966 _materialize_meta_base_modules -> replace_inference_parameters(module)
Repro 2: deterministic (the interrupt raised at the first call of a tail helper)
import gptqmodel.looper.weight_only_looper as WL
orig = WL.restore_disk_offloaded_modules # or WL.replace_inference_parameters
WL.restore_disk_offloaded_modules = lambda *a, **k: (_ for _ in ()).throw(KeyboardInterrupt())
m = GPTQModel.load(MODEL_4L, RTNConfig(bits=4, group_size=128), dtype=torch.float16)
try: m.quantize(None)
except KeyboardInterrupt: pass
WL.restore_disk_offloaded_modules = orig
m.model(ids)| interrupt lands in | params/buffers left on meta | next forward |
|---|---|---|
restore_disk_offloaded_modules |
156 (model.embed_tokens.weight, model.norm.weight, every layer's packed buffers) |
RuntimeError: Tensor on device meta is not on the expected device cpu! |
replace_inference_parameters (inside _materialize_meta_base_modules) |
3 (model.norm.weight, rotary_emb.inv_freq, original_inv_freq) |
NotImplementedError: Cannot copy out of meta tensor; no data! |
For comparison, the same injection into ModuleLooper's tail (GPTQ, restore_disk_offloaded_modules / ensure_version_counters) leaves a model that still runs a forward, because its layers keep their offload hooks and the run dir is kept. Its tail (module_looper.py:2147-2155) is unguarded in the same way, though.
Suggested fix
Move the tail inside the try of both WeightOnlyLooper.loop() and ModuleLooper.loop(), so a failure there goes through the same best-effort cleanup (_restore_offloaded_base_modules(strict=False), _materialize_unreached_meta_modules, keeping the offload root while modules still read from it). Or give the failure branch its own _materialize_meta_base_modules(strict=False).
Test that should have caught it
The cancel tests raise only inside the layer loop (callbacks or processor methods). Add a case that raises from each post-loop helper (restore_disk_offloaded_modules, _materialize_meta_base_modules, materialize_remaining_meta_modules) for RTN/GGUF/FP8 and asserts the in-session forward is finite.
Severity
Medium-low. A cancel or failure in the final phase of a weight-only quantize() leaves the in-session model unusable, with an error that points at meta tensors instead of the cancellation.
🤖 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:
agent-root-5011is working on this issue now.Qubitium commentedon Nov 18, 2026
Agent claim:
agent-root-5023-tail-cleanupis working on this issue now.Started 2026-11-18T00:02:35Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.
claiming: route a post-loop tail failure (restore/materialize) through the failed-run cleanup in WeightOnlyLooper and ModuleLooper
fix(looper): keep a post-loop tail failure inside the failed-run clea…
Qubitium commentedon Nov 18, 2026
Agent release:
agent-root-5011stood down on this issue.#5039 (
0783ccdbc, "keep a post-loop tail failure inside the failed-run cleanup") landed onmainwhile I was implementing it, withtests/test_post_loop_tail_failure_5023.pycovering both loopers. Atorigin/main@236f31b07the tail is inside the guarded region in bothWeightOnlyLooper.loop()andModuleLooper.loop(), so my duplicate change was dropped. (Two GPTQ nodes of that new test still fail on this host with anUnboundLocalErroringptq_processor.py— identically on unmodified main, so it is a separate pre-existing defect, not part of this issue's fix.)Qubitium commentedon Nov 18, 2026
Agent claim released — merged.
#5039 landed as
0783ccdbconmain: the weight-only and GPTQ post-loop tails now run inside the failed-run guard, so a Ctrl-C/OOM/I-O error there recovers instead of leavingembed_nokens/norm/rotary_embon meta. 4 of the 6 new test nodes were red on the parent commit.