Skip to content

fix(gptq): classify solver allocation failures for CPU fallback (#4350) - #4359

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4350-hessian-oom-fallback
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4350-hessian-oom-fallback

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4350

Problem

The GPTQ CPU-fallback gates re-raised every RuntimeError whose text did not contain "out of memory". cuSOLVER/hipSOLVER report a failed solver workspace allocation as CUSOLVER_STATUS_ALLOC_FAILED / HIPSOLVER_STATUS_ALLOC_FAILED, so the Hessian inverse aborted the whole run instead of finishing the module on CPU.

Fix

Added _is_memory_allocation_failure() in gptqmodel/quantization/gptq.py and used it at the Hessian-accumulation, shared-Hessian-cache and Hessian permutation/inverse fallback gates:

  • primary discriminator (structural): torch.OutOfMemoryError / MemoryError types, plus solver/allocator status codes (CUSOLVER_STATUS_ALLOC_FAILED, HIPSOLVER_STATUS_ALLOC_FAILED, CUBLAS_STATUS_ALLOC_FAILED, HIPBLAS_STATUS_ALLOC_FAILED, CUDNN_STATUS_ALLOC_FAILED, MIOPEN_STATUS_OUT_OF_RESOURCES) and CUDA/HIP allocation error names (cudaErrorMemoryAllocation, hipErrorOutOfMemory, ...);
  • last resort: the legacy "out of memory" phrase;
  • explicit exclusion: torch._C._LinAlgError (non-positive-definite Cholesky) is always a numerical failure, never a CPU-fallback trigger.

Evidence (fail before on origin/main 4818ae7c2, pass after)

Fallback engages (real GPU GPTQ task, hessian_inverse raises the reported HIP error on CUDA):

Before:

RuntimeError: hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling hipsolverDnSpotrs(...)
  raised out of GPTQ.quantize (no fallback)
1 passed, 12 failed

After:

test_solver_alloc_failure_engages_the_cpu_fallback PASSED
calls == {"cuda": 1, "cpu": 1}; qweight on cuda:0; log: "... falling back to CPU"
13 passed

Fallback does not engage (numerical failure, hessian_inverse raises torch._C._LinAlgError("The leading minor of order 1 is not positive definite") on CUDA):

Before and after:

test_numerical_cholesky_failure_does_not_engage_the_cpu_fallback PASSED
pytest.raises(torch._C._LinAlgError); calls == {"cuda": 1, "cpu": 0}

Classifier unit coverage (CPU): torch.OutOfMemoryError, MemoryError, HIPSOLVER_STATUS_ALLOC_FAILED, CUSOLVER_STATUS_ALLOC_FAILED, CUBLAS_STATUS_ALLOC_FAILED, hipErrorOutOfMemory, cudaErrorMemoryAllocation, and the legacy phrase classify as memory failures; _LinAlgError, generic non-PD RuntimeError, and unrelated exceptions do not.

Tests / lint

  • tests/test_gptq_hessian_alloc_fallback_4350.py: 13 passed (with CUDA_VISIBLE_DEVICES=3, RTX 4090; index 2 never touched).
  • Existing tests/test_gptq.py::test_gptq_cpu_hessian_fallback_returns_quantized_weights_to_original_cuda_device + tests/test_hessian_fallback_contracts.py: 27 passed together with the new file.
  • ruff check gptqmodel docs/eora tests setup.py: All checks passed.

Residual risk

  • The fallback gate still requires H.device.type == "cuda" (unchanged); ROCm is covered because it reports through the same torch CUDA-like device namespace.
  • The marker list is a curated set of known solver/allocator status names; an unfamiliar allocator status string that also omits "out of memory" would still propagate (by design: better than silently downgrading an unknown failure).
  • The CUDA fallback test is skipped on CPU-only CI; the classifier tests still run there.

- add _is_memory_allocation_failure(): torch OOM/MemoryError and
  cuSOLVER/hipSOLVER/cuBLAS/hipBLAS/cuDNN allocation status codes are
  memory failures; the legacy 'out of memory' text is a last resort
- non-positive-definite torch._C._LinAlgError stays a numerical failure
- use the classifier in the Hessian accumulation, shared-cache and
  Hessian permutation/inverse CPU fallback gates
- regression test covers fallback engagement and numerical propagation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant