You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] #4829 (fix of #4807) incomplete: after a cancelled/failed quantize() with default offload, layers past the cancel point stay lazy meta shells (no hook) -> next forward still fails 'Tensor on device cpu is not on the expected device meta' #4860
#4829 (the fix for #4807) keeps the per-run offload root alive after a cancelled or failed quantize(), so the layers that finished before the cancel stay readable through their disk-offload hooks. That part works.
The fix misses the layers after the cancel point. With the default offload_to_disk=True, the model is loaded as a lazy shell, so every layer the looper never reached is still on meta, with no offload hook and no bundle. The success path materializes these layers with _materialize_remaining_meta_modules() (gptqmodel/looper/module_looper.py:2115). The failure branch (module_looper.py:2061-2106) still skips that call. As a result, the next forward still fails, now on the first unreached layer instead of on layer 0:
RuntimeError: Tensor on device cpu is not on the expected device meta!
#4807 already counted these modules: its ON_META 23 was 7 + 7 offloaded modules in layers 0-1 plus the 9 lazy modules of layer 3. Its suggested fix also said "materialize or rehome the rest".
The new regression test tests/test_cancelled_quantize_disk_offload_4807.py misses this. It uses a 2-layer model and cancels at layer_idx == 1, which is the last layer, so no unreached layer exists.
m=GPTQModel.load(MODEL, C.GPTQConfig(bits=4, group_size=128), dtype=torch.float16) # offload_to_disk=Truedefcb(**kw):
ifkw.get("stage") =="forward_start"andkw.get("layer_idx") ==AT:
returnStopMainLoop# same result with `raise RuntimeError(...)`m.subset_callback=cbtry:
m.quantize(C.CalibrationConfig(dataset=calib, batch_size=4))
exceptBaseExceptionase:
print("ERR", type(e).__name__)
fori, Linenumerate(m.model.model.layers):
... # count modules with meta params / with an _hf_hookx=tok("Hello world, the capital of France is", return_tensors="pt").input_ids# embed is on CPUwithtorch.inference_mode():
m.model(x)
Output with AT=2, on main:
ERR StopMainLoop Subset callback requested stop at layer 2 subset 0
layer0: meta-mods=7 hooked=7 q_proj=TorchLinear <- fixed by #4829, loadable
layer1: meta-mods=7 hooked=7 q_proj=TorchLinear
layer2: meta-mods=0 hooked=0 q_proj=AutoNF12HookedLinear (in-flight, restored by #4580)
layer3: meta-mods=9 hooked=0 q_proj=Linear <- never materialized
FWD_FAIL RuntimeError Tensor on device cpu is not on the expected device meta!
With AT=1 and an injected RuntimeError, layers 2 and 3 are both left with meta-mods=9 hooked=0, and the forward fails the same way.
With AT=3 (cancel at the last layer, the case the PR test covers), the forward works (FWD_OK). Before #4829, at 9d2ea51^, AT=2 failed with FileNotFoundError .../model.layers.0.self_attn.q_proj/module.safetensors.
The offload_to_disk=False control gives ON_META 0 and FWD_OK for the same cancel.
Suggested fix
In the failure branch, after _restore_offloaded_base_modules(strict=False), call materialize_remaining_meta_modules(self.gptq_model, device=CPU) (non-strict, best effort). It touches only modules that are still on meta and have no offload hook, so it does not undo #4829's choice to keep the finished layers lazily loaded. Apply the same change to WeightOnlyLooper's failure branch.
Extend test_cancelled_quantize_disk_offload_4807.py to at least 3 layers and cancel at a layer that is not the last one.
Severity
Medium. This is the default config and the documented cancel path. The in-session model still cannot run a forward after a cancel or failure anywhere except the last layer, which is what #4546, #4807 and #4829 set out to guarantee.
Finish #4829: a cancelled/failed quantize() with default offload must release layers past the cancelled point (offload root cleanup); add a cancellation test with default offload.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4893
Finish #4829: a cancelled/failed quantize() with default offload must release layers past the cancelled point (offload root cleanup); add a cancellation test with default offload.
fix(looper): materialize unreached layers after a cancelled run (#4860)…
fix(weight-only): return the in-flight layer to its home device on fa…
fix(looper): leave a cancelled quantize() with a runnable model (Mode…
tests: pin file-backed offload instead of meta + hook offload (#6471)
Remove accelerate: explicit WeightLoader for weight loading, placemen…