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关闭,不对卷积网络进行加速,上述卷积代码不报错;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值