failed to query event: CUDA_ERROR_ILLEGAL_INSTRUCTION: an illegal instruction was encountered

在这里插入图片描述
报错信息:
Error polling for event status: failed to query event: CUDA_ERROR_ILLEGAL_INSTRUCTION: an illegal instruction was encountered
2022-03-24 23:32:13.170887: F tensorflow/core/common_runtime/gpu/gpu_event_mgr.cc:273] Unexpected Event status: 1

情况描述:
我自定义了一个损失函数

        def amp_loss(y_true, y_pred):  #其实就是幅频特性的损失
            #tf.squeeze先去掉axis=1的维度,因为Computes the 1-dimensional discrete Fourier transform of a real-valued signal over the inner-most dimension of input.
            #tf.signal.rfft做DFT
            #tf.math.abs求幅值
            #tf.expand_dims还原原来的axis=1的维度
            
                amplitude_true = tf.expand_dims(tf.math.abs( tf.signal.rfft(tf.squeeze(y_true))),-1)
                amplitude_pred = tf.expand_dims(tf.math.abs( tf.signal.rfft(tf.squeeze(y_pred))),-1)

                amplitude_loss = tf.math.reduce_mean(tf.math.square(amplitude_true - amplitude_pred))

                return amplitude_loss

报错是在model.fit的时候出现的,考虑是以为损失函数中的某些算术操作我的cuda不支持

1.检查cudnn版本有无问题
像我的笔记本是tensorflow2.2 GPU版本,cudnn好像是7.6.5

我尝试在aws sagemaker studio lab可以运行
上面的是tensorflow-gpu 2.6.2 cudnn=8.2.1

2.尝试使用CPU运行
在import tensorflow as tf 前面
加入

import os

#用CPU跑
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"

以及尝试使用

with tf.device('/cpu:0'):

强制模型运行在CPU上,实测无问题。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值