【发布时间】:2019-04-29 14:43:11
【问题描述】:
下面是我正在使用的代码。我注释掉了将我的模型转换为 TPU 模型的行。使用 GPU 处理相同数量的数据,一个 epoch 需要 7 秒,而使用 TPU 需要 90 秒。
Inp = tf.keras.Input(name='input', shape=(input_dim,), dtype=tf.float32)
x = tf.keras.layers.Dense(900, kernel_initializer='uniform', activation='relu', input_dim=input_dim, name = 'Dense_01')(Inp)
x = tf.keras.layers.Dropout(0.3, name = 'Dropout_02')(x)
output = tf.keras.layers.Dense(stop_criteria, activation='softmax',name = 'Dense_02')(x)
model = tf.keras.Model(inputs=[Inp], outputs=[output])
opt = tf.train.AdamOptimizer(.001)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['acc'])
'''tpu_model = tf.contrib.tpu.keras_to_tpu_model(model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
tf.contrib.cluster_resolver.TPUClusterResolver(TPU_ADDRESS)))'''
model.fit(X_tra, y_tra, epochs=5, batch_size=batch_size, shuffle=False,
validation_split=0.1, verbose=2)
这是notebook的链接
【问题讨论】:
-
你能分享一个重现减速的笔记本吗?
-
@BobSmith 我更新了问题并提供了 colab notebook 的链接
-
您是否根据cloud.google.com/tpu/docs/tpus#when_to_use_tpus检查了您的脚本是否适合TPU用例?
-
@Jaroslav 我最终使用了 GPU,因为我的数据集并没有那么大。
-
@mjosh 你指的是 TPU 还是 GPU?
标签: tensorflow keras google-colaboratory google-cloud-tpu mlp