【发布时间】:2019-03-05 22:26:14
【问题描述】:
我刚刚尝试在 Google Colab 中使用 TPU,我想看看 TPU 比 GPU 快多少。我得到了令人惊讶的相反结果。
以下是NN。
random_image = tf.random_normal((100, 100, 100, 3))
result = tf.layers.conv2d(random_image, 32, 7)
result = tf.reduce_sum(result)
性能结果:
CPU: 8s
GPU: 0.18s
TPU: 0.50s
不知道为什么.... TPU的完整代码如下:
def calc():
random_image = tf.random_normal((100, 100, 100, 3))
result = tf.layers.conv2d(random_image, 32, 7)
result = tf.reduce_sum(result)
return result
tpu_ops = tf.contrib.tpu.batch_parallel(calc, [], num_shards=8)
session = tf.Session(tpu_address)
try:
print('Initializing global variables...')
session.run(tf.global_variables_initializer())
print('Warming up...')
session.run(tf.contrib.tpu.initialize_system())
print('Profiling')
start = time.time()
session.run(tpu_ops)
end = time.time()
elapsed = end - start
print(elapsed)
finally:
session.run(tf.contrib.tpu.shutdown_system())
session.close()
【问题讨论】:
-
我怀疑这还不足以作为充分利用 TPU 的基准。您可以尝试调整示例笔记本中的微基准:colab.research.google.com/notebooks/…
-
这就是我适应上面示例代码的方式......虽然我首先发现了 MNIST 示例的问题(GPU 大约需要 0.8s/100 步,但 TPU 需要 2.2s/100 步)。我怀疑需要编写一些特定于 TPU 的代码才能利用它...github.com/tensorflow/tensorflow/tree/master/tensorflow/…
-
是的,您必须抽取 100 兆 MB 并循环多次才能看到差异。但它比 same 代码扩展更快更重要。你只需要设置从 1 个 TPU 到 N 个 TPU。在 8 之后使用 GPU,您必须开始进行 horovd 和集群分发并更改设置和...
标签: tensorflow machine-learning gpu google-colaboratory google-cloud-tpu