Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python keras中的小型LSTM模型不适合我的GPU_Python_Tensorflow_Keras - Fatal编程技术网

Python keras中的小型LSTM模型不适合我的GPU

Python keras中的小型LSTM模型不适合我的GPU,python,tensorflow,keras,Python,Tensorflow,Keras,我正在Google Collab中编程一个相对较小的LSTM模型 作为参考,我使用TensorFlow 1.13构建模型,使用TensorFlow.keras构建KerasAPI seq_len = 20000; n_classes = 4 inputs = ll.Input(shape=(seq_len,)) x = ll.Embedding(len(word_index), 1000)(inputs) x = ll.LSTM(units=100, activation='relu', ret

我正在Google Collab中编程一个相对较小的LSTM模型

作为参考,我使用TensorFlow 1.13构建模型,使用TensorFlow.keras构建KerasAPI

seq_len = 20000; n_classes = 4
inputs = ll.Input(shape=(seq_len,))
x = ll.Embedding(len(word_index), 1000)(inputs)
x = ll.LSTM(units=100, activation='relu', return_sequences=True)(x)
outputs = ll.Dense(units = n_classes, activation='softmax')(x)
model = Model(inputs, outputs)
model.summary()
我有15GB的GPU RAM可用,根据型号,批量大小为32的GPU应该适合3GB的RAM

但是,无论何时启动培训,服务器都会耗尽内存

公平地说,我使用的是非常长的数据序列(20000是最大的序列长度),但我希望模型能够在内存中象征性地展开,并且正好适合

将批处理大小减少到1也无济于事

发生了什么事?如何使此模型适合内存

编辑:我尝试将序列长度减少到2,这确实使它适合内存。但我需要序列长度保持高。如何告诉Tensorflow在任何时候都不要展开网络?(我怀疑这就是幕后发生的事情,我如何才能确认这是否属实?)


编辑:如果删除Softmax层,则内存使用将再次降至正常范围。我认为Softmax层导致Tensorflow展开网络。不过,时间分配Softmax并没有帮助

为CuDNNLSTM层更改LSTM层成功了

inputs = ll.Input(shape=(seq_len,))
x = ll.Embedding(len(word_index), 1024)(inputs)
x = ll.CuDNNLSTM(units=100, return_sequences=True)(x)
x = ll.Dense(units = n_classes, activation='softmax')(x)
outputs = x
model = Model(inputs, outputs)

请包含model.summary()的输出,参数数量可能很大。用不同的序列长度进行实验,看看参数数量的变化。@MatiasValdenegro参数数量在我通常使用的范围内:
1474404
parameters