首页 > 解决方案 > cuDNN 内核上的 LSTM 配置

问题描述

我正在尝试在具有 gpu 支持的 Google Colab 中使用自动编码器配置运行 LSTM。但我收到以下警告:

警告:tensorflow:Layer lstm 不会使用 cuDNN 内核,因为它不符合 cuDNN 内核标准。在 GPU 上运行时,它将使用通用 GPU 内核作为后备

通用 GPU 内核比 cuDNN 内核慢得多。所以我搜索了解决方案,并在此处找到(https://keras.io/api/layers/recurrent_layers/lstm/)LSTM单元的 cuDNN 内核要求。具体来说:

activation == tanh
recurrent_activation == sigmoid
recurrent_dropout == 0
unroll is False
use_bias is True
Inputs, if use masking, are strictly right-padded.
Eager execution is enabled in the outermost context.

我以为我在激活函数中发现了问题,即“relu”,其他 cuDNN 要求是 TF 中的默认值。这是更新的代码:

model = Sequential()
model.add(LSTM(200, activation='tanh',input_shape=(n_timesteps, n_features)))
model.add(RepeatVector(n_outputs))
model.add(LSTM(200, activation='tanh', return_sequences=True))
model.add(TimeDistributed(Dense(100, activation='relu')))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam')
model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=verbose)

但是在执行时,我会收到相同的警告,即未满足 cuDNN 要求。怎么了?

TF:2.3.0

标签: tensorflowkeraslstm

解决方案


推荐阅读