FED之bug目录
一、RuntimeError: CUDA error: device-side assert triggered
错误描述:
RuntimeError: CUDA error: device-side assert triggered
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
报错图片如下:
由图片可得是batch:19752出错,于是用debug看看这个batch,详细报错如下:
可知是embedding的size不对
或者是以下这样
1.问题如下:
RuntimeError: CUDA error: device-side assert triggered 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训练问题,出现维度错误
定位到代码中的
原因:
在对单卡和多卡下的self.weights打印形状发现,多卡时此参数多了一个维度。self.weights的定义如下,nn.parameter是可学习的参数,大意是创建一个此形状的tensor,然后将其转换为可学习的参数。
我们怀疑是torch.nn.DataParrell或者torch.rand或者cfloat有问题,尝试过把cfloat换成其他的类型,最后发现维度出错的原因是cfloat表示复数tensor,pytorch在将参数从单gpu复制到多gpu上时,会把实部和虚部拆开,因此维度加倍,无法进行后面的复数计算。
解决办法:
去掉这个参数,重新定义实部和虚部参数,加载至gpu后,分别复制到其他gpu上,在每块gpu上都把实部和虚部结合成复数参数,从而进行复数运算。
代码:
运行指令:
python test.py 0,1
注意:device_ids表示的是虚拟的卡号,必须得有0号,如0,1或者0, 2,3。0号表示的是你填的物理卡的第一个
gpus表示物理的卡号。
pytorch之多GPU使用#CUDA_VISIBLE_DEVICES使用