【记录】torch.inverse报错及其解决办法

在运行矩阵求逆代码时运行torch.inverse()或者torch.linalg.inv()遇到报错:

RuntimeError: Error in dlopen: libnvJitLink.so.12: cannot open shared object file: No such file or directory 

原因是少安装了libnvJitLink.so.12这个库,安装链接
在安装完之后依旧出现报错

RuntimeError: cusolver error: CUSOLVER_STATUS_NOT_INITIALIZED, when calling `cusolverDnCreate(handle)` 

网上也查不到相应的解决方法,也不是GPU显存不够出现的问题,因此选择使用cpu进行计算,然后再放到cuda上。

# 函数运行测试
import torch
import numpy as np
device = torch.device("cuda:6" if torch.cuda.is_available() else "cpu")
print(device)

a = np.array([[[ 2.7734e+03,  0.0000e+00, -1.0740e+03, -4.5573e+06],[ 0.0000e+00, -2.7734e+03, -4.2000e+02,  9.9102e+05],[ 0.0000e+00, 0.0000e+00, -1.0000e+00,  1.2700e+03],[ 0.0000e+00,  0.0000e+00,  0.0000e+00,  1.0000e+00]]])
print(a)
a = torch.from_numpy(a)
print(a)
a_gpu = a.to(device)
print(a_gpu)
a_inv_cpu = torch.inverse(a) # 在cpu上torch.inverse()可以正常运行
print(a_inv_cpu)
a_inv_gpu = torch.inverse(a_gpu.to('cpu')).to(device) #先放到cpu上计算,完成后再放到gpu上参与下一步深度学习
#a_inv_gpu = torch.inverse(a_gpu)
print(a_inv_gpu)

猜你喜欢

转载自blog.csdn.net/yaoyao_chen/article/details/130688639
今日推荐