[英]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.