成功解决:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1! (when checking argument for argument index in method wrapper__index_select),报错问题。

问题原因:模型训练时,数据不在同一块GPU上
解决方案:在模型训练的代码最前面加上下面的代码即可
import os
# 指定使用一块GPU,[0,1,2,3]下面是只选择使用1号GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
博客主要讲述成功解决RuntimeError报错问题,该错误是在模型训练时,数据不在同一块GPU上导致。解决方案是在模型训练的代码最前面添加特定代码。

923

被折叠的 条评论
为什么被折叠?



