gpt4 book ai didi

python - Google Cloud - TPU 节点资源名称

转载 作者:行者123 更新时间:2023-12-05 05:46:13 31 4
gpt4 key购买 nike

我正在尝试使用 TPU client API 创建 Google Cloud TPU 节点我无法找出 Google Cloud 中 TPU 节点的父资源名称。

下面你可以找到我用来创建节点的完整代码,我正在努力理解 CreateNodeRequestparent 属性的值应该是什么> 类(class):

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}

最佳答案

您可以在底层 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 包运行了这个示例

关于python - Google Cloud - TPU 节点资源名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71214083/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com