繁体   English   中英

gpu 部分检测到,火炬张量未上传到 gpu

[英]gpu partially detected, torch tensor is not uploaded to gpu

检测到我的 gpu

torch.cuda.is_available()

torch.randn(1).cuda()

tensorflow.test.is_built_with_cuda()

torch.cuda.device_count()

但不在

device_lib.list_local_devices()

tensorflow.config.list_local_devices('GPU')

我使用的代码是:

print(torch.cuda.is_available())

print(torch.randn(1).cuda())

print(device_lib.list_local_devices())

print(tf.test.is_built_with_cuda())

print(tf.__version__)

print(tf.config.list_physical_devices('GPU'))

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
print(torch.cuda.device_count())

结果是:

True
tensor([0.7429], device='cuda:0')
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 11914755976629927437
xla_global_id: -1
]
True
2.10.0
[]
cuda:0
1

我使用的是 NVIDIA GTX 1070 Ti,Nvidia 显卡驱动 460.89、cuda 11.2、cudnn 8.1.1、torch 1.7.1+cu110、torchvision 0.8.2+cu110。

虽然上面的结果,我的深度学习 model 成功进入了 cuda。问题是我无法将我的张量数据获取到 gpu。当我使用print(type(x))检查数据类型时,它返回<class 'torch.Tensor'> .

然后我尝试了x.to(device)x.cuda()

但在这两种情况下,它都会向x.is_cuda返回 false。

当我试图通过我的 model 使这个数据 go 时,它返回了这个: RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

这意味着我的 model 在 gpu 上。我不明白为什么我的张量在 cpu 上,但我的 model 不在。

我的数据是由图像转换而来的张量,形状为[3, 3, 512, 512]。 我的 model 是一个 GAN。

没关系。

我没有重新分配 x。

以防有人遇到这个问题,使用x = x.cuda()而不是x.cuda()来修复它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM