解决AMD GPU上TensorFlow出现的CudnnRNN OpKernel未注册错误
解决AMD GPU(TensorFlow-DirectML)运行LSTM模型的报错问题
错误原因:默认Keras LSTM会尝试调用NVIDIA专属的CuDNN RNN算子,但AMD GPU的TensorFlow-DirectML后端不支持该算子,导致找不到对应OpKernel。
以下是可行的解决方案:
强制禁用CuDNN优化
在定义LSTM层时添加use_cudnn_on_gpu=False参数,让TensorFlow使用适配通用GPU的LSTM实现,DirectML即可处理:model = Sequential([ LSTM(units=50, return_sequences=True, input_shape=(lookback,1), use_cudnn_on_gpu=False), Dense(units=1) ])备选方案:切换循环激活函数
如果你的TensorFlow 2.10版本中use_cudnn_on_gpu参数不存在,可将recurrent_activation设为sigmoid(CuDNN LSTM默认用hard_sigmoid,切换后会自动 fallback 到通用实现):model = Sequential([ LSTM(units=50, return_sequences=True, input_shape=(lookback,1), recurrent_activation='sigmoid'), Dense(units=1) ])
修改完成后,重新编译并训练模型,即可在AMD GPU上正常运行,无需强制指定CPU设备。
内容的提问来源于stack exchange,提问作者Lakshit Karsoliya
相关产品推荐
相关产品推荐

