Skip to content

[BUG] #4893 (fix of #4860) incomplete: after a cancelled/failed AWQ or QQQ quantize(), finished layers keep CUDA-only kernels on CPU (failure branch never runs rehome_quantized_kernel) -> next forward NotImplementedError #4947

Closed

Description

@Qubitium

Found on main @ 3867c82, RTX 4090, torch 2.15.

What is wrong

#4893 (fix of #4860), and #4829/#4580 before it, made an in-session model usable after a cancelled or failed quantize(). The failure branch now restores the in-flight layer, restores the offloaded base modules and materializes the layers that were never reached (gptqmodel/looper/module_looper.py:2085-2112). It never calls rehome_quantized_kernel() (gptqmodel/models/base.py:640). The success path runs it at base.py:2627 (#4381/#4450): the quantize loop leaves packed layers on CPU, so AWQ/QQQ/GGUF modules packed with an accelerator-only kernel must be switched to the portable Torch kernel before any in-session forward.

After a cancel or failure, the layers that finished before the cancel point keep their CUDA-only kernel (AwqGEMMLinear, QQQLinear) while their weights sit on CPU behind the offload hooks. The next forward raises:

NotImplementedError: Could not run 'gptqmodel_awq::gemm_forward_fp32_reduce' with arguments from the 'CPU' backend.

GPTQ passes only because its pack kernel (TorchLinear) already runs on CPU. The cancel regression tests (test_cancelled_quantize_disk_offload_4807.py, test_cancelled_quantize_default_offload_4860.py, test_cancelled_quantize_layer_cleanup_4546.py) only use GPTQ.

Repro

Qwen2.5-0.5B-Instruct truncated to 4 layers (num_hidden_layers=4), 16 C4 rows, default offload_to_disk=True:

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import config as C
from gptqmodel.looper.module_looper import StopMainLoop
m = GPTQModel.load(MODEL_4L, C.AWQConfig(bits=4, group_size=128), dtype=torch.float16)
def cb(**kw):
    if kw.get("stage") == "forward_start" and kw.get("layer_idx") == AT:
        return StopMainLoop                      # or: raise RuntimeError("injected")
m.subset_callback = cb
try: m.quantize(C.CalibrationConfig(dataset=calib, batch_size=4))
except BaseException as e: print("ERR", type(e).__name__)
x = m.tokenizer("Hello world, the capital of France is", return_tensors="pt").input_ids
m.model(x.to(m.model.get_input_embeddings().weight.device))
method cancel layer kernels after the run in-session forward
GPTQ StopMainLoop at layer 2 / RuntimeError at 1 TorchLinear (done) / nf12 shell (in-flight) / Linear OK
AWQ none (success) AwqTorchLinear x4 (rehomed) OK
AWQ StopMainLoop at layer 2 AwqGEMMLinear (layers 0-1, hooked) / AutoNF12HookedLinear / Linear NotImplementedError ... gemm_forward_fp32_reduce ... 'CPU' backend
AWQ RuntimeError at layer 1 same same
AWQ StopMainLoop at layer 3 (last, no unreached layer) AwqGEMMLinear x3 same
QQQ StopMainLoop at 2 / RuntimeError at 1 QQQLinear NotImplementedError ... gptqmodel_qqq::qqq_gemm ... 'CPU' backend

It is the same at 0facf5f^ (before #4893), so this is not a regression from #4893. It is the part of the cancelled-run contract that #4546/#4807/#4829/#4860 left uncovered for the non-GPTQ methods. GGUF is in the same _IN_SESSION_KERNEL_METHODS set but runs through the weight-only looper. I did not drive a cancel there.

Suggested fix

At the end of the failure branch, after _materialize_unreached_meta_modules(), call rehome_quantized_kernel(self.gptq_model) best-effort: catch and log its "save and reload" RuntimeError so the original exception still propagates. Do the same in WeightOnlyLooper's failure branch. rehome_quantized_kernel already copes with offloaded modules (#4450).

Test that should have caught it

Parametrize tests/test_cancelled_quantize_default_offload_4860.py (and the #4807 test) over METHOD.AWQ and METHOD.QQQ on CUDA, and assert a finite in-session forward after the cancel.

Severity

Medium: for AWQ and QQQ, the documented "cancelled quantize leaves a usable model" guarantee does not hold on any cancel or failure, with either default offload or the cancel-at-last-layer case.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4979

    Finish #4893: after a cancelled/failed AWQ or QQQ quantize(), finished layers keep CUDA-only kernels on CPU so the failure path leaves an unrunnable model; rehome or restore those layers in the failure cleanup and test both methods.

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

Metadata

Metadata

Assignees

No one assigned

    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