1. 程式人生 > >RuntimeError: all tensors must be on devices[0]問題解決方案

RuntimeError: all tensors must be on devices[0]問題解決方案

RuntimeError: all tensors must be on devices[0]

該問題由於PyTorch程式設定的gpu_id編號未從0開始導致的。

解決方案,在執行python命令前設定一下CUDA_VISIBLE_DEVICES:

CUDA_VISIBLE_DEVICES=1,2,3 python example.py --gpu_id 0 1 2

注意:在程式中設定gpu_id仍要從0開始,上例中gpu_id 0對應device 1,gpu_id 1對應device 2,gpu_id 2對應device 3