CUSOLVER_STATUS_INTERNAL_ERROR cuda runtime_error ai_generated true

运行时错误:cusolver错误:计算奇异矩阵的SVD时出现CUSOLVER_STATUS_INTERNAL_ERROR

RuntimeError: cusolver error: CUSOLVER_STATUS_INTERNAL_ERROR when computing SVD of a singular matrix

ID: cuda/cusolver-internal-error-on-svd

其他格式: JSON · Markdown 中文 · English
76%修复率
84%置信度
1证据数
2025-03-12首次发现

版本兼容性

版本状态引入弃用备注
CUDA 12.4 active
cuSolver 11.5.1 active
PyTorch 2.3.0 active

根因分析

当输入矩阵恰好是奇异矩阵或包含NaN/inf值时,cuSolver的SVD例程(gesvdj或gesvd)内部失败,导致迭代求解器中的缓冲区溢出或除零错误。

English

cuSolver's SVD routine (gesvdj or gesvd) fails internally when the input matrix is exactly singular or has NaN/inf values, causing a buffer overflow or division by zero in the iterative solver.

generic

官方文档

https://docs.nvidia.com/cuda/cusolver/index.html

解决方案

  1. Preprocess the matrix to remove exact singularities: add a small regularization term (e.g., A += 1e-8 * torch.eye(n, device=A.device)) before calling torch.linalg.svd. Example: A_reg = A + 1e-8 * torch.eye(A.size(0), device=A.device); U, S, V = torch.linalg.svd(A_reg).
  2. Use torch.linalg.lstsq instead of SVD for solving least-squares problems, as it handles singular matrices more robustly.

无效尝试

常见但无效的做法:

  1. 60% 失败

    This works but defeats the purpose of GPU acceleration; also, the error may still occur on CPU if the matrix is singular.

  2. 85% 失败

    Singular matrices remain singular regardless of precision; the error is algorithmic, not numerical.