google-cloud-platform - 将 Colab 连接到付费 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 名称和 'credentials=gcp-permissions.json' 的 TPUClusterResolver 调用 - 结果相同。我已经仔细检查了我的 TPU 是否已在 GCP 控制台中启动并运行。它不是可抢占的。我错过了什么?
谢谢!
解决方案
所以看起来您正试图从 Colab 笔记本连接到您自己的 Google Cloud 项目中的付费 TPU,对吗?这是行不通的,因为 Colab 运行时由 GCE VM 支持,而 GCE VM 与您自己的项目位于不同的项目中My-project-name
。因此,您还想在同一个项目中创建一个 GCE 虚拟机并从该虚拟机运行您的训练脚本。查看本教程:https ://cloud.google.com/tpu/docs/quickstart 。
推荐阅读
- django - 如何在 django 表单向导中制作 django 字段,如 RadioSelector
- python - 从 trello 导入 TrelloClient 停止工作
- android - 在 Kotlin 中使用静态 Java 方法作为静态(或单例)属性
- javascript - 未定义的 ReadableStream 前缀
- angular - ngFor 使用 trackby 按文本过滤
- c++ - 仅当使用 unordered_map 而不是向量时,将 const 作为此参数传递才会丢弃限定符
- javascript - 是的,如何根据其他几个变量的函数验证一个变量?
- python - 跨多面图设置轴限制
- laravel - Laravel 如何在工厂中有 if 语句?
- uml - UML 如果父类连接,是否子类也必须连接