AutoDL 跑深度学习报错:RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

提示中给出了一段其他的代码来检测:

import torch

# 设置CUDA和cuDNN配置
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = False
torch.backends.cudnn.allow_tf32 = True

# 创建输入数据和网络
data = torch.randn([16, 1, 33, 33], dtype=torch.float, device='cuda', requires_grad=True)
net = torch.nn.Conv2d(1, 64, kernel_size=[9, 9], padding=[4, 4], stride=[1, 1], dilation=[1, 1], groups=1)
net = net.cuda().float()

# 在GPU上执行前向传播和反向传播
out = net(data)
out.backward(torch.randn_like(out))
torch.cuda.synchronize()

# 显示卷积参数信息
print("ConvolutionParams")
print("data_type = CUDNN_DATA_FLOAT")
print("padding = [4, 4, 0]")
print("stride = [1, 1, 0]")
print("dilation = [1, 1, 0]")
print("groups = 1")
print("deterministic = false")
print("allow_tf32 = true")
print("input: TensorDescriptor 0x56528e74e640")
print("type = CUDNN_DATA_FLOAT")
print("nbDims = 4")
print("dimA = 16, 1, 33, 33, ")
print("strideA = 1089, 1089, 33, 1, ")
print("output: TensorDescriptor 0x56528e765c50")
print("type = CUDNN_DATA_FLOAT")
print("nbDims = 4")
print("dimA = 16, 64, 33, 33, ")
print("strideA = 69696, 1089, 33, 1, ")
print("weight: FilterDescriptor 0x56528e765c10")
print("type = CUDNN_DATA_FLOAT")
print("tensor_format = CUDNN_TENSOR_NCHW")
print("nbDims = 4")
print("dimA = 64, 1, 9, 9, ")
print("Pointer addresses:")
print("input: 0x7f2642c70c00")
print("output: 0x7f25e4400000")
print("weight: 0x7f2642c00000")

运行以后依旧出现以上报错,说明并不是脚本的问题。但想来想去,Auto DL平台CUDA与cuDNN是配置好的啊,不会出现CUDA和cuDNN版本与PyTorch不兼容的问题。

也有伙伴说是由于显存不足,需要调整Batchsize,于是把Batchsize从32依次调整到16、8、4,仍然不管用,且运行

nvidia-smi

发现显存是没问题的,后来在运行之前加入了下面这行代码

CUDA_VISIBLE_DEVICES=1 python xxx.py

问题得到完美解决,代码跑起来了。

原因分析:加上 CUDA_VISIBLE_DEVICES=1 这一行命令的作用是指定程序在哪块GPU上运行。

在多GPU环境下,有时候默认情况下程序可能会选择不合适的GPU,导致出现一些问题,比如显存溢出或者资源冲突等。通过设置 CUDA_VISIBLE_DEVICES 环境变量,可以显式地告诉程序在哪块GPU上运行,从而避免这些问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值