我在一个ml.p3.2xlarge实例上使用Tensorflow训练一个Seq2Seq模型。当我在Google Colab上运行代码时,每个epoch的时间大约是40分钟。然而在实例上却需要大约5个小时!
这是我的训练代码
def train_model(train_translator, dataset, path, num=8): with tf.device("/GPU:0"): cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=path, save_weights_only=True, verbose=1) batch_loss = BatchLogs('batch_loss') train_translator.fit(dataset, epochs=num,callbacks=[batch_loss,cp_callback]) return train_translator
我还尝试过不使用tf.device
命令,但时间仍然相同。我做错了什么吗?
回答:
我不得不通过以下方式强制使用GPU
with tf.device('/device:GPU:0')