tensorflow - Tensorflow:不同时期的训练速度和 CPU 使用率
问题描述
我正在一个包含大约 8000 个句子的句子分类数据集上训练一个简单的 Bi-LSTM 模型。我提取了关于模型的代码片段,如下所示。我在不同的时期随机且不一致地经历了训练减速和加速。这很奇怪,因为在我的本地机器或公司服务器上,这并没有发生,而是在我的 AWS 服务器上。我想知道在不同时期随机导致训练减速的原因是什么?我可以确认没有其他 CPU 或内存密集型进程同时运行。我的程序是唯一的。
代码:
input_shapes=Input(shape=(100, 300))
embedding = Embedding(...)(input_shapes)
lstm = Bidirectional(LSTM(units=100, return_sequences=False))(embedding)
dense = Dense(600)(lstm)
final = Dense(num_of_classes, activation="softmax")(dense)
model = Model(inputs=input_shapes, outputs=final)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
training_generator = data_generator(...) #my own method to generate batch on the fly
training_steps_per_epoch = round(len(X_train) / 100
model.fit_generator(training_generator, steps_per_epoch=training_steps_per_epoch, epochs=20)
...
配置:
OS: Ubuntu 18.04.2 LTS
CPU: 8 Cores, Mem: 32G
conda 4.4.10
tensorflow 1.10.0
theano 0.9.0
scikit learn 0.19.0
keras 2.0.9
fasttext 0.9.1
nltk 3.2.5 (stopwords, wordnet)
pydot 1.2.3
观察/问题:在不同的时期,训练速度会减慢并随机加快,在此期间观察到不同的 CPU 使用率。例如,在 60 秒的 epoch 中,我注意到 CPU 使用率约为 300%。但是当它花费 <10s 时,CPU 使用率为 600%。但是,正如我上面提到的,在 AWS 服务器上的整个这段时间内,根本没有其他用户进程。我的 AWS 服务器是专门为此实验创建的。而且这只发生在我的 AWS 服务器上,而不是我的本地机器或公司服务器上。查看不同时期的观察时间截图
截屏
解决方案
推荐阅读
- java - 从 CLI 构建的 Maven 失败但从 Eclipse 成功
- python - Python/Tkinter:是否可以通过单击外部来检测 OptionMenu/Menubutton 弹出窗口何时关闭?
- spring - 使用spring依赖管理无法解析依赖
- sockets - 在 FTP 服务器中,为什么服务器应该打开端口而不是客户端?
- go - 为什么我的 go 代码在使用 goroutine 和 channels 时会挂起?
- node.js - websocket 就绪状态 0(连接中)
- bash - 如何根据变量的长度来控制线的长度,并且能够使线均匀
- spring - Spring Boot 配置客户端刷新属性不起作用
- python - 获取数据框中大型语料库中选定单词的百分比
- c++ - 关于 C++ 中字符串流中的数组