下面代码单独测试可以运行,训练的时候就报错 ExternalError: Cudnn error, CUDNN_STATUS_EXECUTION_FAILED
USE_CUDA = True
place = fluid.CUDAPlace(0) if USE_CUDA else fluid.CPUPlace()
exe = fluid.Executor(place)
data = fluid.data(name='poetry', shape=[BATCH_SIZE, LENGTH], dtype='int64')
label = fluid.data(name='label', shape=[-1, 1], dtype='int64')
hid1 = fluid.data(name='H2L', shape=[BATCH_SIZE, NUM_LAYERS, HIDDEN_DIM], dtype='float32')
hid2 = fluid.data(name='C2L', shape=[BATCH_SIZE, NUM_LAYERS, HIDDEN_DIM], dtype='float32')
hid1 = fluid.layers.reshape(hid1, [NUM_LAYERS, BATCH_SIZE, HIDDEN_DIM])
hid2 = fluid.layers.reshape(hid1, [NUM_LAYERS, BATCH_SIZE, HIDDEN_DIM])
#LSTM
data = fluid.embedding(data, size=[DICT_SIZE, EMBD_SIZE], is_sparse=True)
# if IS_INFER == 0:
# h = fluid.layers.fill_constant([NUM_LAYERS, BATCH_SIZE, HIDDEN_DIM], 'float32', 0.0 )
# c = fluid.layers.fill_constant([NUM_LAYERS, BATCH_SIZE, HIDDEN_DIM], 'float32', 0.0 )
# else:
h, c = hid1, hid2
output, h, c = fluid.layers.lstm(data, h, c, max_len=64, hidden_size=HIDDEN_DIM, num_layers=NUM_LAYERS)
output = fluid.layers.reshape(output, [BATCH_SIZE*SEQ_SIZE, -1])
prediction = fluid.layers.fc(output, DICT_SIZE, act='softmax')
loss = fluid.layers.cross_entropy(prediction, label)
avg_loss = fluid.layers.mean(loss)
opt = fluid.optimizer.Adam(learning_rate=0.002)
re = opt.minimize(avg_loss)
Cudnn error,检查下cuDNN版本,需要使用 cuDNN 7.6+