【问题标题】:Google Cloud - TPU Node Resource NameGoogle Cloud - TPU 节点资源名称
【发布时间】:2022-03-08 02:51:58
【问题描述】:

我正在尝试使用 TPU client API 创建一个 Google Cloud TPU 节点,但我无法确定 Google Cloud 中 TPU 节点的父资源名称。

您可以在下面找到我用来创建节点的完整代码,我很难理解应该是 CreateNodeRequest 类的 parent 属性的值:

def create_tpu_node(parent_resource_name, node_name, accelerator_type, runtime_version):
# Create a client
client = tpu_v2alpha1.TpuClient()

# Initialize request argument(s)
node = tpu_v2alpha1.Node()
node.name = node_name
node.accelerator_type = accelerator_type
node.runtime_version = runtime_version

request = tpu_v2alpha1.CreateNodeRequest(
    parent=parent_resource_name,
    node=node,
)

# Make the request
operation = client.create_node(request=request)

print("Waiting for operation to complete...")

response = operation.result()

# Handle the response
return response

我已经尝试过这些父资源名称以及其他组合:

  1. projects/my-project-id/zones/europe-west4-a/tpus
  2. my-project-id/zones/europe-west4-a/tpus

而且我总是分别得到以下错误之一:

google.api_core.exceptions.InvalidArgument: 400 Malformed name: 'projects/my-project-id/zones/europe-west4-a/tpus/nodes/'

google.api_core.exceptions.InvalidArgument: 400 Invalid resource field value in the request.

我真的不知道如何获取 TPU 节点父资源名称,甚至 TPU 节点资源名称。任何帮助将不胜感激!

编辑:我也尝试使用以下父资源名称projects/my-project-id/locations/europe-west4-a,但仍然收到以下 gRPC 错误:

status = StatusCode.INVALID_ARGUMENT details = "Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'" debug_error_string = "{"created":"@1645875905.514000000","description":"Error received from peer ipv4:142.251.36.42:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'","grpc_status":3}

【问题讨论】:

  • 尝试为您的项目和位置修改此字符串:projects/example-project/locations/us-east1
  • 嗨@John Hanley,我试过了,但我得到了错误:google.api_core.exceptions.InvalidArgument: 400 Malformed name。我还尝试了其他组合(请参阅我编辑的帖子)。还有其他建议吗?

标签: python google-cloud-platform google-cloud-tpu


【解决方案1】:

您可以在底层 API 方法的文档中找到 parent 的预期格式:projects.locations.nodes.create

parent 的格式应为projects/*/locations/*。即把zones改成locations,把/tpus去掉。

编辑:在下面添加一些示例代码

我在Cloud Shell 上尝试了以下内容(项目和 TPU 名称除外):

from google.cloud import tpu_v2alpha1

req = tpu_v2alpha1.CreateNodeRequest(
  parent='projects/my-project-id/locations/europe-west4-a', 
  node_id='test-tpu',
  node=tpu_v2alpha1.Node(
    accelerator_type='v2-8',
    runtime_version='v2-alpha',
    network_config=tpu_v2alpha1.NetworkConfig(
      enable_external_ips=True)))

op = client.create_node(req)
# Shows TPU created successfully
op.result()

我在1.3.2 使用google-cloud-tpu 包运行了这个示例

【讨论】:

  • 嗨,我也尝试了这种格式,但我仍然收到以下错误(顺便说一句,我使用 conda virtual env)status = StatusCode.INVALID_ARGUMENT details = "Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'" debug_error_string = "{"created":"@1645875905.514000000","description":"Error received from peer ipv4:142.251.36.42:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'","grpc_status":3}"
  • 您似乎需要从路径中删除 nodes。即将projects/my-project-id/locations/europe-west4-a/nodes/更改为projects/my-project-id/locations/europe-west4-a/
  • 嗨,我也有同样的问题。需要明确的是,作者和我在父字符串中添加尾随 /nodes,只是 parent="projects/*/locations/*",按照对此问题的回复中的要求。但是我们仍然可以在“格式错误的名称”错误中看到 /nodes。也许是图书馆添加的?
  • 感谢您的澄清。您可以尝试我添加到答案中的示例代码并告诉我是否可行吗?
  • 您好,您的示例代码现在也适用于我的 1.3.1。非常感谢
猜你喜欢
  • 2021-02-17
  • 1970-01-01
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 2017-09-26
  • 2013-11-27
相关资源
最近更新 更多