RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

遇到的问题

RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

详细错误

***.py
return F.conv1d(input, weight, bias, self.stride,
RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
You can try to repro this exception using the following code snippet. If that doesn’t trigger the error, please include your original repro script when reporting this issue.

import torch
torch.backends.cuda.matmul.allow_tf32 = False
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = False
torch.backends.cudnn.allow_tf32 = True
data = torch.randn([64, 80, 1, 200], dtype=torch.float, device=‘cuda’, requires_grad=True)
net = torch.nn.Conv2d(80, 512, kernel_size=[1, 5], padding=[0, 2], stride=[1, 1], dilation=[1, 1], groups=1)
net = net.cuda().float()
out = net(data)
out.backward(torch.randn_like(out))
torch.cuda.synchronize()

解释:如上所示在某个文件中的F.conv1d报错

解决方法

在相同的环境,使用相同的代码跑,前几天不报错,今天突然报错了;理论上讲不是CUDA、cudnn、pytorch版本的问题;可能是一个bug;
在模型加载为分布式模型后,添加 torch.backends.cudnn.benchmark=False,可解决问题;

ddp_model = torch.nn.parallel.DistributedDataParallel(model)
device = torch.device("cuda")
torch.backends.cudnn.benchmark=False

原理

cudnn用来加速模型,benchmark打开会对卷积网络进行加速推理,速度大约是2倍?没实际跑过;benchmark关闭,不对卷积网络进行加速,上述卷积代码不报错;

你可能感兴趣的:(pytorch)