栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

cuda2 but found one of them on device cuda 0

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cuda2 but found one of them on device cuda 0

cuda2 but found one of them on device cuda 0

上面问题的重点是,不是cpu和gpu之间的常规问题,而是出现在不同gpu之间的数据。
出问题地方:

model = nn.DataParallel(model, device_ids=[2,4])

先说解决方法:
方案一:

model = nn.DataParallel(model, device_ids=[0,2,4])

前面一定要给一个0的序号,如果0被别人占了呢?
方案二:

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "2, 4"
model = nn.DataParallel(model, device_ids=[1,2])

首先两行指定了可见的gpu,然后再重新parallel的时候,就使用1,2(逻辑顺序)代替原来的2,4(实际物理顺序)


原因是DataParallel的缺省参数:

CLASS torch.nn.DataParallel(module, device_ids=None, output_device=None, dim=0)

有个output_device默认是0,即使前面设置的不包含0,这个参数也会使得0被调用,所以导致出现这种没有指定,但偏偏出现的cuda 0上的错误:“cuda2 but found one of them on device cuda 0”

以上解释参考自:
Pytorch的nn.DataParallel

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/268589.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号