Repository navigation
fix(gptq): classify solver allocation failures for CPU fallback (#4350) - #4359
Merged
Merged
Conversation
- 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
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4350
Problem
The GPTQ CPU-fallback gates re-raised every
RuntimeErrorwhose text did not contain"out of memory". cuSOLVER/hipSOLVER report a failed solver workspace allocation asCUSOLVER_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()ingptqmodel/quantization/gptq.pyand used it at the Hessian-accumulation, shared-Hessian-cache and Hessian permutation/inverse fallback gates:torch.OutOfMemoryError/MemoryErrortypes, 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, ...);"out of memory"phrase;torch._C._LinAlgError(non-positive-definite Cholesky) is always a numerical failure, never a CPU-fallback trigger.Evidence (fail before on
origin/main4818ae7c2, pass after)Fallback engages (real GPU GPTQ task,
hessian_inverseraises the reported HIP error on CUDA):Before:
After:
Fallback does not engage (numerical failure,
hessian_inverseraisestorch._C._LinAlgError("The leading minor of order 1 is not positive definite")on CUDA):Before and after:
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-PDRuntimeError, and unrelated exceptions do not.Tests / lint
tests/test_gptq_hessian_alloc_fallback_4350.py: 13 passed (withCUDA_VISIBLE_DEVICES=3, RTX 4090; index 2 never touched).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
H.device.type == "cuda"(unchanged); ROCm is covered because it reports through the sametorchCUDA-like device namespace.