首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在google colab中使用TPU

如何在google colab中使用TPU
EN

Stack Overflow用户
提问于 2018-09-27 14:16:55
回答 1查看 15.8K关注 0票数 13

Google colab在运行时加速器中引入了TPU。我找到了一个例子,如何在Official Tensorflow github中使用TPU。但是这个例子在google-colaboratory上不起作用。它停留在下面这一行:

代码语言:javascript
复制
tf.contrib.tpu.keras_to_tpu_model(model, strategy=strategy)

当我在colab上运行print available devices时,它返回用于TPU加速器的[]。有人知道如何在colab上使用TPU吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-27 23:41:21

下面是一个特定于Colab的TPU示例:https://colab.research.google.com/github/tensorflow/tpu/blob/master/tools/colab/shakespeare_with_tpu_and_keras.ipynb

关键线路是那些连接到TPU本身的线路:

代码语言:javascript
复制
# This address identifies the TPU we'll use when configuring TensorFlow.
TPU_WORKER = 'grpc://' + os.environ['COLAB_TPU_ADDR']

...

tpu_model = tf.contrib.tpu.keras_to_tpu_model(
training_model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
    tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)))

(与GPU不同,使用TPU需要显式连接到TPU worker。因此,您需要调整您的训练和推理定义,以观察加速效果。)

票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52530578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档