简体   繁体   English

如何使用 Google Cloud Platform TPU v3?

[英]How to use Google Cloud Platform TPU v3?

I found a tutorial on How to Set up an Instance to Run a Jupyter Notebook in GCP?我找到了关于如何在 GCP 中设置实例以运行 Jupyter Notebook的教程

This tutorial is about how to run Jupyter Notebook in Google Cloud Platform.本教程是关于如何在 Google Cloud Platform 中运行 Jupyter Notebook。 I would like to use also TPU v3.我也想使用 TPU v3。 I also read the documentation https://cloud.google.com/tpu/docs/quickstart .我还阅读了文档https://cloud.google.com/tpu/docs/quickstart But unfortunately it doesn't help me.但不幸的是,它对我没有帮助。

My questions now are:我现在的问题是:

  • How do I create a TPU v3 and use it in the Jupyter Notebook?如何创建 TPU v3 并在 Jupyter Notebook 中使用它?
  • How do I read and write data when TPU v3 is selected as run time?选择 TPU v3 作为运行时,如何读写数据?

In Google Colab I do the following in order to use the TPU:在 Google Colab 中,我执行以下操作以使用 TPU:

%tensorflow_version 2.x
import tensorflow as tf
print("Tensorflow version " + tf.__version__)

try:
  tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  # TPU detection
  print('Running on TPU ', tpu.cluster_spec().as_dict()['worker'])
except ValueError:
  raise BaseException('ERROR: Not connected to a TPU runtime; please see the previous cell in this notebook for instructions!')

tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)
.
.
.
batch_size = 16 * tpu_strategy.num_replicas_in_sync
.
.
.
with tpu_strategy.scope(): 
  model = create_model()
model.summary()

How do I use a TPU v3 with Google Cloud Platform?如何将 TPU v3 与 Google Cloud Platform 结合使用?

It sounds like you were able to setup a Google Cloud Platform VM and use that VM to host a Jupyter notebook.听起来您可以设置 Google Cloud Platform VM 并使用该 VM 来托管 Jupyter 笔记本。

One thing to note is that you can create a Jupyter notebook directly in Google Cloud with this guide: https://cloud.google.com/ai-platform/notebooks/docs/create-new需要注意的一件事是,您可以使用本指南直接在 Google Cloud 中创建 Jupyter 笔记本: https ://cloud.google.com/ai-platform/notebooks/docs/create-new

If you really wanted to make your own VM and host Jupyter on there, you could try following this tutorial: https://cloud.google.com/tpu/docs/tutorials/mnist-2.x如果您真的想制作自己的虚拟机并在那里托管 Jupyter,可以尝试按照本教程进行操作: https ://cloud.google.com/tpu/docs/tutorials/mnist-2.x

Note there is the step ctpu up ... that will create a VM and a TPU.请注意,步骤ctpu up ...将创建一个 VM 和一个 TPU。 You could use that VM and follow the steps in the first tutorial you linked to turn that VM into your Jupyter host.您可以使用该 VM 并按照您链接的第一个教程中的步骤将该 VM 转换为您的 Jupyter 主机。 Then follow the rest of the steps in this tutorial from within a notebook hosted on that VM and see if it works然后从托管在该 VM 上的笔记本中执行本教程中的其余步骤,看看它是否有效

Overall I'd recommend:总的来说,我会推荐:

  • Use this if you want to use Google Cloud + Jupyter如果您想使用 Google Cloud + Jupyter,请使用 选项
  • Use Colab if you're OK with any notebook and want to use TPUs如果您对任何笔记本都满意并想使用 TPU,请使用 Colab
  • Use this guide if you want the best experience using TPUs and are OK with not having a notebook如果您想获得使用 TPU 的最佳体验并且没有笔记本电脑也可以,请使用本指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM