Skip to content

[BUG] GPTAQ/FOEM have no accelerator-OOM CPU fallback around hessian_inverse: HIPSOLVER/CUSOLVER_STATUS_ALLOC_FAILED aborts the run where GPTQ recovers (#4350/#4400 incomplete) #4604

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

#4350, #4400, #4442 and #4492 gave GPTQ (and QQQ/EXL3) a CPU fallback when the dense Hessian inverse runs out of accelerator memory. The guard is _is_memory_allocation_failure (it matches HIPSOLVER/CUSOLVER_STATUS_ALLOC_FAILED, OutOfMemoryError, ...). The GPTQ copy lives at gptqmodel/quantization/gptq.py:2647-2667.

GPTAQ and FOEM re-implement the quantize loop and call self.hessian_inverse(H) with no guard at all. For GPTAQ that is gptqmodel/quantization/gptaq.py:502; FOEM has the same pattern. A solver workspace allocation failure that GPTQ survives therefore aborts the whole GPTAQ/FOEM quantization.

I hit this for real while the card was shared and nearly full. A Llama-3.2-1B-Instruct GPTAQ run died with:

File "gptqmodel/quantization/gptaq.py", line 502, in quantize
File "gptqmodel/quantization/gptq.py", line 2204, in hessian_inverse
File "gptqmodel/quantization/gptq.py", line 2112, in try_factor
File "gptqmodel/quantization/gptq.py", line 2091, in inverse_factor
RuntimeError: hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling `hipsolverDnSpotrs(handle, uplo, n, nrhs, A, lda, B, ldb, devInfo)`.

Deterministic repro (inject the solver allocation failure)

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import config as C

_orig = torch.linalg.cholesky_ex
def fake(H, *a, **k):
    if H.is_cuda and H.shape[0] >= 896:
        raise RuntimeError("hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling `hipsolverDnSpotrf(...)`")
    return _orig(H, *a, **k)
torch.linalg.cholesky_ex = fake

for name, cfg in (("gptq",  C.GPTQConfig(bits=4, group_size=128)),
                  ("gptaq", C.GPTQConfig(bits=4, group_size=128, gptaq=C.GPTAQConfig())),
                  ("foem",  C.GPTQConfig(bits=4, group_size=128, foem=C.FOEMConfig()))):
    m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", cfg, dtype=torch.float16)
    m.model.model.layers = m.model.model.layers[:1]; m.model.config.num_hidden_layers = 1
    try:
        m.quantize(calib8); print(name, "OK")
    except Exception as e:
        print(name, "CRASH", e)

Output:

INFO  Quantization: Module `self_attn.q_proj` -> CPU fallback complete; moving final quantized weights back to cuda:0.
... (all 7 modules)
gptq OK
gptaq CRASH hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling `hipsolverDnSpotrf(...)`
foem CRASH hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling `hipsolverDnSpotrf(...)`

Suggested fix

Share GPTQ's guarded inverse with GPTAQ and FOEM. Factor the try: hessian_inverse(...) except RuntimeError: if _is_memory_allocation_failure(exc): move H (and W, dXXT for GPTAQ's native delta, the static-group quantizers) to CPU and retry block from GPTQ._quantize_impl into a helper. Then call that helper from gptaq.py:502 and from the FOEM equivalent. The GPTAQ P = alpha * ((dXXT @ Hinv.T).triu(1)) @ Hinv product right after the inverse is another C x C allocation and needs the same treatment.

Test that should have caught it

The #4350/#4464 fallback tests cover GPTQ and QQQ only. Parametrizing them over gptaq=GPTAQConfig() and foem=FOEMConfig() would catch this.

Severity

Medium: GPTAQ/FOEM runs abort on large hidden sizes or shared GPUs, where GPTQ would have finished the module on CPU. Incomplete coverage of #4350/#4400.

🤖 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