Skip to content

[BUG] AWQ format=GEMV quantize() always raises at the end (no CPU in-session kernel; #4426 rehome): calibration lost, documented quantize->save flow crashes on ROCm and CUDA #4554

Closed

Description

@Qubitium

Found on main @ 4b65923, AMD Radeon AI PRO R9700 (gfx1201, ROCm 10.1). The root cause is not ROCm-specific.

What is wrong

AWQConfig(format="gemv") quantization runs the whole calibration, packs every layer, and then quantize() raises at the very end:

RuntimeError: Quantize: quantized layers use kernels that cannot run on the final device `cpu` (AwqGEMVTritonLinear). The in-session model cannot run inference; reload the saved checkpoint on this device (or use the portable Torch backend) before using it.

rehome_quantized_kernel() (gptqmodel/models/base.py:631-689, called from quantize() at base.py:2510) runs for METHOD.AWQ because AWQ is in _IN_SESSION_KERNEL_METHODS (base.py:563). The quantize loop leaves the packed layers on CPU, and select_in_session_quant_linear(qcfg, cpu) has no CPU kernel for the FORMAT.GEMV layout (AwqTorchLinear only handles FORMAT.GEMM), so it raises ValueError("No valid quant linear"). That error is then turned into a hard RuntimeError from quantize().

Effects:

  • Any script that follows the documented quantize() -> save() -> reload flow for GEMV (docs/rocm-rdna4.md, "AWQ GEMV AUTO resolution": "quantize -> save -> reload with BACKEND.AWQ_GEMV_TRITON") aborts after the full calibration time, and nothing is saved.
  • The message tells the user to "reload the saved checkpoint", but quantize() raised before the user could save anything.
  • The model is actually fine. If the exception is caught, save() works and the checkpoint reloads and generates correctly with BACKEND.AWQ_GEMV_TRITON (see the repro). The only problem is the hard raise on a path that does not need an in-session forward.

The same applies on CUDA: the GEMV pack kernel AwqGEMVLinear is CUDA-only, and there is still no CPU GEMV kernel. On ROCm this breaks the path that #4107/#4424 made selectable (awq_gemv_pack_backend -> AWQ_GEMV_TRITON). The raise came in with the #4381 fix (#4426).

Minimal repro

import torch, gzip, json
from gptqmodel import GPTQModel, BACKEND
from gptqmodel.quantization.config import AWQConfig

calib = []
with gzip.open("c4-train.00000-of-01024.json.gz", "rt") as f:
    for line in f:
        t = json.loads(line)["text"]
        if len(t) >= 1500:
            calib.append(t[:2500])
            if len(calib) >= 16: break

model = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", AWQConfig(bits=4, group_size=128, format="gemv"), dtype=torch.float16)
try:
    model.quantize(calib)
except Exception as e:
    print("quantize raised:", type(e).__name__, e)
model.save("out_gemv")                      # works
q = GPTQModel.load("out_gemv", backend=BACKEND.AWQ_GEMV_TRITON, dtype=torch.float16)
ids = q.tokenizer("The capital of France is", return_tensors="pt").to("cuda:0")
print(q.tokenizer.decode(q.generate(**ids, max_new_tokens=12, do_sample=False)[0]))

Output (gfx1201):

quantize raised: RuntimeError Quantize: quantized layers use kernels that cannot run on the final device `cpu` (AwqGEMVTritonLinear). The in-session model cannot run inference; reload the saved checkpoint on this device (or use the portable Torch backend) before using it.
INFO  Kernel: loaded -> `[AwqGEMVTritonLinear]`
The capital of France is Paris. The population of Paris is 2,40

The same failure happens with the full 128-sample run (the matrix job crashes in quantize() after about 2 minutes of calibration).

Suggested fix

When no layout-compatible kernel exists for the final device, rehome_quantized_kernel should not fail quantize(). Options:

  • log a warning and leave the packed modules as they are. Raise the "save and reload" error lazily from the first in-session forward, so save() still works.
  • or, when the final device is CPU but an accelerator kernel for the layout exists (AwqGEMVTritonLinear on ROCm, AwqGEMVLinear on CUDA), keep or move the quantized layers to that accelerator instead of failing.

In both cases the message should say "save the model and reload it", not "reload the saved checkpoint".

Test that should have caught it

tests/test_quantize_in_session_4381.py::test_rehome_quantized_kernel_raises_when_no_portable_kernel pins the raise with a mocked selector. No test runs quantize() + save() end to end for FORMAT.GEMV/GEMV_FAST, and tests/test_rocm_awq_gemv_gating.py only checks kernel selection. A small AWQConfig(format="gemv") quantize -> save -> reload test (CUDA and ROCm) would catch it.

Severity

Medium-high. Every AWQ FORMAT.GEMV quantization crashes at the end of a full calibration, on a documented and supported path. The workaround (catch the exception, then call save()) is not documented, and the error message points the user the wrong way.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed by an AI agent. Will reproduce on CPU, fix, add a focused regression test, and open a PR.

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