无法从 GCP 中的 VM 访问 TPU
Can't access TPU from VM in GCP
尝试运行此代码
import os import tensorflow as tf from tensorflow.contrib
import tpu from tensorflow.contrib.cluster_resolver import TPUClusterResolver
def axy_computation(a, x, y): return a * x + y
inputs = [
3.0,
tf.ones([3, 3], tf.float32),
tf.ones([3, 3], tf.float32), ]
tpu_computation = tpu.rewrite(axy_computation, inputs)
tpu_grpc_url = TPUClusterResolver(
tpu=["sahil-wadhwa"], zone="us-central1-b").get_master()
with tf.Session(tpu_grpc_url) as sess:
sess.run(tpu.initialize_system())
sess.run(tf.global_variables_initializer())
output = sess.run(tpu_computation)
print(output)
sess.run(tpu.shutdown_system())
但是我得到以下错误,
googleapiclient.errors.HttpError: https://tpu.googleapis.com/v1alpha1/projects/nlp-research-198620/locations/us-central1-b/nodes/sahil-wadhwa?alt=json
returned "Permission 'tpu.nodes.get' denied on
'projects/nlp-research-198620/locations/us-central1-b/nodes/sahil-wadhwa'">
有人可以告诉我需要什么权限才能顺利地向 运行 提供我的 VM 或 TPU 吗?
ctpu 工具可自动执行许多此类步骤,是创建 TPU 和 VM 的推荐方法。
如果您更喜欢手动创建 VM,则需要按照此处所述将云平台身份验证范围添加到您的 VM
gcloud compute instances create tpu-demo-vm \
--machine-type=n1-standard-2 \
--image-project=ml-images \
--image-family=tf-1-11 \
--scopes=cloud-platform
https://cloud.google.com/tpu/docs/custom-setup#create_resources
Michaelb 的回答有效,但也可以在控制台中更改现有 VM 的权限。您必须停止 VM,然后对其进行编辑以允许 read/write 访问计算引擎 api。为此,请单击虚拟机的名称,然后单击顶部栏中的编辑; api 访问设置位于页面底部。
尝试运行此代码
import os import tensorflow as tf from tensorflow.contrib
import tpu from tensorflow.contrib.cluster_resolver import TPUClusterResolver
def axy_computation(a, x, y): return a * x + y
inputs = [
3.0,
tf.ones([3, 3], tf.float32),
tf.ones([3, 3], tf.float32), ]
tpu_computation = tpu.rewrite(axy_computation, inputs)
tpu_grpc_url = TPUClusterResolver(
tpu=["sahil-wadhwa"], zone="us-central1-b").get_master()
with tf.Session(tpu_grpc_url) as sess:
sess.run(tpu.initialize_system())
sess.run(tf.global_variables_initializer())
output = sess.run(tpu_computation)
print(output)
sess.run(tpu.shutdown_system())
但是我得到以下错误,
googleapiclient.errors.HttpError: https://tpu.googleapis.com/v1alpha1/projects/nlp-research-198620/locations/us-central1-b/nodes/sahil-wadhwa?alt=json returned "Permission 'tpu.nodes.get' denied on 'projects/nlp-research-198620/locations/us-central1-b/nodes/sahil-wadhwa'">
有人可以告诉我需要什么权限才能顺利地向 运行 提供我的 VM 或 TPU 吗?
ctpu 工具可自动执行许多此类步骤,是创建 TPU 和 VM 的推荐方法。
如果您更喜欢手动创建 VM,则需要按照此处所述将云平台身份验证范围添加到您的 VM
gcloud compute instances create tpu-demo-vm \
--machine-type=n1-standard-2 \
--image-project=ml-images \
--image-family=tf-1-11 \
--scopes=cloud-platform
https://cloud.google.com/tpu/docs/custom-setup#create_resources
Michaelb 的回答有效,但也可以在控制台中更改现有 VM 的权限。您必须停止 VM,然后对其进行编辑以允许 read/write 访问计算引擎 api。为此,请单击虚拟机的名称,然后单击顶部栏中的编辑; api 访问设置位于页面底部。