完整报错
RuntimeError: CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
描述
师兄告诉我分配给我的GPU编号为6和7,但是我在训练的时候使用
device = torch.device('cuda:6')
报如上错误。
解决
原因在于,虽然师兄分配给我的卡为6,7,但是在我自己登陆的用户里,对应映射的编号是0,1,我作为非管理员的用户看不到全局的卡的状态,只能看到映射后的编号。所以如果我使用代码
device = torch.device('cuda:0')
就是在使用编号为6的卡,代码
device = torch.device('cuda:1')
就是在使用编号为7的卡。