将 Colab 连接到付费 TPU

Connect Colab to paid TPU

我想将 Colab 连接到付费 TPU(从免费 TPU 升级)。我使用本指南创建了一个 JSON 密钥:https://cloud.google.com/docs/authentication/production#auth-cloud-explicit-python,然后将其上传到 Colab。我可以连接到我的存储,但不能连接到 TPU:

%tensorflow_version 2.x
import tensorflow as tf
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './gcp-permissions.json'

# Authenticated API request - works.
storage_client = storage.Client.from_service_account_json(
    'gcp-permissions.json')
print(list(storage_client.list_buckets())

#Accessing the TPU - does not work. Request times out.
cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(
    tpu='My-TPU-Name',
    zone='us-central1-a',
    project='My-Project-Name'
)

我也尝试过仅使用 tpu 名称调用 TPUClusterResolver,并且 'credentials=gcp-permissions.json' - 结果相同。我已经在 GCP 控制台中仔细检查了我的 TPU 是否已启动并且 运行。它是不可抢占的。我错过了什么?

谢谢!

看来您正尝试通过 Colab 笔记本从您自己的 Google 云项目连接到付费 TPU,对吗?这不会起作用,因为 Colab 运行time 由 GCE VM 支持,该 VM 与您自己的 My-project-name 位于不同的项目中。因此,您还想在同一个项目中创建一个 GCE VM,并 运行 来自该 VM 的训练脚本。查看本教程:https://cloud.google.com/tpu/docs/quickstart.