Skip to content

[BUG] #5031/#5066 cancelled-run contract: a Ctrl-C during pack_module leaves a half-built TorchLinear (no qweight/qzeros) in the model; every later forward raises AttributeError 'qzeros' #5089

Closed

Description

@Qubitium

Found on main @ e75181d, RTX 4090 (CUDA 13.2, torch 2.15). Same on c2b0bf64f, so not a regression. #5031/#5066 claim a "Runnable" in-session model after any cancelled quantize() (docs/cancelled-run-contract.md). This window was never covered.

What is wrong

GPTQProcessor.submodule_finalize (gptqmodel/looper/gptq_processor.py:1112-1160) first swaps the projection for its kernel class with create_quant_module(..., register_buffers=False). The kernel goes into the model without qweight/qzeros/scales. Only after that does it call pack_module() -> BaseQuantLinear.pack_gpu() (nn_modules/qlinear/__init__.py:2637) to register and fill those buffers. The weight-only path (WeightOnlyProcessor.submodule_finalize -> pack_module) does the same.

When a Ctrl-C or an exception lands while pack_gpu runs, the model is left holding a half-built TorchLinear. RunExitRecovery.abort() restores the in-flight layer and rehomes the kernels (rehome_failed_run_kernels), but it neither finishes the pack nor puts the original nn.Linear back. So every later forward fails:

AttributeError: 'TorchLinear' object has no attribute 'qzeros'

Packing is a large share of RTN/GPTQ wall time, so the window is wide. A random-time Ctrl-C sweep of RTN (Qwen2.5-0.5B, 4 layers, 33 cancel points) hit it once without any patching.

Repro (deterministic)

KeyboardInterrupt raised at the 60th Tensor.copy_ of a GPTQ run (inside pack_gpu of layer 0), Qwen2.5-0.5B-Instruct truncated to 4 layers:

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import config as C
state = {"n": 0}
orig = torch.Tensor.copy_
def copy_(self, *a, **k):
    state["n"] += 1
    if state["n"] == 60: raise KeyboardInterrupt()     # lands in pack_gpu (nn_modules/qlinear/__init__.py:2779)
    return orig(self, *a, **k)
m = GPTQModel.load(MODEL_4L, C.GPTQConfig(bits=4, group_size=128), dtype=torch.float16)
torch.Tensor.copy_ = copy_
try: m.quantize(C.CalibrationConfig(dataset=cal, batch_size=4))
except KeyboardInterrupt: pass
torch.Tensor.copy_ = orig
with torch.inference_mode(): m.model(ids, labels=ids)
interrupt at: __init__.py:2779 pack_gpu <- model.py:1428 pack_module <- gptq_processor.py:1153 submodule_finalize
AttributeError: 'TorchLinear' object has no attribute 'qzeros'

The result is identical on c2b0bf64f (interrupt at __init__.py:2733 pack_gpu). RTN through WeightOnlyLooper gives the same error when interrupted by a real timer Ctrl-C during packing.

Suggested fix

Make the kernel swap atomic with respect to packing. Build and pack the quant module off-model and install it with a single setattr once pack() has returned. Alternatively, have the run-exit recovery detect a quant module without its packed buffers (for example qweight missing) and put the original float module back. It is still available as the layers[...] source that pack_module received.

Test that should have caught it

tests/test_run_exit_recovery_contract_5060.py injects faults only at looper helper boundaries. Add a node that interrupts inside pack_module (GPTQ and RTN) and asserts that the next forward runs.

Severity

Low to medium. This is a loud failure, not silent corruption, but the cancelled-run contract says the model stays runnable, and the only recovery is to reload the model.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    More data, natural interrupts with no patching: 40 _thread.interrupt_main() timer Ctrl-Cs at uniform random times during RTNConfig(bits=4, group_size=128) quantize of the same 4-layer Qwen2.5-0.5B (default offload_to_disk=True), main @ e75181d:

    On c2b0bf64f the same sweep failed with device mismatches instead (#5011, now fixed). For weight-only methods, this window is now the dominant way a cancelled run leaves the model unusable.

    🤖 Generated with Claude Code

  2. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Agent claim released: agent-bf42512e3169 finished this issue.

    Pull request: #5152

    Reproducing the half-built kernel window after pack_module cancellation on CPU/GPTQ+RTN fixtures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions