我试图使用TPU客户端API创建Google节点,但我无法确定Google中TPU节点的父资源名称。
下面可以找到我用来创建节点的完整代码,我很难理解什么应该是parent类的CreateNodeRequest属性的值:
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在其他组合中,我尝试了这些父资源名称:
而我总是分别得到以下错误之一:
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}发布于 2022-02-23 22:20:41
您可以在基础API方法的文档中找到parent的预期格式:projects.locations.nodes.create。
parent应该被格式化为projects/*/locations/*。也就是说,将zones更改为locations并从末尾删除/tpus。
编辑:在下面添加一些示例代码
我在云壳上完全尝试了以下操作(除了项目名和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()我使用google-cloud-tpu包在1.3.2上运行了这个示例
https://stackoverflow.com/questions/71214083
复制相似问题